On my Drupal 8 site, I am configuring a Search API search bar that uses a Search API Page that I've configured to include 3 entity types (Content, as well as 2 custom entities I have built).

The search is working as expected. The Search API Page for my defined index is set to show "Search results" style, which is just showing a hyperlink of the name or title of the entity, and all 3 entity types are returned in the search. The name/titles are all indexed as "Fulltext".

I want these links to be sortable alphabetically by the name or title of the entity (the text that appears in the hyperlink). I am attempting to use Search API Sorts to accomplish this. I have set up another field in the Index, an Aggregated field indexed as type "String", where I have checked it off to include just the name or title of each of the 3 entity types and no other fields. I chose "First" as the aggregation type since no search result will contain more than 1 of these fields. I then used Search API Sorts for this index to sort by this Aggregated Field by default, and then re-indexed my search.

It is just plain not working, the order of the returned results has not changed from before implementing the sort, they are not being returned alphabetically. I also tried using "Maximum" instead of "First" as the aggregation type, that did not make a difference either.

Am I missing a step here? I am not sure what to do to get this to work or what I could have done wrong.

edit: I'm aware that a search results page view can be created via Views which offers built-in sorting functionality, but when I attempt to create a View and choose my index under "Settings" with type set to "All" and tags left blank, I get this error:

The website encountered an unexpected error. Please try again later.

Drupal\Component\Plugin\Exception\PluginNotFoundException: The "" entity type does not exist. in Drupal\Core\Entity\EntityTypeManager->getDefinition() (line 133 of core\lib\Drupal\Core\Entity\EntityTypeManager.php).

This is of course total gibberish to me... I am not sure where this is coming from. The verbose logs are as follows:

Notice: Undefined index: entity_type in Drupal\views\Plugin\views\field\Field->getFieldStorageDefinition() (line 325 of core\modules\views\src\Plugin\views\field\Field.php).
Drupal\views\Plugin\views\field\Field->getFieldStorageDefinition() (Line: 346)
Drupal\views\Plugin\views\field\Field->defineOptions() (Line: 99)
Drupal\search_api\Plugin\views\field\SearchApiEntityField->defineOptions() (Line: 138)
Drupal\views\Plugin\views\PluginBase->init(Object, Object, Array) (Line: 102)
Drupal\views\Plugin\views\HandlerBase->init(Object, Object, Array) (Line: 115)
Drupal\views\Plugin\views\field\FieldPluginBase->init(Object, Object, Array) (Line: 177)
Drupal\views\Plugin\views\field\Field->init(Object, Object, Array) (Line: 57)
Drupal\search_api\Plugin\views\field\SearchApiEntityField->init(Object, Object, Array) (Line: 888)
Drupal\views\Plugin\views\display\DisplayPluginBase->getHandlers('field') (Line: 2639)
call_user_func(Array, 'field') (Line: 2604)
Drupal\views\Plugin\views\display\DisplayPluginBase->mergeDefaults() (Line: 2395)
Drupal\views\ViewExecutable->mergeDefaults() (Line: 802)
Drupal\views\Plugin\views\wizard\WizardPluginBase->addDisplays(Object, Array, Array, Object) (Line: 690)
Drupal\views\Plugin\views\wizard\WizardPluginBase->instantiateView(Array, Object) (Line: 1259)
Drupal\views\Plugin\views\wizard\WizardPluginBase->validateView(Array, Object) (Line: 165)
Drupal\views_ui\ViewAddForm->validateForm(Array, Object)
call_user_func_array(Array, Array) (Line: 83)
Drupal\Core\Form\FormValidator->executeValidateHandlers(Array, Object) (Line: 270)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object, 'view_add_form') (Line: 119)
Drupal\Core\Form\FormValidator->validateForm('view_add_form', Array, Object) (Line: 571)
Drupal\Core\Form\FormBuilder->processForm('view_add_form', Array, Object) (Line: 314)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 74)
Drupal\Core\Controller\FormController->getContentResult(Object, Object)
call_user_func_array(Array, Array) (Line: 123)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->Drupal\Core\EventSubscriber\{closure}() (Line: 574)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 124)
Drupal\Core\EventSubscriber\EarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97)
call_user_func_array(Object, Array) (Line: 139)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 62)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 652)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

I am trying to do it with these settings in the Views wizard: Link, since imgur seems to be down

  • No idea if simple search pages support configurable sorts. Set error logging to verbose and provide that, also include a screenshot of your settings on the views wizard. If possible with open selection of the options for Content and so on.. If you select your index, then you shouldn't have those additional fields.
    – Berdir
    Feb 28, 2017 at 20:05
  • Thanks for the reply @Berdir, I have added the info as requested. The selected search index in the screenshot is the only one I have defined.
    – saramm1
    Feb 28, 2017 at 21:40
  • I think search API sorts doesn't work well with aggregated fields. Instead of indexing aggregated field, try indexing title field twice, once with Full Text and once with string. Configure sort settings on string field and make sure sort has been enabled. You can also check Facets and Search API glossary modules which also sorts search results. Views sort will not work properly with Solr indexed results. Jan 13, 2018 at 19:06


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.