1

I am wondering if it is possible with Solr 3.4 to boost a search result, if the query is found in a special field without using the "fieldname:query"-syntax.

Let me explain:

I have several fields in my index. One of it is named "abbreviation" and is filled with text like AVZ, JSP, DECT, ...

To be able to find results when searching purely for "AVZ" I added a

<copyField source="abbreviation" dest="text"/>

in my schema.xml. The field text is my defaultSearchField.

This is not the best solution in my opinion. So I am trying to find out, if it is possible to search for "AVZ" in all fields and if the String is found in the field abbreviation, the result entry should be boosted (increasing the score) so that it will be listed at first entry in the result list. Would be the same as using abbreviation:AVZ AVZ as query.

The other possibility I can think of is to analyze the query. And if a substring like "AVZ" is found, the query will be appended with abbreviation:AVZ. But in this case I must be able to find out, which abbreviations are indexed. Is it possible to retrieve all possible terms of a field from the Solr index using SolrJ?

Best Regards Tobias

javanna
  • 59,145
  • 14
  • 144
  • 125

2 Answers2

2

Without the fieldname:term syntax use can define a request handler -

<requestHandler name="search" class="solr.SearchHandler" default="true">
 <lst name="defaults">
   <str name="echoParams">explicit</str>
   <str name="defType">dismax</str>
   <str name="qf">
      abbreviation^2 text
   </str>
   <str name="q.alt">*:*</str>
   <str name="rows">10</str>
   <str name="fl">*,score</str>
 </lst>
</requestHandler>

This uses the dismax query parser. You can use edismax as well.
This will boost the results and query would be a simple query as q=AVZ.

If only through url, you can boost match on specific field like mentioned @ link

e.g.

q=abbreviation:AVZ^2 text:AVZ

This would boost the results with a match on abbreviation, which would result the documents to appear on top.

It is not possible to get all results with dismax using the *:* query.
However, for all docs just do not pass any q param. q.alt=*:* will return all the docs.

Else, update the defType to edismax.

<requestHandler name="search" class="solr.SearchHandler" default="true">
 <lst name="defaults">
   <str name="echoParams">explicit</str>
   <str name="defType">edismax</str>
   <str name="qf">
      abbreviation^2 text
   </str>
   <str name="q.alt">*:*</str>
   <str name="rows">10</str>
   <str name="fl">*,score</str>
 </lst>
</requestHandler>
Jayendra
  • 52,349
  • 4
  • 80
  • 90
  • Thanks for that answer. Does this mean, Solr is able to search automatically inside the text and abbreviation fields at the same time only by adding the qf-config to the request handler? – user1014617 Nov 03 '11 at 07:07
  • yup the qf decides the fields that would be queried. So they both would be searched on, and as the weight is higher on abbreviation those results will be boosted. – Jayendra Nov 03 '11 at 07:11
  • Ok, that is clear to me. Can you explain, why the query q=*:* does not return any results with the above request handler configuration? – user1014617 Nov 03 '11 at 08:01
  • updated the answer with more details. for dismax just don't pass any q param q.alt will take care of it. – Jayendra Nov 03 '11 at 08:23
  • Thank you for the update. One last question: The above configuration searches in all fields, configured in qf. But how about setting a filter like q=AVZ AND doctype:FOOBAR? – user1014617 Nov 03 '11 at 08:49
  • Ah, I forgot to use edismax. :-) – user1014617 Nov 03 '11 at 08:56
  • you can use q=AVZ&fq=doctype:FOOBAR. Also if the answer worked for you might want to accept it. – Jayendra Nov 03 '11 at 10:18
1

Apache Solr 6.4.2:

Boosting Exact phrase search not working: Solrconfig.xml:

explicit

  <int name="rows">10</int>
  <str name="defType">edismax</str>

  <str name="qf">names^50</str>



  <!-- <str name="df">text</str> -->
</lst>

Solr query used to test: q=(names:alex%20pandian)&wt=json&debugQuery=on

In debug mode it shows

"parsedquery_toString":"+((names:alex ((names:pandian)^50.0))) ()"

It is boosting the terms from second word only. In this case only Pandian is boosted but Alex is not.

ADyson
  • 57,178
  • 14
  • 51
  • 63
chimbu
  • 11
  • 4