Autocompletion breaks for first character after space characters
Closed this issue · 3 comments
Hey,
I have been having an issue which can be reproduced even with the sample completely application. Basically, whenever a search term consists of two words, Completely will stop working if only one character is entered for the second word. To show this using an example from your sample application, here's what happens if you keep adding one character between every search:
Query: "Western"
- Western Sahara
Query: "Western "
- Western Sahara
Query: "Western S"
No Results
Query: "Western Sa"
- Western Sahara
In other words:
When searching "Western S", I would expect "Western Sahara" to be returned, however, Completely returns nothing. Once one more character is added - in the case the latter "a" - Completely becomes functional again. I have looked at your source code but I have not been able to see why this happens, however, I may have just missed something obvious.
Thank you for the feedback.
I confirm the described behaviour. The issue arises from the SampleAdapter
:
double threshold = Math.log(token.length() - 1);
Which for a single character, creates a Automaton with a invalid threshold.
new EditDistanceAutomaton(token, threshold)
I will create a test case for this situation.
I pushed a fix for the sample: e4a9a4b
The EditDistanceAutomaton API will change in the next version in order to prevent negative threshold.
As of version 0.6.0 the EditDistanceAutomaton will throw an IllegalArgumentException if threshold is negative.