tried to boost sapi query with termid, do not work

This commit is contained in:
2021-03-03 11:32:23 +01:00
parent ae0778b8b2
commit 8fd57d2579
3 changed files with 67 additions and 16 deletions

View File

@@ -6,7 +6,8 @@
*/
use Drupal\Core\Routing\RouteMatchInterface;
use Solarium\QueryType\Select\Query\Query;
use Drupal\search_api\Query\QueryInterface;
/**
* Implements hook_help().
*/
@@ -22,3 +23,28 @@ function materio_sapi_help($route_name, RouteMatchInterface $route_match) {
default:
}
}
/**
* Implements hook_search_api_solr_query_alter();
*/
function materio_sapi_search_api_solr_query_alter(Query $solarium_query, QueryInterface $query) {
if ($termid = (int)$query->getOption('termid')) {
// get solarium fileds name
$index = $query->getIndex();
$solrFields = $index->getServerInstance()
->getBackend()
->getSolrFieldNames($index);
// tag_tid"itm_tag_tid"
// thesaurus_tid"itm_thesaurus_tid"
$tag_fname = $solrFields['tag_tid'];
$thes_fname = $solrFields['thesaurus_tid'];
// $solarium_query->addParam('bf', "recip(abs(ms(NOW,{$solrField})),3.16e-11,10,0.1)");
// $bfparam = "if(or(gt(termfreq({$tag_fname},{$termid}),0),gt(termfreq({$thes_fname},{$termid}),0)),^21,0)";
$bfparam = "if(or(exists(query({$tag_fname}:{$termid})),exists(query({$thes_fname}:{$termid}))),^21,0)";
// boost=if(or(exists(query(itm_tag_tid:396)),exists(query(itm_thesaurus_tid:396))),^21,0 )
$solarium_query->addParam('boost', $bfparam);
// $solarium_query->addParam('debugQuery', 'on');
}
}