Search api very slow sort on custom date field vs relevance sort: is there a solution?

I’m using search api with database backend on a Drupal 9.3.3 site. I’ve indexed 26,000 nodes of a custom content type and these include a custom date field: field_display_date

The index is set up to do rendered html. Since I need users to be able to sort on field_display_date (descending) as well as relevance, I’ve exposed two sorts: relevance and date (using this custom date field) and have added field_display_date to the index in "date" format.

The ultimate goal is to be able get highly relevant search results but be able to sort them to see the most recent highly relevant results. Maybe there’s a completely different way to do this.

Problem: with the view all set up, key in a search term an execute. With the sort set to the default ‘relevance,’ returns are pretty quick. If I change the sort to ‘date’ (field_display_date: descending) and submit again, there is a very long wait time, often a gateway timeout.

On one that didn’t time out, the view sql and performance redout said this…

Query    Index: main2 Keys: 'test' Parsed keys: array (     '#conjunction' => 'AND',     0 => 'test',   ) Searched fields: rendered_item, title Sorting: field_display_date DESC Options: array (     'search_api_view' => 'object (Drupal\views\ViewExecutable)',     'search_api_base_path' => 'search2',   ) Title   Search2 Path    /search2 Query build time    1.43 ms Query execute time  2.81 ms View render time    43237.89 ms 

Why is the render time so high and any ideas on how to correct this? Also, is switching to apache solr likely to work better or have the same result? (Since setting up solr looks pretty involved and is going to take me quite a while, would like to know if it’s likely to be worth doing.)

By contrast, here’s the same view and index and search keyword sorted by relevance…

Query    Index: main2 Keys: 'test' Parsed keys: array (     '#conjunction' => 'AND',     0 => 'test',   ) Searched fields: rendered_item, title Sorting: search_api_relevance DESC Options: array (     'search_api_view' => 'object (Drupal\views\ViewExecutable)',     'search_api_base_path' => 'search2',   ) Title   Search2 Path    /search2 Query build time    1.23 ms Query execute time  2.68 ms View render time    2990.91 ms 

This seems to suggest that the search itself and getting the result are both pretty quick but for some reason loading the page is really slow?

Interestingly, bypassing search api entirely and just plopping the body field into a regular view and searching on the keyword gets a faster result, which makes me think I’m doing something incorrectly at a fundamental level.

Plain views filter with no index, sorted by field_display_date descending, searching the body field for the same keyword…

Title   Content Path    /admin/content/node2 Query build time    3.23 ms Query execute time  1.2 ms View render time    6291.28 ms 
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

Search api very slow sort on custom date field vs relevance sort: is there a solution?

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.