Adding dates to complex SOLR queries

I currently have a SOLR query that uses query (q), query fields (qf) and phrase fields (pf) to get the results I want. Example:

/solr/select ?q=superbowl &qf=title^3+headline^2+intro+fulltext &pf=title^3+headline^2+intro+fulltext &fl=id,title,ts_modified,score &debugQuery=true 

The idea is that the heading and heading of the โ€œmain elementโ€ give the best idea of โ€‹โ€‹what the result is โ€œabout,โ€ but the input and full text also give some data. Those. imagine a collection of links in which the collection itself has metadata (that it is a collection), but each link has its own data (link name, resume, etc.). If we search for "superbowl", the most relevant are the results with "superbowl" in the collection metadata, the least relevant are the results with "superbowl" in only one of the links ... but they are all valid results.

What I'm trying to do is add a boost to the relevance value so that the latest results pop up, but keep the title, title, input, full text as part of the formula. A recent search result in a collection metadata will be more relevant than one with it only in link metadata ... but this "only links" recent result may be more relevant than a very old result using a search string in a collection metadata. (I hope this is somewhat clear).

The problem is that I cannot figure out how to combine the boost function registered on the SOLR site using qf / pf fields. In particular...

From the SOLR site, something like the following works to increase results by date:

 /solr/select ?q={!boost%20b=$dateboost%20v=$qq} &dateboost=ord(ts_modified) &qq=superbowl &fl=ts_modified,score &debugQuery=true 

However, I cannot figure out how to combine this query using qf and pf. Any suggestions would be more than welcome.

Thanks to Danben's answer, I was able to come up with the following:

 /solr/select ?q={!boost%20b=$dateboost%20v=$qq%20defType=dismax} &dateboost=ord(ts_modified) &qq=superbowl &qf=title^3+headline^2+intro^2+fulltext &pf=title^3+headline^2+intro^2+fulltext &fl=ts_modifieds,score &debugQuery=true 

It seems that the actual issues I ran into were:

  • I left spaces in the q parameter instead of running away from them (% 20) when copying / pasting
  • In my q parameter, I did not include defType = dismax so that it would pay attention to the qf / pf parameters.
+4
source share
2 answers

Check out http://wiki.apache.org/solr/SolrRelevancyFAQ#How_can_I_boost_the_score_of_newer_documents

This is based on the ms function, which returns the difference in milliseconds between two timestamps / dates and the ReciprocalFloatFunction , which increases as the value decreases.

Since you are using DisMaxRequestHandler, you may need to specify your request using the bq / bf parameters. From http://lucene.apache.org/solr/api/org/apache/solr/handler/DisMaxRequestHandler.html :

bq - (Boost Query) - an unprocessed lucene query that will be included in users can affect the score. If this is a BooleanQuery with a default boost (1.0f), then individual offers will be added directly to the main query. Otherwise, the request will be included as is. This parameter can be several times, and the enhancements are additive. Note the behavior listed above is only in effect if one parameter bq equals specified. Therefore, you can disable it by specifying an additional, empty, bq parameter.

Functions

bf - (Boost Functions) (with additional enhancements), which will be included in the user request to affect the score. Format: "FuncA (arg1, arg2) ^ 1.2 funcB (arg3, arg4) ^ 2.2" NOTE: Spaces are not allowed in function arguments. This parameter can be several times, and the functions are additive.

+4
source

Here is a good date Solr article with a date:

http://www.metaltoad.com/blog/date-boosting-solr-drupal-search-results


In Drupal, this can simply be achieved with the following code:

using Apacheolr module

 /** * Implements hook_apachesolr_query_alter(). */ function hook_search_apachesolr_query_alter(DrupalSolrQueryInterface $query) { $query->addParam('bf', array('freshness' => 'recip(abs(ms(NOW/HOUR,dm_field_date)),3.16e-11,1,.1)' )); } 
0
source

Source: https://habr.com/ru/post/1299982/


All Articles