0

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?

Community
  • 1
  • 1
user2173353
  • 4,316
  • 4
  • 47
  • 79

1 Answers1

2

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

Community
  • 1
  • 1
  • Thanks. This helps, but for some reason I cannot make it keep all the results containing the search term/phrase on top. I have tried very big weights on the property I want, but for some reason it refuses to apply those weights or something... :^) I have tried putting weights on most of the fields, but still nothing. I have no idea what goes on... – user2173353 May 15 '17 at 08:59
  • Hm... I think I got it: It wants me to put `*term*` instead of `term*` in order to find a field containing something like `This is a term.`. Not quite sure why... :^) – user2173353 May 15 '17 at 08:59
  • If you have any idea for the question in my last comment, let me know. But, anyhow, thanks a lot for the help. At least I got it working pretty good now. I am only afraid of performance issues. :) – user2173353 May 15 '17 at 11:47
  • Hm.... I see that this misses some results for some reason. E.g. when I search with `test` I get the results I expect (I think at least) but when searching with `ppt` I don't get some results that I get when not using `dismax`/`edismax`. Not sure what is going on here... – user2173353 May 18 '17 at 12:06
  • I highly discourage the use of regular expression queries. Spend some time designing a proper analysis chain, that would help to keep your queries simple! – Alessandro Benedetti Jun 29 '17 at 09:10