modified custom solr field types, fixed the reference search
This commit is contained in:
parent
dc2b536be3
commit
fa0c70ccd8
|
@ -21,14 +21,14 @@ field_type:
|
|||
filters:
|
||||
-
|
||||
class: solr.LowerCaseFilterFactory
|
||||
-
|
||||
class: solr.RemoveDuplicatesTokenFilterFactory
|
||||
-
|
||||
class: solr.ASCIIFoldingFilterFactory
|
||||
preserveOriginal: true
|
||||
-
|
||||
class: solr.WordDelimiterGraphFilterFactory
|
||||
preserveOriginal: 1
|
||||
-
|
||||
class: solr.RemoveDuplicatesTokenFilterFactory
|
||||
-
|
||||
type: query
|
||||
tokenizer:
|
||||
|
@ -36,13 +36,13 @@ field_type:
|
|||
filters:
|
||||
-
|
||||
class: solr.LowerCaseFilterFactory
|
||||
-
|
||||
class: solr.RemoveDuplicatesTokenFilterFactory
|
||||
-
|
||||
class: solr.ASCIIFoldingFilterFactory
|
||||
preserveOriginal: true
|
||||
-
|
||||
class: solr.WordDelimiterGraphFilterFactory
|
||||
preserveOriginal: 1
|
||||
-
|
||||
class: solr.RemoveDuplicatesTokenFilterFactory
|
||||
solr_configs: {}
|
||||
text_files: {}
|
||||
|
|
|
@ -27,6 +27,14 @@ class Base extends ControllerBase {
|
|||
// 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
|
||||
|
||||
|
||||
// Otherwise, if you use Solr, you can also set the parse mode to “Direct query”
|
||||
// and use something like 'tm_name:alex AND tm_surname:john' as the keywords (field names may vary).
|
||||
// That will also ensure scoring works for the keywords (the other way just adds filters, which don’t affect scoring).
|
||||
// https://www.drupal.org/project/search_api/issues/3049097
|
||||
|
||||
|
||||
|
||||
$lang = \Drupal::languageManager()->getCurrentLanguage()->getId();
|
||||
|
||||
$this->index = Index::load('database');
|
||||
|
@ -45,15 +53,7 @@ class Base extends ControllerBase {
|
|||
$this->and_query->setParseMode($parse_mode);
|
||||
// Set fulltext search keywords and fields.
|
||||
$this->and_query->keys($this->keys);
|
||||
// $this->and_query->setFulltextFields(['field_reference']);
|
||||
// in case we search for material references like W0117
|
||||
if (preg_match_all('/[WTRPCMFGSO]\d{4}/i', $this->keys, $matches)) {
|
||||
$ref_conditions = $this->and_query->createConditionGroup('OR');
|
||||
foreach ($matches[0] as $key => $value) {
|
||||
$ref_conditions->addCondition('field_reference', $value);
|
||||
}
|
||||
$this->and_query->addConditionGroup($ref_conditions);
|
||||
}
|
||||
|
||||
// in case of term id provided restrict the keys to taxo fields
|
||||
if ($this->term) {
|
||||
$term_conditions = $this->and_query->createConditionGroup('OR');
|
||||
|
@ -72,8 +72,11 @@ class Base extends ControllerBase {
|
|||
// look @ materio_sapi_search_api_solr_query_alter in materio_sapi.module
|
||||
// $this->or_query->setOption('termid', $this->term);
|
||||
}
|
||||
// FILTERS
|
||||
|
||||
$fulltextFields = [];
|
||||
|
||||
if ($this->filters) {
|
||||
// FILTERS
|
||||
$filters_conditions = $this->and_query->createConditionGroup('AND');
|
||||
foreach ($this->filters as $filter) {
|
||||
$filter = (int) $filter;
|
||||
|
@ -83,8 +86,8 @@ class Base extends ControllerBase {
|
|||
}
|
||||
$this->and_query->addConditionGroup($filters_conditions);
|
||||
}else{
|
||||
// Recherche uniquement sur le champ « body »
|
||||
$this->and_query->setFulltextFields([
|
||||
// Recherche uniquement sur les champ thésaurus et tag
|
||||
$fulltextFields += [
|
||||
'thesaurus_name_0',
|
||||
'thesaurus_synonyms_0',
|
||||
'thesaurus_name_1',
|
||||
|
@ -99,10 +102,12 @@ class Base extends ControllerBase {
|
|||
'thesaurus_synonyms',
|
||||
'tag_name',
|
||||
'tag_synonyms'
|
||||
]);
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
if(count($fulltextFields)){
|
||||
$this->and_query->setFulltextFields($fulltextFields);
|
||||
}
|
||||
|
||||
// Restrict the search to specific languages.
|
||||
$this->and_query->setLanguages([$lang]);
|
||||
|
@ -157,6 +162,15 @@ class Base extends ControllerBase {
|
|||
}
|
||||
$this->or_query->addConditionGroup($exclude_and_results_conditions);
|
||||
|
||||
if (preg_match_all('/[WTRPCMFGSO]\d{4}/i', $this->keys, $matches)) {
|
||||
// in case we search for material references like W0117
|
||||
$ref_conditions = $this->or_query->createConditionGroup('OR');
|
||||
foreach ($matches[0] as $key => $value) {
|
||||
$ref_conditions->addCondition('field_reference', $value);
|
||||
}
|
||||
$this->or_query->addConditionGroup($ref_conditions);
|
||||
}
|
||||
|
||||
// Restrict the search to specific languages.
|
||||
$this->or_query->setLanguages([$lang]);
|
||||
|
||||
|
|
Loading…
Reference in New Issue