Hello,

first of all, thank you for this great module, simple to use and just neat !

I am not sure this is really a bug, but like said in the subject, the autocomplete will not give any result for words with upper-cases letters.
For exemple "Video" or "MOOC" won't return anything, when "video" or "mooc" will.
Maybe it is the way the module is designed, but it can be pretty disturbing especially when the user wants to search for a proper noun (like John or Paris).
Or maybe I missed something in the config ?

I thank you for your help or for any hints.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Clauce created an issue. See original summary.

Monkfish-FR’s picture

Hi Clauce,

I had the same issue. I've resolved this with:

  1. enable the "Ignore case" processor at admin/config/search/search-api/index/<YOUR_INDEX>/processors
  2. edit the modules/contrib/search_api_autocomplete/src/Controller/AutocompleteController.php at line 97, add this code:
    # beginning of code
          if ($search->getIndex()->isValidProcessor('transliteration')) {
            $langcode = $this->languageManager()->getCurrentLanguage()->getId();
            $keys = $this->transliterator->transliterate($keys, $langcode);
          }
    // ADD THE CODE BELOW
          if ($search->getIndex()->isValidProcessor('ignorecase')) {
            $keys = \Drupal\Component\Utility\Unicode::strtolower($keys);
          }
    // !
          $split_keys = $this->autocompleteHelper->splitKeys($keys);
    # rest of code
        

    It transforms the search terms in lowercase. It's work for me.

If you need a patch, tell me!

Regards,

Clauce’s picture

Fantastic, thanks, this is perfect, it saved my day.
I hope this will help improve the module development.

stephenrodrigo@yahoo.com’s picture

It's nice to have this as a patch @Monkfish-FR.

stephenrodrigo@yahoo.com’s picture

stephenrodrigo@yahoo.com’s picture

FileSize
1.3 KB
stephenrodrigo@yahoo.com’s picture

stephenrodrigo@yahoo.com’s picture

drunken monkey’s picture

Which server backend are you using, or which suggester (in case it's not "Retrieve from server")?

stephenrodrigo@yahoo.com’s picture

We are using - Acquia search API.
Also, use `Display live results` suggester.
We have an use case that - Client wants `Display live results` style suggestions but not to link to the node.

adammalone’s picture

Minor nitpick with patch in #8. I'd probably look to include \Drupal\Component\Utility\Unicode at the top of the class and then use the following for consistency $keys = Unicode::strtolower($keys);

adammalone’s picture

Status: Active » Needs work
stephenrodrigo@yahoo.com’s picture

stephenrodrigo@yahoo.com’s picture

Status: Needs work » Needs review

The last submitted patch, 8: autocomplete-without-case-sensitive-2947273-3.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

Status: Needs review » Needs work
drunken monkey’s picture

With the "Display live results" suggester, the query should have the exact same preprocessing as for a normal search, so it should already be case-insensitive.
For the "Retrieve from server" suggester, the backend in question would have to decide whether or not to lowercase the search keys. We can't decide that for them, as it might not make sense (or be necessary) in all cases. If you're using the Acquia Search backend, please either move this issue there, or to the Search API Solr module in case the same problem exists there, too.

gge’s picture

Hi,
Just applied #13 and everything is working as expected.
Without this patch "Display live results" suggester was not returning results if the entered word had first letter upper-case.

@drunken monkey here's a demo (simplytest.me) without patches, using "Display live results" suggester and also having "Ignore case" turned on. When searching "Apple" nothing shows up in the autocomplete but it does show the results when "apple" is entered.

Thank you!

drunken monkey’s picture

What backend are you using? If it’s the database backend, did you enable the “Ignore case” processor?

gge’s picture

@drunken monkey yes I'm using the database as backend and "Ignore case" was also enabled. Sorry for this late reply, somehow I missed it...

mvogel’s picture

@drunken monkey
it seems that the preprocessors maybe are forgotten for the live results.

I just added it like this, and everything is ok

--- search_api_autocomplete/src/Plugin/search_api_autocomplete/suggester/LiveResults.php	(date 1528358854000)
+++ search_api_autocomplete/src/Plugin/search_api_autocomplete/suggester/LiveResults.php	(date 1528358854000)
@@ -13,7 +13,7 @@
 use Drupal\search_api_autocomplete\Suggester\SuggesterPluginBase;
 use Drupal\search_api_autocomplete\Suggestion\SuggestionFactory;
 use Symfony\Component\DependencyInjection\ContainerInterface;
-
+use Drupal\search_api\Processor\ProcessorInterface;
 /**
  * Provides a suggester plugin that displays live results.
  *
@@ -187,6 +187,10 @@
     }
     $query->keys($user_input);
 
+    foreach ($index->getProcessorsByStage(ProcessorInterface::STAGE_PREPROCESS_QUERY) as $processor) {
+        $processor->preprocessSearchQuery($query);
+    }
+
     try {
       $results = $query->execute();
     }
drunken monkey’s picture

Version: 8.x-1.0-rc1 » 8.x-1.x-dev
Status: Needs work » Needs review

Ah, you’re right, I see now what’s happening: In the controller we do preprocess the query before handing it over to the suggester(s), but in the LiveResults suggester plugin we only then set the full keywords – which therefore won’t be processed.
The most reasonable fix here is probably to not preprocess prematurely in the controller, but only in plugins that need to do that explicitly (i.e., just Server, for the ones defined in this project).

Patch attached, please test/review!
And thanks for providing more information!

drunken monkey’s picture

Status: Needs review » Needs work

The last submitted patch, 23: 2947273-22--fix-live-results-query-preprocessing.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

drunken monkey’s picture

drunken monkey’s picture

Would be great if someone could review the patch, or test whether it fixes the issue for them. Then I can commit.

mvogel’s picture

works for me, thanks for the patch :)

  • drunken monkey committed 6fb49a5 on 8.x-1.x
    Issue #2947273 by drunken monkey: Fixed keywords preprocessing for “Live...
drunken monkey’s picture

Status: Needs review » Fixed

Good to hear, thanks for testing!
Committed.

Status: Fixed » Closed (fixed)

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