aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPřemysl Janouch <p.janouch@gmail.com>2016-09-27 03:47:36 +0200
committerPřemysl Janouch <p.janouch@gmail.com>2016-09-27 03:47:36 +0200
commitdb0579b7a025d7c97ea2add50b7cb13b2ad2c119 (patch)
tree332bfe79b2ba84dfcfcd7f115f7c9480c2e61285 /src
parentda6c46cba9a7e9fd982a82b89a23e812e1ff6d62 (diff)
downloadtdv-db0579b7a025d7c97ea2add50b7cb13b2ad2c119.tar.gz
tdv-db0579b7a025d7c97ea2add50b7cb13b2ad2c119.tar.xz
tdv-db0579b7a025d7c97ea2add50b7cb13b2ad2c119.zip
Improve partial matches
Diffstat (limited to 'src')
-rw-r--r--src/stardict.c31
1 files changed, 30 insertions, 1 deletions
diff --git a/src/stardict.c b/src/stardict.c
index cc69c07..b7e7be4 100644
--- a/src/stardict.c
+++ b/src/stardict.c
@@ -931,6 +931,35 @@ stardict_dict_search (StardictDict *sd, const gchar *word, gboolean *success)
BINARY_SEARCH_END
+ // Try to find a longer common prefix with a preceding entry
+#define PREFIX(i) stardict_longest_common_collation_prefix \
+ (sd, word, g_array_index (index, StardictIndexEntry, i).name)
+
+ if (sd->priv->collator)
+ {
+ GArray *collated = sd->priv->collated_index;
+ size_t probe, best = PREFIX (g_array_index (collated, guint32, imin));
+ while (imin > 0 && (probe =
+ PREFIX (g_array_index (collated, guint32, imin - 1))) >= best)
+ {
+ best = probe;
+ imin--;
+ }
+ }
+ else
+ {
+ // XXX: only looking for _better_ backward matches here, since the
+ // fallback common prefix searching algorithm doesn't ignore case
+ size_t probe, best = PREFIX (imin);
+ while (imin > 0 && (probe = PREFIX (imin - 1)) > best)
+ {
+ best = probe;
+ imin--;
+ }
+ }
+
+#undef PREFIX
+
if (success) *success = FALSE;
return stardict_iterator_new (sd, imin);
}
@@ -985,7 +1014,7 @@ stardict_longest_common_collation_prefix (StardictDict *sd,
if (!ucol_strcoll (sd->priv->collator, uc1, pos1, uc2, pos2))
longest = pos1;
}
- // I'd need a new collator, so just do the minimal working thing
+ // XXX: I'd need a new collator, so just do the minimal working thing
else if (pos1 == pos2 && !memcmp (uc1, uc2, pos1 * sizeof *uc1))
longest = pos1;
}