I need to filter documents by two fields name and address.
I need to get results with names contains 'mar' first and then results with addresses contains 'mar'. But I'm getting randomly filtered results.
Like:
(name:(mar))^20 OR address:(mar)
Results from this query all documents are randomly sorted.
If some type of sorting exists, I'll appreciate your help. Thanks.
EDIT:
Boost in query working, and problem not with boost but with sorting. I have third field priority and when I provide additional fq priority asc boosting don't affect result.
I've understood my mistake.
I need results with names contains 'mar' as first and then with addresses contains 'mar', and after it I needed just to order by priority asc, and after it order by score desc to get correct results. Now i just need to implement it with Django Haystack.
Related
I am using SOLR 6.5.1 with facet filters.
My query has:
facet.limit=-1 --> to generate all possible facets values
facet.sort=index --> to order facets values not by number of occurrences but by the value itsef
For instance, one facet has integers as values (in particular the fields contains years). So the values are (occurences in brackets):
2010 (438)
2011 (547)
...
2017 (367)
The facet is correctly ordered by value but with asc order (2010-->2017). How can obtaint the reverse order (2017-->2010)?
Thanks
UMG
You won't be able to specify the sort direction with the simple facet API (the old one used directly in the URL). But since you're retrieving all the possible facets, you can reverse the direction in your client side controller before outputting the values. Exactly how you do that depends on which language you're using.
But if you'd switch over to the more modern JSON-based facet API, you can specify the sort order directly on each level of the facet:
"sort":"index desc"
Specifies how to sort the buckets produced. “count” specifies document count, “index” sorts by the index (natural) order of the bucket value. One can also sort by any facet function / statistic that occurs in the bucket. The default is “count desc”. This parameter may also be specified in JSON like sort:{count:desc}. The sort order may either be “asc” or “desc”
I would like to sort my data by the "format", the order is 4002, 4009 and finally 999.
So this sort doesn't work : "sort = desc size".
Do you know how I can do ?
Regards,
Laurent
If those are the three only values present, you can sort by a function query.
Or, you can abuse the q function to give different weights to each hit, and then have your actual queries in fq instead (since filter queries are non-scoring). I.e. q=format:4002^10 format:4009^5 format:999^1.
If you want to do it in a function query, you should be able to use a combination of if and termfreq functions to give sorting values for each term:
sort=if(termfreq(format,'4002'),1,if(termfreq(format,'4009'),2,if(termfreq(format,'999'),3,4))) asc
In Solr , I am fetching results using groupBy on "hash" ( my custom field ) field.
As we know each group will contains a set of documents.
My requirement is:
Solr first do a sorting based on score , that it is already doing.
If score of any two groups is same , then group with more number of documents should come up.
If even number of documents are same , then there should be some tie-breaker.
I need guidance for point 2 and 3. I am not able to get how to do it using 'sort' parameter.
Thanks
Amit Aggarwal
2)group with more number of documents should come up
There is no way to do it. Alternatively, you can use two queries to achieve this. Facets. They are, by default, sorted by numfound. And they loop through facet results to get results per facet.
I want to have search results from SOLR ordered like this:
All the documents that have the same score will be ordered descending by date added.
So when I query solr I will have n documents. In this results set there will be groups of documents with the same score. I want each of this group of documents to be ordered descending by date added.
I discovered I can accomplish this using function queries, more exactly using rord function http://wiki.apache.org/solr/FunctionQuery#rord, but as it is stated in the documentation
WARNING: as of Solr 1.4, ord() and rord() can cause excess memory use
since they must use a FieldCache entry at the top level reader, while
sorting and function queries now use entries at the segment level.
Hence sorting or using a different function query, in addition to
ord()/rord() will double memory use.
it will cause excess memory use.
What other options do I have ?
I was thinking to use recip(ms(NOW,startTime),1,1,0). Is this the best approach ?
Is there any negative performance impact if I use recip and ms ?
You can use multiple SORT conditions:
Multiple sort orderings can be separated by a comma, ie: sort=+[,+]...
http://wiki.apache.org/solr/CommonQueryParameters
So, in your case would be:
sort=score DESC, date_added DESC
Since your questions says:
All the documents that have the same score will be ordered descending
by date added.
the other answer you got is perfect.
Anyway, I'd suggest you to make sure that you really want to sort by date only for document with the same score. In my experience this has always been wrong. In fact, the solr score is not absolute but just relative to other documents, and each document is different.
Therefore I wouldn't sort by score and then something else, because it's hard to predict when you'll have the same score for different documents.
I would personally sort only on score and use a function to boost recent documents. You can find a good example on the solr wiki, the function used there is recip(ms(NOW,date_field),3.16e-11,1,1).
If you're worried for performance you can try index time boosting, which should be faster than query time boosting. Have a look here.
I have a solr index with the unique field as "id".
I have a ordered set of ids, using which I would like to query Solr. But I want the results in the same order.
so for example if i have the ids id = [5,1,3,4] I want the results displayed in solr in same order.
I tried http://localhost:8983/solr/select/?q=id:(5 OR 1 OR 3 OR 4)&fl=id, but the results displayed are in ascending order.
Is their a way to query solr, and get results as I mentioned?
I think you can't,
The results appear in the order they are indexed unless you specify a default sort field or the explicit sort field/order.
You can add another field to keep the initial sort order. You then can sort=field asc to retrieve the data in the original order.
The simple way is to query solr and sort the results in codes of yourself.