0

I am trying to perform a search programmatically with our database search api (no solr or other servers) with the following code:

$query = \Drupal\search_api\Entity\Index::load('us_search')->query();
$query->keys($search_entry);
$query->setFulltextFields(['title', 'url']);
$query->range(0, 5);

$result = $query->execute();

However, when I run the code it is throwing this error:

Search keys are given but no fulltext fields are defined.

I further check if the index itself was able to pull the fulltext fields using this code but the array is always empty

$index = \Drupal\search_api\Entity\Index::load('us_content');
$index_fields = $index->getFulltextFields();

The fields are setup correctly and the search works perfectly fine on the UI side. It is just that I need to be able to create the search programatically for a web service but am stuck right now due to this error.

Anyone has any idea what might be missing? Thanks

  • @Kevin, that seems to be a different issue. In the ticket he was trying to specify the fulltext fields he wanted to return instead of getting all of them. In my case, it is throwing the error saying no fields are defined. – overloading Jan 7 at 13:56

Your Answer

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

Browse other questions tagged or ask your own question.