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

有帮助吗?

解决方案

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>

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top