It will be great to have a method (with a hook, for example) to put meta tags in faceted search results.
I tried to use nodewords with patch #340642 but i have so many error with it :-(

Is in plan something like this?

Comments

David Lesieur’s picture

Could you detail more precisely what you'd like to achieve? Should this work on a per-search result page basis, or per-node in results basis? Could you give some examples of tags you'd like to add, and what data you'd like to use with those tags?

Also, is this something Nodewords ought to do but does not because of bugs or missing features?

eliosh’s picture

Hi David, thanks to answer me.
I have some web site using faceted search where FS is the main way to browse contents. On search results page (using guided search, i don't use for now keyword search) i'd like to have meta tag "keywords" and "description". The first, keyword metatag, could be filled with, for example, content type name, taxonomy terms, plus some other keywords generic defined for whole web site. Description metatag could be a composition in a phrase of some keywords (this is why i was thinking for a hook, so it could be generic).

How i try to do it with nodewords.
With drupal 5, i was capable of doing this using hook_nodewords and using it with this code:

function mymodule_nodewords(& $tags, $op, $a3, $a4) {
	if (arg(0) == 'fs' && arg(1) == 'results') {
		

		$labels = array ();

		global $_faceted_search;
		$env_id = 1;
		if($_faceted_search[$env_id]==null){
			$search = new faceted_search($env_id, arg(2));
		}else{
			$search = $_faceted_search[$env_id];
		}
		foreach ($search->get_filters() as $filter) {
			if ($filter->is_active()) {
				// Note: get_label() is responsible for filtering its returned string.
				$paths = $filter->get_active_path();
				foreach($paths as $path){
					$labels[] = $path->_name;
				}
			}
		}
		$tags['keywords'] = implode(',', $labels);
		$tags['description'] = t("Visualizza tutto, cercando per %values", array("%values" => implode(', ', $labels)));
	}
}

With drupal 6, i try to do similar code, but i have some error. This is the code i tried:

function mymodule_nodewords(& $tags, $op, $a3, $a4) {
	if (arg(0) == 'fs' && arg(1) == 'results') {
		$labels = array ();

		$env = faceted_search_env_load(1);

	    // Perform the search if has not been done previously. This should happen
	    // only when not on an actual search page.
	    if (!$env->ready()) {
	      $env->prepare();
	      $env->execute();
	    }

		foreach ($env->get_filters() as $index => $filter) {
			if ($filter->is_active()) {
				// $category = $filter->get_active_category();
				// Note: get_label() is responsible for filtering its returned string.
				// $labels[] = $category->get_label(FALSE);
				$paths = $filter->get_active_path();
				foreach($paths as $path){
					$labels[] = $path->_name;
				}
			}
		}

		drupal_set_message("Filter Text:" . $filter->get_text());
		$tags['keywords'] = implode(',', $labels);
		$tags['description'] = t("Visualizza tutto, cercando per %values", array("%values" => implode(', ', $labels)));

	}
}

I have errors if i try to "$env->execute". My execution works fine, but the second one, i think execution made by you, give me error on temp table creation (same table name).

If it's useful for you, this hook_nodewords is fired on nodewords_init.

While writing you this line, i was thinking: i can use hook_nodewords the same, without using faceted_search object, parsing by myself the query string. Can you point me the way to try this approach?

Thanks