X-Git-Url: http://gitweb.fperrin.net/?p=Dictionary.git;a=blobdiff_plain;f=src%2Fcom%2Fhughes%2Fandroid%2Fdictionary%2Fengine%2FIndex.java;fp=src%2Fcom%2Fhughes%2Fandroid%2Fdictionary%2Fengine%2FIndex.java;h=0c07472dabf207f82c1e206785d2a5471d67ce84;hp=67f01fa48bb4f1dd9f6ffc1b1353e39b47ab24a0;hb=ff4d0ecbea69106b98b74960d731c20a7d458da1;hpb=ebaed3801560ba0816da039ebb98219f7638b24f diff --git a/src/com/hughes/android/dictionary/engine/Index.java b/src/com/hughes/android/dictionary/engine/Index.java index 67f01fa..0c07472 100644 --- a/src/com/hughes/android/dictionary/engine/Index.java +++ b/src/com/hughes/android/dictionary/engine/Index.java @@ -312,6 +312,7 @@ public final class Index { } private int findInsertionPointIndex(String token, final AtomicBoolean interrupted) { + String orig_token = token; token = normalizeToken(token); int start = 0; @@ -329,7 +330,8 @@ public final class Index { if (comp == 0) comp = sortCollator.compare(token, midEntry.normalizedToken()); if (comp == 0) { - return windBackCase(token, mid, interrupted); + start = end = mid; + break; } else if (comp < 0) { // System.out.println("Upper bound: " + midEntry + ", norm=" + // midEntry.normalizedToken() + ", mid=" + mid); @@ -366,6 +368,23 @@ public final class Index { start--; } + // If the search term was normalized, try to find an exact match first + if (!orig_token.equalsIgnoreCase(token)) { + int matchLen = findMatchLen(sortCollator, token, sortedIndexEntries.get(start).normalizedToken()); + int scan = start; + while (scan >= 0 && scan < sortedIndexEntries.size()) { + IndexEntry e = sortedIndexEntries.get(scan); + if (e.token.equalsIgnoreCase(orig_token)) + { + return scan; + } + if (matchLen > findMatchLen(sortCollator, token, e.normalizedToken())) + break; + if (interrupted.get()) return start; + scan++; + } + } + // If we search for a substring of a string that's in there, return // that. int result = Math.min(start, sortedIndexEntries.size() - 1);