Solr End User Query Translation

388 Views Asked by At

I am wondering if there is anyway to transform an end user query to a more complicated solr query based on some rules.

For example, if the user types in 32" television, then I want to use the dismax query parser to let solr take care of this user query string like below:

http://localhost:8983/solr/select/?q=32" television&defType=dismax

However, if the user types in "televisions on sale", then I want to do a regular search for token televisions and onsale flag is true like below:

http://localhost:8983/solr/select/?q=name:televisions AND isOnSale:true

Is this possible? Or must this logic require an advance search form where the user can clearly state in a checkbox that they only want on sale items.

Thanks.

3

There are 3 best solutions below

0
On

Let the search happen through the whole index and let the user choose. If a review shows up, render it with the appropriate view. If a product shows up, offer to search for more products.

Samsung 32 in reviews --read more

LG 32 in offers --find more like this

Your offers page can offer more options, such as filtering products on sale.

You may use a global boost field on documents. For example, a product on sale has a score of 1.0 while out of stock products have 0.33. A review of a new products has 1.0, old products have less.

0
On

Maybe you can set up the search so when someone searches for whatever have isOnSale as a secondary sort parameter. So by default sort by score then sort by isonsale or just sort by isonsale. That way you will still get all "television" ads in the results just the ones on sale are on top.

0
On

Transforming the user query is quite possible. You can do it in following two ways

  1. implement a Servlet Filter that listens to user query transforms it before dispatching it to solr request handler.

  2. Look at query parser plugin in SOLR and implement one based on the existing one like standard query parser and modify it to apply transformation rules.