tried to boost sapi query with termid, do not work
This commit is contained in:
@@ -24,10 +24,31 @@ class Base extends ControllerBase {
|
||||
|
||||
private function sapiQuery(){
|
||||
// https://www.drupal.org/docs/8/modules/search-api/developer-documentation/executing-a-search-in-code
|
||||
// https://www.hashbangcode.com/article/drupal-8-date-search-boosting-search-api-and-solr-search
|
||||
// https://kgaut.net/blog/2018/drupal-8-search-api-effectuer-une-requete-dans-le-code.html
|
||||
|
||||
$this->index = Index::load('database');
|
||||
|
||||
// // get solarium fileds name
|
||||
// $solrFields = $this->index->getServerInstance()
|
||||
// ->getBackend()
|
||||
// ->getSolrFieldNames($this->index);
|
||||
//
|
||||
// // tag_tid"itm_tag_tid"
|
||||
// // thesaurus_tid"itm_thesaurus_tid"
|
||||
// $taxoSolrFieldsName = [];
|
||||
// foreach (['tag_tid', 'thesaurus_tid'] as $f) {
|
||||
// $taxoSolrFieldsName[] = $solrFields[$f];
|
||||
// }
|
||||
|
||||
$this->query = $this->index->query();
|
||||
|
||||
// Change the parse mode for the search.
|
||||
// Les différentes possibilités sont
|
||||
// - « direct » => Requête directe
|
||||
// - « terms » => Multiple words
|
||||
// - « phrase » => Single phrase
|
||||
// - " edismax " => ???
|
||||
$parse_mode = \Drupal::service('plugin.manager.search_api.parse_mode')
|
||||
->createInstance('direct');
|
||||
$parse_mode->setConjunction('OR');
|
||||
@@ -48,17 +69,21 @@ class Base extends ControllerBase {
|
||||
}
|
||||
// in case of term id provided restrict the keys to taxo fields
|
||||
if ($this->term) {
|
||||
$term_conditions = $this->query->createConditionGroup('OR');
|
||||
$term = (int) $this->term;
|
||||
foreach (['tag_tid', 'thesaurus_tid'] as $field) {
|
||||
$term_conditions->addCondition($field, $term);
|
||||
}
|
||||
// foreach (['tag_name', 'thesaurus_name'] as $field) {
|
||||
// $term_conditions->addCondition($field, $this->keys);
|
||||
// $term_conditions = $this->query->createConditionGroup('OR');
|
||||
// $term = (int) $this->term;
|
||||
// foreach (['tag_tid', 'thesaurus_tid'] as $field) {
|
||||
// $term_conditions->addCondition($field, $term);
|
||||
// }
|
||||
// $term_conditions->addCondition('tag_name', $this->keys);
|
||||
// $term_conditions->addCondition('thesaurus_name', $this->keys);
|
||||
$this->query->addConditionGroup($term_conditions);
|
||||
// $this->query->addConditionGroup($term_conditions);
|
||||
|
||||
// INSTEAD TRY TO BOOST TTHE TAG AND THESAURUS FIELDS
|
||||
// foreach ($taxoSolrFieldsName as $fname) {
|
||||
// // $solarium_query->addParam('bf', "recip(abs(ms(NOW,{$solrField})),3.16e-11,10,0.1)");
|
||||
// $bfparam = "if(gt(termfreq({$fname},{$this->term}),0),^21,0)";
|
||||
// $this->query->addParam('bf', $bfparam);
|
||||
// }
|
||||
|
||||
$this->query->setOption('termid', $this->term);
|
||||
}
|
||||
|
||||
// Restrict the search to specific languages.
|
||||
|
Reference in New Issue
Block a user