I need to write a solr query for search autocomplete where user can enter a product_name OR product_style_no where competitor_id=1 , and returns a list of competitors. I ve used Spring Data Solr @Query annotation but not able to implement 'WHERE' condition in solr. Here is my code :

public interface ProductRepository extends SolrCrudRepository<Product, String>{

@Query("Product_Name:*?0* OR Product_Style_No:*?0*")
public Page<Product> findByProductNameORsku(String productName, Pageable pageable);

@Query("Page_Title:?0")
public Page<Product> findByPageTitle(String pageTitle, Pageable pageable);

} 
有帮助吗?

解决方案

I assume you do not want competitor_id to influence document score. I'd suggest usage of filter query.

    @Query(value="Product_Name:*?0* OR Product_Style_No:*?0*", filters={"competitor_id:1"})
    public Page<Product> findBy...

Once competitor_id probably should not be hardcoded you can use a placehoder as well.

    @Query(value="Product_Name:*?0* OR Product_Style_No:*?0*", filters={"competitor_id:?1"})
    public Page<Product> findByPNameOrSjyFilterByCompetitor(String pname, int competitorId, Pageable pageable);
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top