Libraryless. Click here for Pure Java version (3871L/24K).
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> wordIndex_lookupString(WordIndex<A> index, S query) { |
5 | L<IntRange> ranges = index.wordRanges(query); |
6 | if (empty(ranges)) null; |
7 | new L<Set<A>> sets; |
8 | |
9 | for (IntRange r : ranges) { // go through words in query |
10 | S word = substring(query, r); |
11 | Set<A> l; |
12 | if (r.start == 0) |
13 | if (r.end == l(query)) |
14 | l = msmGetAllAsSet(index.index, containingIC(index.words(), word)); |
15 | else |
16 | l = msmGetAllAsSet(index.index, endingWithIC(index.words(), word)); |
17 | else if (r.end == l(query)) |
18 | l = msmGetAllAsSet(index.index, prefixSubSet(index.words(), word)); |
19 | else |
20 | l = index.get(word); |
21 | if (empty(l)) ret l; |
22 | sets.add(l); |
23 | } |
24 | Set<A> smallest = smallestCollection(sets), out = smallest; |
25 | for (Set<A> set : sets) { |
26 | if (set == smallest) continue; |
27 | new Set<A> out2; |
28 | for (A a : out) |
29 | if (set.contains(a)) |
30 | out2.add(a); |
31 | out = out2; |
32 | } |
33 | ret out; |
34 | } |
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: | #1028973 |
Snippet name: | wordIndex_lookupString |
Eternal ID of this version: | #1028973/12 |
Text MD5: | 2122ffc37290d0a75f35ff1d27fe436a |
Transpilation MD5: | 016383dfc319861b4032be792faf4fb5 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-07-15 13:33:53 |
Source code size: | 1110 bytes / 34 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 265 / 401 |
Version history: | 11 change(s) |
Referenced in: | [show references] |