Avoid doubling queries on search

XMLWordPrintable

    • Type: Task
    • Resolution: Merged
    • Priority: Should have
    • None
    • None
    • 3
    • Search, Technical Debt
    • Sprint #233, Sprint #234
    • umbriel

      Summary

      The way search currently works generates 2 queries to ElasticSearch for 1 search.

      We could rewrite our search to use and integrate more cleanly with the main query, using 'pre_get_posts' hook for example, and set parameters on it. Example:

      add_action('pre_get_posts', function(\WP_Query $query) {
                  if (!is_search() || !$query->is_search()) {
                      return;
                  }
                  $query->set('ep_integrate', true);
                  $query->set('posts_per_page', Search::POSTS_PER_LOAD);
                  $query->set('post_type', Search::get_post_types());
                  $query->set('post_status', ['publish', 'inherit']);
                  $query->set('has_password', false);
                  $query->set('search_fields', [
                      'post_title', 'post_content', 'post_excerpt', 'post_author.display_name',
                  ]);
                  $query->set('meta_query', [
                      'key' => 'p4_do_not_index',
                      'compare' => 'NOT EXISTS',
                  ]);
      }, 10, 1);

      Alternatively, we can try to block the main query in that situation, maybe using 'do_parse_request' hook.

            Assignee:
            Florent Hernandez (Inactive)
            Reporter:
            Florent Hernandez (Inactive)
            Osong Agberndifor Osong Agberndifor
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:

                This issue has been migrated to a new Jira instance:

                PLANET-7485