The autocomplete result list does not always return a complete list of matches. This bug is similar to https://www.drupal.org/node/1430418#comment-5776092

You're attempting to limit the number of options to 10, but what is actually happening is that you've limited the number of records returned by the query to 10 -- the first 10.

To demonstrate, create a view on a large dataset with many duplicated values. Add an exposed filter with Autocomplete enabled. The pop-up autocomplete list will contain fewer than the requested number of results, depending on how many unique values appear in the first n rows of the view result.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

ikeigenwijs’s picture

I also stumbled in to this problem.

We have a short list of distinct values less than 200 but on 20k rows.
In query terms this should be no problem.

Setting the maximum number to return to 0 == no limit.

Gave no better result and longer waiting times.
Large php memory footprint and cascading Ajax errors

setting the minimum length when starting autocompleet did not help.

NWOM’s picture

I'm sadly having the same issue. I'm using an autocomplete on around 8000 entities, and it doesn't pull all of the results. If I change the filter back to a normal non-autocomplete filter, all results can be searched as expected.

For example, if I search for "Ra", it shows no results, but if I search for "Ab" it works. So it appears to stop after a certain number of entities.

NWOM’s picture

NWOM’s picture

NWOM’s picture

For me setting "Maximum number of items in Autocomplete results" to "0" did not help either

Edit:

I was able to isolate the issue even more. If I filter the view manually to include less results, the missing results are then shown in the suggestions as expected.

ikeigenwijs’s picture

Genu’s picture

This bug is due to the method used by the plugin to retrieve suggested values for auto complete.
It happens when you add a limit on the number of suggestions.

Let's assume we choose to set up a 10 suggestions limit.
To retrieve 10 suggested values, the view is executed and the 10-limit is applied on the view result. So, if results 1 to 10 of the view have only 1 single distinct value for the field used in autocomplete, you will get only 1 suggestion.
This is done in views_autocomplete_filters.inc, with the pager defined at line 115. You can see in following lines that the view is simply executed, and results read to build suggested values.

To fix this, the module should use an altered version of the view. It should:

  • remove all fields from the "select" part, except the ones needed to retrieve suggested values
  • add a distinct (the "pure" version, not the base distinct that force the add of nid in selected fields)

The code to do that has to be inserted between the pre_execute and the execute of the view :

  // Execute view query.
  $view->pre_execute();
   // HERE IS THE FIX
  $queryOptions = $display_handler->get_option('query');
  $queryOptions['options']['distinct'] = '1';
  $queryOptions['options']['pure_distinct'] = '1';
  $display_handler->set_option('query',$queryOptions);
  foreach ($view->field as $field_name => $field_obj) {
    if (!in_array($field_name, $field_names)) {
      unset($view->field[$field_name]);
      unset($view->display_handler->handlers['field'][$field_name]);
    }
  }
  // END OF THE FIX
  $view->execute($view->current_display);

Now, the query will do a "select distinct" on the fields used to build the suggest results. The page will limit on distinct values, so you will have exactly the desired number of suggested values. And since your query is focused only on needed data, performance are clearly better.

petrovichby’s picture

#7 worked for me. Thanks.

mitjasvab’s picture

Status: Active » Reviewed & tested by the community
FileSize
849 bytes

Hi,
I just assembled the patch #7 in a patch file. For me it is working too, so I set to Reviewed & tested.