Hello Everybody,

To my mind it would be great to have ability to create multiple search autocomplete fields for a view without hacking of the module's core.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drumm’s picture

Agreed. For Drupal.org, we want to autocomplete separately on project name, related users, and tags. For Views, I don't really understand the use case of searching across all enabled fields, rather than just the one filter that the user is typing in.

drumm’s picture

Nevermind, I see the "Fields to use" setting can be left blank.

Rob230’s picture

Issue summary: View changes

Is this possible? I have multiple fulltext search filters that work on different fields. When I enable and configure this module, it puts an autocomplete on the first one only. Is there anyway to put it on all of them, and return appropriate results?

Rob230’s picture

I have fixed this (patch attached). The problem was that I used multiple fulltext search filters (on different fields), but the code as it was would only detect the first one. Subsequent ones would be named e.g. 'search_api_views_fulltext_1', 'search_api_views_fulltext_2' etc. but the code was simply adding this:

$fields[] = 'search_api_views_fulltext';

and then finding that field like so:

$view->filter[$field]

So it never saw the ones named 'search_api_views_fulltext_1' etc.

I rewrote it to instead loop over each of the filters the view has, and check if the real_field (which is 'search_api_views_fulltext' for all of them) is in the $fields array.

drunken monkey’s picture

Status: Active » Needs review
FileSize
645 bytes
1.9 KB

Looks good, thanks! A quick test also seems to verify this works correctly.
Just one bug, I think:

+++ b/search_api_autocomplete.search_api_views.inc
@@ -30,21 +30,19 @@ function search_api_autocomplete_form_views_exposed_form_alter(array &$form, arr
+          else {
+            $autocomplete_fields = array($filter_name);
+          }

Unless I'm mistaken, the array should contain $filter->real_field, not the Views filter name (which will often be something different).
The attached patch would fix this, please test it again and I can commit it.
(Would be great to get some more reviews, to make sure this doesn't break anything, but unfortunately testers are hard to come by.)

PS: For the future: When you post a patch, please set the issue status to "Needs review" so I know there's something to look at.

drunken monkey’s picture

Could you, or someone else, please test this and verify it works?

  • drunken monkey committed 2f00a78 on 7.x-1.x authored by Rob230
    Issue #1983442 by Rob230, drunken monkey: Fixed problems with multiple...
drunken monkey’s picture

Status: Needs review » Fixed

I would have preferred at least one final review, but it will probably be OK.
Committed.
Still, thanks again for the patch!

Rob230’s picture

Sorry, I've been very busy. I just tested it and your patch works. Thanks.

Status: Fixed » Closed (fixed)

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