I have some content types that I don't want to appear in GSA search results, but I don't see any option for limiting them. Any way to do this? Thanks in advance.

Comments

jweowu’s picture

The content type is added to pages as a meta tag, and therefore indexed by the GSA/Mini. This module does facilitate meta tag filtering (and indeed any arbitrary QueryParts), but you have to write some code to make it happen. Usage will depend upon how you generated your meta tags, but in short you want to build an $options array to pass to google_appliance_search() in order to generate the QueryParts you need.

The 'partialfields' and 'requiredfields' QueryParts enable you to match on meta tags. I recommend reading the GSA documentation regarding these options, as there are some pitfalls (e.g. limitations with AND/OR combinations, and the maximum limits on number of meta tags, and the amount of text per tag, that can be indexed).

See below for some example code (used with an older version of the module, but still relevant I think). That was a submission handler for a form which provided taxonomy terms in a select list. The terms appear in the pages as meta tags, and I convert the values into an $options['requiredfields'] entry when searching.

See theme_google_appliance_add_meta_tags() (which you can override in the usual fashion, of course) for meta tag generation. In one case I ended up writing an override so that I could put many values into a single meta tag (with 'partialfields' consequently used to match the values), as I ran into the indexing limits. I used a double-hyphen marker to delimit term boundaries, as the GSA treats hyphens as word characters (but practically nothing else other than the alpha-numeric chars).

/**
 * Example function for a customised search, demonstrating usage of
 * the google_appliance_search() $options parameter
 *
 * @param $client
 *   Which front end to use (NULL for default)
 * @param $collection
 *   Which collection to search (NULL for default)
 * @param $terms
 *   One or more term ids (comma-separated list)
 * @param $types
 *   One or more content types (comma-separated list)
 * @param $keys
 *   Search string
 */
function example_search($client = NULL, $collection = NULL, $terms = NULL, $types = NULL, $keys = NULL) {
  $output = "";

  if (!isset($_POST['form_id'])) {
    $options = array();

    $requiredfields = array();
    $vocabs = taxonomy_get_vocabularies();
    foreach (explode(',', $terms) as $tid) {
      if ($term = taxonomy_get_term($tid)) {
        $category = google_appliance_sgml_id_name('category-'. strtolower($vocabs[$term->vid]->name));
        $requiredfields[] = $category .':'. rawurlencode($term->name);
      }
    }
    foreach (explode(',', $types) as $type) {
      $requiredfields[] = 'type:'. rawurlencode($type);
    }
    if ($requiredfields) {
      $options['requiredfields'] = implode('.', $requiredfields); //'.' == AND; '|' == OR
    }

    if ($options || $keys) {
      if ($results = google_appliance_search('search', $keys, $options, $collection, $client)) {
        $output .= theme('box', t('Search results'), theme('search_results', $results, 'google-appliance'));
      }
      else {
        $message = variable_get('google_appliance_errorcode_1', t('Your search yielded no results'));
      }
    }
  }
  return $output;
}

Your other option is to configure your GSA/Mini front end to filter out hits on the meta tags in question. That's simpler to configure, but then you run into the problem of the appliance lying about the number of results it found. This problem crops up when any kind of result filtering is performed by the appliance, and it causes the Drupal search results pager to be wrong, so I recommend not doing this.

jweowu’s picture

Another option is to use the robots meta tag.

The GSA/Mini respects this, so you could add <meta name="robots" content="noindex" /> to your headers for the nodes which you do not want to be indexed.

Of course, this will also prevent google.com (and other search engines) from indexing those pages, so it rather depends on whether or not that is acceptable. If it is, then this is makes for an easy solution to the problem.