Sort solr result by weighting certain elements
I have solr query that simply returns the most recent items in the index. However I'm trying to optionally if categories are passed in have it the category field weighted such that if there are matches for the category field then those are weighted higher but still have those without categories show.
so the document structure looks something like this:
{id:1, title:"sometitle", category:['cat1','cat2']},{id:1, title:"sometitle", category:[]}
my general query is something like:
title:*
but if categories are passed in i'd do the same title开发者_JS百科:* query but i'd like the results to be sorted such that those results with category fields that match the categories passed in are weighted higher
I tried boost query (bq) but that didn't work (which makes sense because my query is to return all) and i am sorting primary by score and doing a secondary sort on a "created" field
If I understand your question right, you want certain documents to be scored higher regardless of your query, right? Those documents which have categories in them should be better than ones without categories?
If this is what you want, see: How can I increase the score for specific documents?.
Alternatively, you might be asking to boost things only if you query for them. Your query should be
+(title:"title to search for") category:"categories to boost"
This will only find things which match the title, but it will boost the score if it has a category you included in that query.
精彩评论