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

78
LINES

< > BotCompany Repo | #1029090 // Instant Full-Text Snippet Search v7 [using deep chunked bit-set word index, dev.]

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

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

1  
!7
2  
3  
sclass SearchResult {
4  
  S snippetID;
5  
  S title;
6  
  int occurrences;
7  
  
8  
  sS _fieldOrder = "snippetID title";
9  
}
10  
11  
cmodule FullTextSnippetSearch > DynTableWithInput2<SearchResult> {
12  
  switchable int maxResults = 1000;
13  
  switchable int maxTextLength = 100000;
14  
  transient S status;
15  
  
16  
  JComponent mainComponent() {
17  
    ret northAndCenterWithMargin(dm_rightAlignedLabel status(), super.mainComponent());
18  
  }
19  
  
20  
  start {
21  
    dontPersist();
22  
    //thread { warmUp(); }
23  
  }
24  
  
25  
  void calc {
26  
    setList(search(input, true));
27  
  }
28  
  
29  
  void warmUp enter {
30  
    benchFor5Seconds(r { hijackPrint(r { search("this is cool", false) }) });
31  
  }
32  
  
33  
  L<SearchResult> search(S input, bool setStatus) {
34  
    S mod = dm_require("#1028945/CacheAllSnippets");
35  
    SS data = cast dm_rcall getData(mod);
36  
    SS titles = cast dm_rcall getTitles(mod);
37  
    
38  
    S index = dm_require("#1029089/SnippetsDeepBitSetWordIndex");
39  
    long nanos = nanoTime();
40  
    
41  
    S query = upper(input);
42  
    Iterable<S> preSnippetIDs = cast dm_call(index, 'snippetPreSearch, query);
43  
    long nanos1 = nanoTime()-nanos;
44  
45  
    new L<SearchResult> out;
46  
    if (preSnippetIDs == null) preSnippetIDs = keys(data);
47  
    int scanned = 0;
48  
    if (nempty(query)) {
49  
      fOr ping (S snippetID : preSnippetIDs) {
50  
        S text = data.get(snippetID);
51  
        continue if l(text) > maxTextLength;
52  
        S title = titles.get(snippetID);
53  
        /*int n = 
54  
          countOccurrencesIC(title, query)
55  
          + countOccurrences_optimizedForZero(text, query);
56  
        bool found = n > 0;*/
57  
        scanned += l(text);
58  
        bool found = contains(text, query); 
59  
        if (found) {
60  
          new SearchResult r;
61  
          r.snippetID = snippetID;
62  
          r.title = title;
63  
          //r.occurrences = n;
64  
          out.add(r);
65  
          if (l(out) >= maxResults) break;
66  
        }
67  
      }
68  
    }
69  
    nanos = max(nanoTime()-nanos, 0);
70  
    if (setStatus) {
71  
      setField(status := empty(query) ? " " : "Found " + addPlusToCount(maxResults, l(out), nSnippets(out) + " in "
72  
        + formatDouble(nanoSecondsToMilliseconds(nanos1), 3)
73  
        + " / " + formatDouble(nanoSecondsToMilliseconds(nanos), 3)
74  
        + " ms"));
75  
    }
76  
    ret out;
77  
  }
78  
}

Author comment

Began life as a copy of #1029044

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: #1029090
Snippet name: Instant Full-Text Snippet Search v7 [using deep chunked bit-set word index, dev.]
Eternal ID of this version: #1029090/3
Text MD5: a20fca2c5cabbdb2aa785dc50789b219
Transpilation MD5: 1fcf60c38f187009fbcbb729265539ca
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-19 03:06:45
Source code size: 2266 bytes / 78 lines
Pitched / IR pitched: No / No
Views / Downloads: 188 / 743
Version history: 2 change(s)
Referenced in: [show references]