Libraryless. Click here for Pure Java version (4134L/25K).
1 | // returns a prefiltered list of elements; you still need to do a |
2 | // full-text search on those. |
3 | // If it returns null, you have to search all elements |
4 | static <A> Cl<A> doubleWordIndex_lookupString(DoubleWordIndex<A> index, S query, O... _) { |
5 | optPar bool debug; |
6 | L<IntRange> ranges = index.wordRanges(query); |
7 | if (empty(ranges)) null; |
8 | new L<Set<A>> sets; |
9 | |
10 | for (IntRange r : ranges) { // go through words in query |
11 | S word = substring(query, r); |
12 | Set<A> l; |
13 | if (r.start == 0) |
14 | if (r.end == l(query)) // bad case - look for part of word |
15 | l = msmGetAllAsSet(index.index1.index, containingIC(index.index1.words(), word)); |
16 | else { // look for ending of word - use reverse index |
17 | Cl<S> words = prefixSubSet(index.index2.words(), reversed(word)); |
18 | l = msmGetAllAsSet(index.index2.index, words); |
19 | if (debug) |
20 | print(n2(words) + "/" + nEntries(l) + " for: " + word); |
21 | } |
22 | else if (r.end == l(query)) { // look for start of word |
23 | Cl<S> words = prefixSubSet(index.index1.words(), word); |
24 | l = msmGetAllAsSet(index.index1.index, words); |
25 | if (debug) |
26 | print(n2(words) + "/" + nEntries(l) + " for: " + word); |
27 | } else // look for complete word |
28 | l = index.get(word); |
29 | if (empty(l)) ret l; |
30 | sets.add(l); |
31 | } |
32 | Set<A> smallest = smallestCollection(sets), out = smallest; |
33 | for (Set<A> set : sets) { |
34 | if (set == smallest) continue; |
35 | new Set<A> out2; |
36 | for (A a : out) |
37 | if (set.contains(a)) |
38 | out2.add(a); |
39 | out = out2; |
40 | } |
41 | ret out; |
42 | } |
Began life as a copy of #1028973
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1029005 |
Snippet name: | doubleWordIndex_lookupString |
Eternal ID of this version: | #1029005/4 |
Text MD5: | 07aee06902a63921986271fd0e11076d |
Transpilation MD5: | 090f4254d1e46fd99dc5ea6b584b20c0 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-07-16 18:49:15 |
Source code size: | 1582 bytes / 42 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 231 / 342 |
Version history: | 3 change(s) |
Referenced in: | [show references] |