+ if (dictFilename == null && intent.getStringExtra(C.SEARCH_TOKEN) != null)
+ {
+ final List<DictionaryInfo> dics = application.getDictionariesOnDevice(null);
+ final String search = intent.getStringExtra(C.SEARCH_TOKEN);
+ String bestFname = null;
+ String bestIndex = null;
+ int bestMatchLen = 2; // ignore shorter matches
+ AtomicBoolean dummy = new AtomicBoolean();
+ for (int i = 0; dictFilename == null && i < dics.size(); ++i)
+ {
+ try {
+ final String fname = dics.get(i).uncompressedFilename;
+ Dictionary dic = new Dictionary(new RandomAccessFile(new File(fname), "r"));
+ for (int j = 0; j < dic.indices.size(); ++j) {
+ Index idx = dic.indices.get(j);
+ if (idx.findExact(search) != null)
+ {
+ dictFilename = fname;
+ intent.putExtra(C.INDEX_SHORT_NAME, idx.shortName);
+ break;
+ }
+ int matchLen = getMatchLen(search, idx.findInsertionPoint(search, dummy));
+ if (matchLen > bestMatchLen)
+ {
+ dictFilename = fname;
+ intent.putExtra(C.INDEX_SHORT_NAME, idx.shortName);
+ bestMatchLen = matchLen;
+ }
+ }
+ } catch (Exception e) {}
+ }
+ }