相关疑难解决方法(0)

文本搜索不使用Spring Boot MongoDB

我正在开发Spring Boot + MongoDB + spring data mongo + Text search示例.通过链接参考:https://spring.io/blog/2014/07/17/text-search-your-documents-with-spring-data-mongodb,我开发了我的代码,但当我执行时,它给出了空结果集.请帮助这个场景.我期待得到两者results OrderId = 10248 and 10249,但我得空了.

我开发的代码:OrderDetails.java

@Document(collection="order-details")
public class OrderDetails {

    @Id
    private ObjectId id;

    //@TextIndexed(weight=2)
    @Field("OrderID")
    private Integer orderID;

    @Field("ProductID")
    private Integer productID;

    @Field("UnitPrice")
    private Double unitPrice;

    @Field("Quantity")
    private Integer quantity;

    @Field("Discount")
    private Integer discount;
        // setters and getters
}
Run Code Online (Sandbox Code Playgroud)

OrderDetailsS​​ervice.java

public interface OrderDetailsService {
    List<OrderDetails> findAllBy(Integer searchValue);
}
Run Code Online (Sandbox Code Playgroud)

OrderDetailsS​​erviceImpl.java

@Component
public class OrderDetailsServiceImpl implements OrderDetailsService{

    @Autowired
    private OrderDetailsRepository odRepository; …
Run Code Online (Sandbox Code Playgroud)

java spring-data-mongodb spring-boot

16
推荐指数
1
解决办法
2145
查看次数

Spring Data MongoDB | 带分页的动态搜索

我正在尝试对大量产品进行动态搜索。该对象具有多个属性,包括productNamesubCategoryNamecategoryNamebrandName等。用户可以使用这些属性中的任何一个来搜索产品。顺序是固定的,搜索字符串的首要任务是在productName和 then中找到它subCategoryName,依此类推。

\n

我曾经aggregate实现这一点,然后unionWith连接与其他属性匹配的记录。当作为原始查询触发时,它似乎可以工作,但我们还需要对分页的支持,而我无法使用 Spring Data MongoDB 来实现这一点

\n
db.product.aggregate(\n[\n\xc2\xa0 { $match: { "productName" : { "$regex" : "HYPER", "$options" : "i"}, \n\xc2\xa0 "companyNo" : { "$in" : [10000009]}, "status" : { "$in" : ["ACTIVE", "IN_ACTIVE", "OUT_OF_STOCK"]} }},\n\xc2\xa0 { $unionWith: { coll: "product", pipeline: [{ $match: { "subCategoryName" : { "$regex" : "HYPER", "$options" : "i"},\n\xc2\xa0 "companyNo" : { "$in" : [10000009]}, "status" : …
Run Code Online (Sandbox Code Playgroud)

java mongodb spring-data aggregation-framework spring-data-mongodb

5
推荐指数
1
解决办法
2143
查看次数