Alphabetical sort of Search API results including multiple entity types

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

This article was republished from its original source.
Call Us: 1(800)730-2416

Pixeldust is a 20-year-old web development agency specializing in Drupal and WordPress and working with clients all over the country. With our best in class capabilities, we work with small businesses and fortune 500 companies alike. Give us a call at 1(800)730-2416 and let’s talk about your project.

FREE Drupal SEO Audit

Test your site below to see which issues need to be fixed. We will fix them and optimize your Drupal site 100% for Google and Bing. (Allow 30-60 seconds to gather data.)

Powered by

Alphabetical sort of Search API results including multiple entity types

On-Site Drupal SEO Master Setup

We make sure your site is 100% optimized (and stays that way) for the best SEO results.

With Pixeldust On-site (or On-page) SEO we make changes to your site’s structure and performance to make it easier for search engines to see and understand your site’s content. Search engines use algorithms to rank sites by degrees of relevance. Our on-site optimization ensures your site is configured to provide information in a way that meets Google and Bing standards for optimal indexing.

This service includes:

  • Pathauto install and configuration for SEO-friendly URLs.
  • Meta Tags install and configuration with dynamic tokens for meta titles and descriptions for all content types.
  • Install and fix all issues on the SEO checklist module.
  • Install and configure XML sitemap module and submit sitemaps.
  • Install and configure Google Analytics Module.
  • Install and configure Yoast.
  • Install and configure the Advanced Aggregation module to improve performance by minifying and merging CSS and JS.
  • Install and configure Schema.org Metatag.
  • Configure robots.txt.
  • Google Search Console setup snd configuration.
  • Find & Fix H1 tags.
  • Find and fix duplicate/missing meta descriptions.
  • Find and fix duplicate title tags.
  • Improve title, meta tags, and site descriptions.
  • Optimize images for better search engine optimization. Automate where possible.
  • Find and fix the missing alt and title tag for all images. Automate where possible.
  • The project takes 1 week to complete.