Autocomplete with results for a specific field

Created on 6 April 2022, over 2 years ago
Updated 28 February 2024, 10 months ago

Problem/Motivation

We have an event "power search" interface, where people can search based on multiple criteria. A text field is one of the filters, which is exposed as a form for user input. (The configuration).)

We would like to suggest completion for organization names from the values in the same field.

Instead, the completion suggestions are for node titles. Is there any configuration or trick for this?

Steps to reproduce

  1. Add a text field to a Search API search
  2. Use this field as a filter, exposed form
  3. Enable Search API Autocomplete for this field

The field autocompletes all right— but for node titles, not the value of the field.

Proposed resolution

Provide documentation for how to / an option to autocomplete on a per-field basis.

Remaining tasks

User interface changes

API changes

Data model changes

🐛 Bug report
Status

Fixed

Version

1.0

Component

Plugins

Created by

🇺🇸United States mlncn Minneapolis, MN, USA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • Open in Jenkins → Open on Drupal.org →
    Core: 9.5.x + Environment: PHP 8.1 & sqlite-3.27
    last update over 1 year ago
    34 pass
  • 🇦🇹Austria drunken monkey Vienna, Austria

    Thanks for reporting this problem, and sorry it took me so long to get back to you!

    I wanted to reply that this should already be working as described, at least for the “Retrieve from server” suggester, which should only suggest text values from the field for which autocompletion is executed.
    However, when I wanted to verify that this is working as it should, it failed for me. Apparently, Core changed the form array structure for Views at some point, causing this functionality to break.
    The attached patch should fix this again. Please test/review!

    (The Return a diferent field than the searched Closed: won't fix ticket seems unrelated, and like something that is also already implemented.)

  • Status changed to Fixed over 1 year ago
  • 🇦🇹Austria drunken monkey Vienna, Austria

    Since I could reproduce the issue, I think I’m just going to commit this now, and assume you don’t have the problem anymore. No wonder, after almost a year.
    Also, it seems like we already have a test for this, it just didn’t fail. For some strange reason, when the tests run the form structure is as expected, but it’s different when I try it myself in the browser, running the exact same code. I quickly gave up trying to make sense of that and just resigned myself to committing this without new tests.

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

  • Status changed to Fixed 10 months ago
  • 🇩🇪Germany stefan.korn Jossgrund

    I suppose that this bug is still persisting. Still getting the suggestions from all fields provided in any exposed filter (if having multiple fields exposed though). Even if there is an exposed field for which no suggestions where activated, the suggestions for the other fields will be provided there too.

    I could pin this down to:
    https://git.drupalcode.org/project/search_api_autocomplete/-/blame/8.x-1...

    if I comment this line out, it seems to work like expected. But I am not sure what's up about the $input and the $single_field_filter here.

    But the setExposedInput() - https://git.drupalcode.org/project/drupal/-/blob/10.2.x/core/modules/vie... - expects a string[] array. The actual implementation for the $single_field_filter case is not in line with this, at least my IDE is complaining.

  • 🇩🇪Germany stefan.korn Jossgrund

    Oh, it seems it depends on whether "Override used fields" in "Configure Suggester Retrieve from server" is configured or not.

    If there are fields configured, that it will not work as expected (showing suggestions in all exposed fields) and if there are no fields configured, it works like expected.

  • 🇩🇪Germany stefan.korn Jossgrund

    Okay, once more.

    It seems setFullTextFields() is possibly called twice in case the "override used fields" is configured:
    https://git.drupalcode.org/project/search_api_autocomplete/-/blob/8.x-1....

    This is overruling:
    https://git.drupalcode.org/project/search_api_autocomplete/-/blob/8.x-1....

    So maybe that is intended, but seems at least not intuitive.

    Inserting

          if (!$query->getFulltextFields()) {
            $query->setFulltextFields($this->configuration['fields']);
          }
    

    here might solve this.

Production build 0.71.5 2024