Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

42
LINES

< > BotCompany Repo | #1029005 // doubleWordIndex_lookupString

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (4134L/25K).

// returns a prefiltered list of elements; you still need to do a
// full-text search on those.
// If it returns null, you have to search all elements
static <A> Cl<A> doubleWordIndex_lookupString(DoubleWordIndex<A> index, S query, O... _) {
  optPar bool debug;
  L<IntRange> ranges = index.wordRanges(query);
  if (empty(ranges)) null;
  new L<Set<A>> sets;
  
  for (IntRange r : ranges) { // go through words in query
    S word = substring(query, r);
    Set<A> l;
    if (r.start == 0)
      if (r.end == l(query)) // bad case - look for part of word
        l = msmGetAllAsSet(index.index1.index, containingIC(index.index1.words(), word));
      else { // look for ending of word - use reverse index
        Cl<S> words = prefixSubSet(index.index2.words(), reversed(word));
        l = msmGetAllAsSet(index.index2.index, words);
        if (debug)
          print(n2(words) + "/" + nEntries(l) + " for: " + word);
      }
    else if (r.end == l(query)) { // look for start of word
      Cl<S> words = prefixSubSet(index.index1.words(), word);
      l = msmGetAllAsSet(index.index1.index, words);
      if (debug)
        print(n2(words) + "/" + nEntries(l) + " for: " + word);
    } else // look for complete word
      l = index.get(word);
    if (empty(l)) ret l;
    sets.add(l);
  }
  Set<A> smallest = smallestCollection(sets), out = smallest;
  for (Set<A> set : sets) {
    if (set == smallest) continue;
    new Set<A> out2;
    for (A a : out)
      if (set.contains(a))
        out2.add(a);
    out = out2;
  }
  ret out;
}

Author comment

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: 185 / 279
Version history: 3 change(s)
Referenced in: #1006654 - Standard functions list 2 (LIVE, continuation of #761)
#1029012 - deepDoubleWordIndex_lookupString