0

I am new to Drupal. I'm trying to implement advanced search on my Drupal8 website. It's working perfectly with the logical operator 'OR' and 'AND' but not with 'NOT', '+', '-'.

Here is my request :

$index = \Drupal\search_api\Entity\Index::load('videos_full');
    $query = $index->query();
    $parse_mode = \Drupal::service('plugin.manager.search_api.parse_mode')
                  ->createInstance('direct');
    $query->setParseMode($parse_mode);
    $query->addCondition('search_api_language', \Drupal::languageManager()->getCurrentLanguage()->getId());
    $query->addCondition("status",5);

    $query->setFulltextFields(['field_title', 'title', 'resourcetype', 'tag', 'choreographer', 'director', 'producer', 'structure', 'contributor', 'secondaryauthor']);
    $query->keys($search);

    $query->sort('created','DESC');
    $results = $query->execute();

Thank you for your help !

0

Please refer to following Drupal documentation example for advanced configuration of search query:

https://www.drupal.org/docs/8/modules/search-api/developer-documentation/executing-a-search-in-code

$query->keys($search);

'+', '-' works by default in $search(searched keyword)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.