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

37
LINES

< > BotCompany Repo | #1029025 // Snippets Deep Word Index [OK]

JavaX source code (Dynamic Module) [tags: use-pretranspiled] - run with: Stefan's OS

Uses 911K of libraries. Click here for Pure Java version (6519L/32K).

!7

cprint SnippetsDeepWordIndex {
  transient DeepWordIndex<S> wordIndex; // string = snippet ID
  switchable S regexp = "\\w+|\\S"; // a word or a non-space

  start-thread {
    dm_reloadOnFieldChange regexp();
    time "Make double word index" {
      print("Making index");
      new DeepWordIndex<S> wordIndex;
      wordIndex.regexp = regexp;
      wordIndex.useHashMaps = true;
      wordIndex.sortEntries = true;
      for (virtual CSnippet sn : dm_allSnippets()) {
        S snippetID = (S) rcall snippetID(sn);
        S text = cast rcall text(sn);
        wordIndex.add(snippetID, text);
      }
      wordIndex.doneAdding();
      setField(+wordIndex);
    }
    infoBox("Indexed " + nWords(wordIndex.numWords()));
  }
  
  // API
  
  Iterable<Pair<S, Cl<Int>>> snippetPreSearch_withPositions(S query, O... _) {
    long nanos = nanoTime();
    Iterable<Pair<S, Cl<Int>>> l;
    //time "lookup" {
      l = wordIndex == null ? null : wordIndex.lookupString_withPositions(query, _);
    //}
    //print((nanoTime()-nanos) + " nanos in pre");
    ret l;
  }
}

Author comment

Began life as a copy of #1029010

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: #1029025
Snippet name: Snippets Deep Word Index [OK]
Eternal ID of this version: #1029025/18
Text MD5: e4eb469b547db7a3134cd5bb5318ce1b
Transpilation MD5: 4f93bb17f21bffc4c552a154030dc7bc
Author: stefan
Category: javax
Type: JavaX source code (Dynamic Module)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-07-17 18:54:22
Source code size: 1109 bytes / 37 lines
Pitched / IR pitched: No / No
Views / Downloads: 191 / 708
Version history: 17 change(s)
Referenced in: [show references]