0

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);

} 
Frederic Close
  • 9,389
  • 6
  • 56
  • 67
user3095886
  • 37
  • 1
  • 1
  • 4

1 Answers1

2

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);
Christoph Strobl
  • 6,491
  • 25
  • 33