Figure out how to allow advanced search operands (alongside type:, category:)

Created on 9 May 2008, about 17 years ago
Updated 15 July 2025, about 18 hours ago

LIVE FROM THE MINNESOTA SEARCH SPRINT, this patch refactors the advanced search form and search keys so that modules can add additional "things" to search on. In the current code only node types, taxonomy terms, and languages are added to the advanced search form. Then, everywhere the search keys are processed, these three special use cases are checked for.

This patch makes the system more generic.

I've added two new hooks, hook_searchform and hook_searchkeys:

hook_searchform returns the form that gets added to the advanced search fieldset. For example,

function taxonomy_searchform() {
  if ($taxonomy = taxonomy_form_all(1)) {
    $form['category'] = array(
      '#type' => 'select',
      '#title' => t('Only in the category(s)'),
      '#prefix' => '<div class="criterion">',
      '#size' => 10,
      '#suffix' => '</div>',
      '#options' => $taxonomy,
      '#multiple' => TRUE,
    );
    return $form;
  }
}

Notice that the form returned does not included $form['advanced'] because it is relative to the advanced fieldset.

hook_searchkeys returns the keys used in this form along with the SQL to generate. hook_searchkeys may may also return additional join clause. For example,

function taxonomy_searchkeys() {
  return array(
    'category' => array(
      'where' => "tn.cid = '%s'",
      'join' => ' INNER JOIN {term_node} tn ON n.vid = tn.vid'
    ),
  );
}

I'm open to different hook names.

This patch accomplishes similar refactoring to the search_rankings patch #145242, although the two patches refactor different things for different purposes.

✨ Feature request
Status

Postponed: needs info

Version

11.0 πŸ”₯

Component

search.module

Created by

πŸ‡ΊπŸ‡ΈUnited States douggreen Winchester, VA

Live updates comments and jobs are added and updated live.
  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

  • stale-issue-cleanup

    To track issues in the developing policy for closing stale issues, [Policy, no patch] closing older issues

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States smustgrave

    Thank you for sharing your idea for improving Drupal.

    We are working to decide if this proposal meets the Criteria for evaluating proposed changes. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or there is no community support. Your thoughts on this will allow a decision to be made.

    Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.

    Thanks!

Production build 0.71.5 2024