First of all thanks for a great module and your work. Appreciated.

My case:
I am using a "views finder" with which I want to show categorized results when autocomplete is doing it's work. The results are categorized already by "content-type". What I would like to do is show the name of the "content-type" as a header above the content types result. So like (cars, faq, contact) as shown in the attachment.

My question
- what's the best practice to implement this feauture? what's the best place to implement this?

Thanks for your support in advance
Undersound

CommentFileSizeAuthor
finder_example.png11.44 KBundersound3

Comments

danielb’s picture

I'm not really sure what the best way to do that is. The array of autocomplete data is composed in the function finder_autocomplete_autocomplete() but you wouldn't want to really be inserting a new 'suggestion' as the heading. It's more like you'd want to prefix the first option in the group with a heading, and then use css trickery to make it look right. You could try adding that by overriding theme_finder_autocomplete_suggestion().
You could use a static variable to track what the current content type is, and when the function is called you check the option against the content type, if it's a new content type then add the heading.

danielb’s picture

Status: Active » Fixed

Can't really give much more advice that that, I haven't done this myself, so you're the guinea pig for this idea.

undersound3’s picture

Thanks for your reply.

This information is very helpful and I will give it a go this week.
I will post back any progress here.

undersound3’s picture

I have my theme_finder_autocomplete_suggestion() setup in template.php but am not sure how to properly debug this $option variable. Normaly I would use print_r ($option) but that's not working in this case.

Thanks for any advice

danielb’s picture

Use the devel module's dsm() function. The debug output will appear on the next page load.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

undersound3’s picture

undersound3’s picture

Status: Closed (fixed) » Active

Thanks debugging with dsm() function works and the output I receive on the next page load show's what I want to accomplish. That is:

Cars

car1
car2
car3

FAQ

faq1
faq2

Thing is that it's not showing up that way while doing a "live" search. As you can see it's missing the second content type "FAQ".

Cars

car1
car2
car3
faq1
faq2

My function at the moment:

function mytheme_finder_autocomplete_suggestion ($option, $finder_element)  {
	static $curr_content_type;

	$node = node_load($option->nid);

	if (!isset($curr_content_type) || $curr_content_type != $node->type) {
		$curr_content_type = $node->type;
                dsm($curr_content_type);
		return $curr_content_type . "<br />";
	}
	else {
                dsm($node->title);
		return  $node->title;
	}
}

What is it I'm doing wrong in this function?

Thanks in advance

danielb’s picture

I would start with something more like this

<?php

function mytheme_finder_autocomplete_suggestion($option, $finder_element)  {
  static $curr_content_type;

  $node = node_load($option->nid);

  $output = '';

  if (!isset($curr_content_type) || $curr_content_type != $node->type) {
    $curr_content_type = $node->type;
    $output .= '<div class="content-type-title">' . $curr_content_type . '</div>';
  }
  $output .= $node->title;
   return $output;
}

?>

I'm just going based off your code, and haven't checked the API or tested this or anything.

I don't know why your code didn't show the FAQ title though.

Anonymous’s picture

Your base code worked pretty after a little bit of tweaking, however if we are displaying multiple content types as listed above, is there any way to weight/order them using this system?

danielb’s picture

No, you have to set the ordering in Views, assuming it's a Views Finder. Can't really do it in a Node/User finder unless you hook in and hack the SQL or the results arrays.

danielb’s picture

Status: Active » Closed (duplicate)

I will be in a better position to make these features available if we stop using drupal core's autocomplete.
#1151136: Finder Autocomplete Revolution