简体   繁体   中英

How to implement this products search query with multiple filters in Solr?

I need to implement a products search. Each product has a name, a category, price & availableAtPlace. I want search using these parameters:

- product name - look for specified keywords in product name
- filter those belonging to one of the many selected categories(from fixed 8 categories only, forever)
- filter those within specified price limit. 
- filter those available within radius of 'x' miles from spot 'y'

Now I have the following questions:

 1. What should be the query to get the search results filtered by above parameters ?

 2. Is there any way I could store these categories field in optimized
    way(since this is always out of fixed set of 8 values), so that
    query performance could be improved ? Probably some way of defining
    my set earlier so that indexing/querying of this field could be
    optimized!?

 3. I need to sort the results in the order of relevance of keyword
    search within product names + sorted in descending order of price.
    How do I accomplish this sort order?

Using SolrJ with Solr 4.5

I would make product name the default search field.

q param would be the keywords to search on

Use fq params for filtering on category and price. Those are cached for performance and are NOT used in the relevancy ranking.

Then use spatial search for radius.

This is an example searching for "some product" in category foo priced between 200 and 600 within 20 miles of carlsbad ca.

q=some+product&fq=category:foo&fq=price:[200+TO+600]&fq={!geofilt}&sfield=location&pt=33.1580933,-117.3505939&d=32.18688&sort=price+desc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM