How can I configure (or code?) the module to suggest whole words only when using "Search API autocomplete" module?

Example: user type "som" and she will be suggested with "some" but not with "som" itself?

Thanks.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sgurlt’s picture

The answer could be found here https://www.drupal.org/node/2091995
See comment #13

Amir Simantov’s picture

Hi and thanks. I am currently not using Solr as a service class but search_api_db. The other post you have referred me to is interesting but only deals with Solr... Any other ideas? Or should it be addressed in the search_api_db queue? Thanks once again! Amir

drunken monkey’s picture

Project: Search API Autocomplete » Search API Database Search
Version: 7.x-1.1 » 7.x-1.4

This definitely belongs into the DB backend's issue queue, yes. The Autocomplete module has no control over the suggestions that are displayed.
However, as noted in the other issue, I have no idea at all how this could happen. In the DB backend, only complete words should ever be present in the index, and only words from the index should appear as suggestions.

Can you maybe take a look into your database (table name search_api_db_INDEX_text) and see whether "som" or other incomplete words are present there?
Are you using the "Tokenizer" processor for your search index? If so, what is its configuration?

Amir Simantov’s picture

FileSize
17.08 KB

Thanks for helping me understand which module is responsible for returning the values.

I have looked at the table "search_api_db_partial_word_index_text" for my index - only whole words are listed there.
Tokenizer processor is not enabled.

I am adding a three pictures here - of three example searching - just to make sure that I have be made the issue clear:

1
In the above picture - I want only the first 5 suggestions. I do not want the last 5 ones.

Just to make sure there is no 'wor' word indexed, I have queried:

SELECT * FROM `search_api_db_partial_word_index_text`
WHERE `word` like 'som'

The query brings 0 results

Was I helpful for you to help me?...

Thanks again.

drunken monkey’s picture

Version: 7.x-1.4 » 7.x-1.x-dev
Status: Active » Needs review
Issue tags: +needs Drupal 8 port
FileSize
2.54 KB

Ah, yes, thank you very much!
I now spotted the problem: it seems we didn't quite think of this in #1299238: Add option for partial matching and now, when you have enabled the "Search on parts of a word" option, you will also get incomplete words in your suggestions.
Once found, the bug was easy to fix: please see (and test) the attached patch.
(Would be great if we could add a test for this, but it would unfortunately be very hard to test the autocomplete functionality.)

This will also need to be ported to D8.

Amir Simantov’s picture

Hi Thomas, thanks for taking the time and making the patch. I wanted to test it carefully before adding my comment here.

It works to some degree. I am not sure whether there is anything more to do or not, as I am not inside the very code. So, here is my findings, and you can tell me if this "the best we can do" or some other tweak might be added.

Indexed words: siva, sivakosa (and more). That is, the string "siva" is both a whole word and, occasionally, a part of a word.

Typing the string "siv" gives us this:
siv
So it seems nice when the typed string is part of a word only.

However, typing the string "siva" gives us this:
siva
And this is a bit not what I would expect.
Problems are:
1. A result "siva" itself is not suggested - that is, without accompanying second word.
2. I do not want the 2 words results at all.

So... Anything here from your part?

Thanks once again,
Amir

drunken monkey’s picture

Status: Needs review » Reviewed & tested by the community

Thanks for testing, good to hear it works!

1. A result "siva" itself is not suggested - that is, without accompanying second word.

For "siva", the user can just press "Enter" – whether it's useful to still explicitly suggest it is at least debatable. In any case, it's a different issue.

2. I do not want the 2 words results at all.

Just disable "Suggest additional words" in the database server's autocomplete settings.

So, on the whole, this issue seems to be fixed with the provided patch? Then, if you have no further comments, I'll just commit it in the next days.

Amir Simantov’s picture

Hi and thanks for the fast reply. Let's see:

Disable "Suggest additional words" in the database server. - Worked, thanks.

Suggesting the typed string if it is - in itself - a whole word indexed. - Do we have an issue in the queue for it or should I open one?

Another question, however, sneaking in before doors are shut...
Isn't a suggestion supposed to appear even in the case of typing part of it not from the beginning? That is, following the "siva" string example above, shouldn't the words be suggested when typing "iva"? That is, without the first letter "s", in thi case. If by design id does not show them then I will open a feature request issue. If it is a bug - is there an issue for it?

Thanks.

drunken monkey’s picture

Project: Search API Database Search » Search API
Version: 7.x-1.x-dev » 8.x-1.x-dev
Component: Code » Database backend
Category: Support request » Bug report
Status: Reviewed & tested by the community » Patch (to be ported)
Issue tags: -needs Drupal 8 port

OK, committed.

As far as I know, there are no issues for the two feature requests you mention. (And the second one is by design, so they'd both be feature requests.)

Moving this issue to Search API 8.x so the patch can be ported.

Amir Simantov’s picture

Issue summary: View changes

Added a context "Search API autocomplete module".

Amir Simantov’s picture

Y.sa’s picture

D8 port of the patch #5

Y.sa’s picture

Status: Patch (to be ported) » Needs review
Nick_vh’s picture

  1. +++ b/search_api_db/src/Plugin/search_api/backend/Database.php
    @@ -1996,7 +1996,7 @@ class Database extends BackendPluginBase {
    +    $limit /= ceil(count($passes));
    

    I don't quite like that syntax. Is this something that is even allowed in Drupal core code standards? I mean. Could it ever divide itself by zero?

  2. +++ b/search_api_db/src/Plugin/search_api/backend/Database.php
    @@ -2024,7 +2030,7 @@ class Database extends BackendPluginBase {
    +          return array();
    

    I can't see it here, but is the documentation updated to mention it can return an empty array?

drunken monkey’s picture

Thanks a lot for the patch, Yannick, looks very good! It's really good to have help with porting all these old patches …

To address Nick's concerns:

I don't quite like that syntax. Is this something that is even allowed in Drupal core code standards? I mean. Could it ever divide itself by zero?

That's two entirely different questions. Is the syntax allowed? I wouldn't see why not. I think it's clear enough what it does, it's concise and I don't think making it more verbose would really increase readability.
But could that lead to a division by zero? Yes, yes it could. That's not the fault of the syntax, though, but of the logic. I'm putting in a check now. Thanks a lot for pointing this out!

However, the third question, which you've missed, is: Is this line complete and utter nonsense? Why, yes, yes it is! We of course want to apply ceil() to $limit after the division, not to the count (which is always an integer anyways) before.
So, fixed that, too (in the patch and with a quick commit in D7). Lucky you quoted that line and I spotted it this time.
(Just to be clear, this was in my D7 patch and commit already, so it's completely my own fault.)

I can't see it here, but is the documentation updated to mention it can return an empty array?

Since the search_api_autocomplete module doesn't even have a D8 branch yet, there isn't really a documentation per se. However, since it's perfectly possible that a successful search would also find no suggestions, it's of course legal to return an empty array.

  • drunken monkey committed 8bea7d2 on 8.x-1.x authored by Y.sa
    Issue #2400795 by Y.sa, drunken monkey: Fixed autocomplete suggestions...
drunken monkey’s picture

Status: Needs review » Fixed

Committed.
Thanks again!

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Ehm...so how do I enable the partial searching for db backend?