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.
DrupalComponentPluginExceptionPluginNotFoundException: The "" entity type does not exist. in DrupalCoreEntityEntityTypeManager->getDefinition() (line 133 of corelibDrupalCoreEntityEntityTypeManager.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 DrupalviewsPluginviewsfieldField->getFieldStorageDefinition() (line 325 of coremodulesviewssrcPluginviewsfieldField.php). DrupalviewsPluginviewsfieldField->getFieldStorageDefinition() (Line: 346) DrupalviewsPluginviewsfieldField->defineOptions() (Line: 99) Drupalsearch_apiPluginviewsfieldSearchApiEntityField->defineOptions() (Line: 138) DrupalviewsPluginviewsPluginBase->init(Object, Object, Array) (Line: 102) DrupalviewsPluginviewsHandlerBase->init(Object, Object, Array) (Line: 115) DrupalviewsPluginviewsfieldFieldPluginBase->init(Object, Object, Array) (Line: 177) DrupalviewsPluginviewsfieldField->init(Object, Object, Array) (Line: 57) Drupalsearch_apiPluginviewsfieldSearchApiEntityField->init(Object, Object, Array) (Line: 888) DrupalviewsPluginviewsdisplayDisplayPluginBase->getHandlers('field') (Line: 2639) DrupalviewsPluginviewsdisplayDisplayPluginBase->mergeHandler('field') call_user_func(Array, 'field') (Line: 2604) DrupalviewsPluginviewsdisplayDisplayPluginBase->mergeDefaults() (Line: 2395) DrupalviewsViewExecutable->mergeDefaults() (Line: 802) DrupalviewsPluginviewswizardWizardPluginBase->addDisplays(Object, Array, Array, Object) (Line: 690) DrupalviewsPluginviewswizardWizardPluginBase->instantiateView(Array, Object) (Line: 1259) DrupalviewsPluginviewswizardWizardPluginBase->validateView(Array, Object) (Line: 165) Drupalviews_uiViewAddForm->validateForm(Array, Object) call_user_func_array(Array, Array) (Line: 83) DrupalCoreFormFormValidator->executeValidateHandlers(Array, Object) (Line: 270) DrupalCoreFormFormValidator->doValidateForm(Array, Object, 'view_add_form') (Line: 119) DrupalCoreFormFormValidator->validateForm('view_add_form', Array, Object) (Line: 571) DrupalCoreFormFormBuilder->processForm('view_add_form', Array, Object) (Line: 314) DrupalCoreFormFormBuilder->buildForm(Object, Object) (Line: 74) DrupalCoreControllerFormController->getContentResult(Object, Object) call_user_func_array(Array, Array) (Line: 123) DrupalCoreEventSubscriberEarlyRenderingControllerWrapperSubscriber->DrupalCoreEventSubscriber{closure}() (Line: 574) DrupalCoreRenderRenderer->executeInRenderContext(Object, Object) (Line: 124) DrupalCoreEventSubscriberEarlyRenderingControllerWrapperSubscriber->wrapControllerExecutionInRenderContext(Array, Array) (Line: 97) DrupalCoreEventSubscriberEarlyRenderingControllerWrapperSubscriber->DrupalCoreEventSubscriber{closure}() call_user_func_array(Object, Array) (Line: 139) SymfonyComponentHttpKernelHttpKernel->handleRaw(Object, 1) (Line: 62) SymfonyComponentHttpKernelHttpKernel->handle(Object, 1, 1) (Line: 57) DrupalCoreStackMiddlewareSession->handle(Object, 1, 1) (Line: 47) DrupalCoreStackMiddlewareKernelPreHandle->handle(Object, 1, 1) (Line: 47) DrupalCoreStackMiddlewareReverseProxyMiddleware->handle(Object, 1, 1) (Line: 50) DrupalCoreStackMiddlewareNegotiationMiddleware->handle(Object, 1, 1) (Line: 23) StackStackedHttpKernel->handle(Object, 1, 1) (Line: 652) DrupalCoreDrupalKernel->handle(Object) (Line: 19)
I am trying to do it with these settings in the Views wizard: Link, since imgur seems to be down