I am trying to put Solr search results that contain my search phrase in a specific field (here resourcename
) on the top of the result set.
I am a beginner on Solr. I have searched the web for quite a while and found some related questions, like:
Use function query for boosting score in Solr
SolrNet queries with boost functions
Then I started experimenting myself with queries like these:
https://localhost:8898/solr/collection1/select?defType=edismax&fl=resourcename&indent=on&q=resourcename:"test"*^200,%20content:"test"*^1&qf=resourcename^200%20content^2&rows=1000&wt=json
https://localhost:8898/solr/collection1/select?bf=if(exists(resourcename),100,1)&defType=edismax&fl=resourcename&indent=on&q=resourcename:"test"*^200,%20content:"test"*^1&rows=1000&wt=json
https://localhost:8898/solr/collection1/select?bf=if(exists(resourcename),100,1)&defType=edismax&fl=resourcename&indent=on&q=*:"test"*&rows=1000&wt=json
https://localhost:8898/solr/collection1/select?defType=edismax&fl=resourcename&indent=on&q=*:"test"*&qf=resourcename^200%20content^2&rows=1000&wt=json
But, no matter what I try, I get results containing the word test
in the resourcename
all over the place and not only on the top of the results.
Any ideas what I might be missing or doing wrong?
There are a lot of syntax mistakes, I would recommend to take a look to the solr wiki for query parsers[1] .
As a suggestion, always take a look to the parsed query and explore the debug functionality for search results.
To get the behavior you are asking I would use the following request parameters (quoting from the wiki):
q=foo bar
qf=field1^5 field2^10
pf=field1^50 field2^20
defType=dismax
With these parameters, the Dismax Query Parser generates a query that looks something like this:
(+(field1:foo^5 OR field2:foo^10) AND (field1:bar^5 OR field2:bar^10))
But it also generates another query that will only be used for boosting results:
field1:"foo bar"^50 OR field2:"foo bar"^20
In this way you can boost results according to the matches in some fields, with related boosts and then also boost phrases appearing in specific other fields.
[1] https://cwiki.apache.org/confluence/display/solr/The+Extended+DisMax+Query+Parser