]> gitweb.fperrin.net Git - Dictionary.git/commitdiff
Fix multiword search with incomplete words.
authorReimar Döffinger <Reimar.Doeffinger@gmx.de>
Sun, 21 Oct 2018 17:55:51 +0000 (19:55 +0200)
committerReimar Döffinger <Reimar.Doeffinger@gmx.de>
Sun, 21 Oct 2018 17:55:51 +0000 (19:55 +0200)
It would trip over if the dictionary contained
words with the same prefix starting with -.
Example is searching for
"sense des aiguilles" which would break the loop
upon encountering "-aige".
Which meant that searching for "sense des aig" would
find nothing. "sense des a" would however due to "a"
not being considered due to the stoplist.

src/com/hughes/android/dictionary/engine/Index.java
src/com/hughes/android/dictionary/engine/NormalizeComparator.java

index 30c18e2eb3bce1acd67ae9cac22d4ad102bb7637..ef6d11cadaaf41f02e33aeba51bdd5c20740ab62 100644 (file)
@@ -410,7 +410,8 @@ public final class Index implements RAFSerializable<Index> {
                 return -1;
             }
             final IndexEntry indexEntry = sortedIndexEntries.get(index);
                 return -1;
             }
             final IndexEntry indexEntry = sortedIndexEntries.get(index);
-            if (!indexEntry.normalizedToken.startsWith(normalizedPrefix)) {
+            if (!indexEntry.normalizedToken.startsWith(normalizedPrefix) &&
+                !NormalizeComparator.withoutDash(indexEntry.normalizedToken).startsWith(normalizedPrefix)) {
                 break;
             }
             rowCount += indexEntry.numRows + indexEntry.htmlEntries.size();
                 break;
             }
             rowCount += indexEntry.numRows + indexEntry.htmlEntries.size();
@@ -500,7 +501,8 @@ public final class Index implements RAFSerializable<Index> {
                 return null;
             }
             final IndexEntry indexEntry = sortedIndexEntries.get(index);
                 return null;
             }
             final IndexEntry indexEntry = sortedIndexEntries.get(index);
-            if (!indexEntry.normalizedToken.startsWith(searchToken)) {
+            if (!indexEntry.normalizedToken.startsWith(searchToken) &&
+                !NormalizeComparator.withoutDash(indexEntry.normalizedToken).startsWith(searchToken)) {
                 break;
             }
 
                 break;
             }
 
index efe05d1f58e0bd2cba2171ff7d47db90c9ca5cd7..c744334b150ea5073aa9081e71915a40de606656 100644 (file)
@@ -31,12 +31,16 @@ public class NormalizeComparator implements Comparator<String> {
         this.version = version;
     }
 
         this.version = version;
     }
 
+    public static String withoutDash(final String a) {
+        return a.replace("-", "").replace("þ", "th").replace("Þ", "Th");
+    }
+
     // Handles comparison between items containing "-".
     // Also replaces other problematic cases like "thorn".
     public static int compareWithoutDash(final String a, final String b, final Comparator<Object> c, int version) {
         if (version < 7) return 0;
     // Handles comparison between items containing "-".
     // Also replaces other problematic cases like "thorn".
     public static int compareWithoutDash(final String a, final String b, final Comparator<Object> c, int version) {
         if (version < 7) return 0;
-        String s1 = a.replace("-", "").replace("þ", "th").replace("Þ", "Th");
-        String s2 = b.replace("-", "").replace("þ", "th").replace("Þ", "Th");
+        String s1 = withoutDash(a);
+        String s2 = withoutDash(b);
         return c.compare(s1, s2);
     }
 
         return c.compare(s1, s2);
     }