1

I have a set of users with field_first_name and field_last_name, and i want to create a user search using the search api, to search for users using those fields, but it doesn't seems to be working.

Here is my code:

$query = Index::load('default_index')
      ->query(array(
          'offset' => 0,
          'limit'  => 12,
      ))
      ->keys($text)
      ->addCondition('search_api_datasource', 'entity:user')
      ->execute();

It's not fetching any of my users per name. I am missing something?

1

On the first hand, can you check if your content is being indexed properly ? If yes, then I would recommend using the default search box provided by drupal, and see if you get results.

Assuming you are using search api solr module.

2
  • I eventually found out the issue: i had to add the fields to my index and associate a view mode to the rendered user in: admin > config > search > search-api > index > default_index > fields. It was just a settings issue, my code was ok. I wasn't using Solr, but the Database Server. Jul 26 '17 at 16:13
  • Cool, good to hear that. Jul 27 '17 at 6:14

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.