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

59
LINES

< > BotCompany Repo | #1028975 // Instant Full-Text Snippet Search v2 [using word index, seems OK]

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

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

1  
!7
2  
3  
sclass SearchResult {
4  
  S snippetID;
5  
  S title;
6  
  int occurrences;
7  
  
8  
  sS _fieldOrder = "snippetID title occurrences";
9  
}
10  
11  
cmodule FullTextSnippetSearch > DynTableWithInput2<SearchResult> {
12  
  switchable int maxResults = 1000;
13  
  transient S status;
14  
  
15  
  JComponent mainComponent() {
16  
    ret northAndCenterWithMargin(dm_rightAlignedLabel status(), super.mainComponent());
17  
  }
18  
  
19  
  start {
20  
    dontPersist();
21  
  }
22  
  
23  
  void calc {
24  
    S query = upper(input);
25  
    
26  
    S index = dm_require("#1028972/SnippetsWordIndex");
27  
    Cl<S> preSnippetIDs = cast dm_call(index, 'snippetsContainingTextIC_preSearch, query);
28  
    print("Pre-search: " + (preSnippetIDs == null ? "-" : lstr(preSnippetIDs)));
29  
    
30  
    S mod = dm_require("#1028945/CacheAllSnippets");
31  
    SS data = cast dm_rcall getData(mod);
32  
    SS titles = cast dm_rcall getTitles(mod);
33  
    new L<SearchResult> out;
34  
    if (preSnippetIDs == null) preSnippetIDs = keys(data);
35  
    long nanos = 0;
36  
    if (nempty(query)) {
37  
      nanos = nanoTime();
38  
      fOr ping (S snippetID : preSnippetIDs) {
39  
        S text = data.get(snippetID);
40  
        S title = titles.get(snippetID);
41  
        int n = 
42  
          countOccurrencesIC(title, query)
43  
          + countOccurrences_optimizedForZero(text, query);
44  
        if (n > 0) {
45  
          new SearchResult r;
46  
          r.snippetID = snippetID;
47  
          r.title = title;
48  
          r.occurrences = n;
49  
          out.add(r);
50  
          if (l(out) >= maxResults) break;
51  
        }
52  
      }
53  
      nanos = max(nanoTime()-nanos, 0);
54  
    }
55  
    sortInPlaceByCalculatedFieldDesc(out, r -> r.occurrences);
56  
    setField(status := empty(query) ? " " : "Found " + addPlusToCount(maxResults, l(out), nSnippets(out) + " in " + formatDouble(nanoSecondsToMilliseconds(nanos), 3) + " ms"));
57  
    setList(out);
58  
  }
59  
}

Author comment

Began life as a copy of #1028948

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: #1028975
Snippet name: Instant Full-Text Snippet Search v2 [using word index, seems OK]
Eternal ID of this version: #1028975/8
Text MD5: 9ae02108b0ced589e535fb4793ed1ccd
Transpilation MD5: 035eb387428410c96dbec5f19ae7878c
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-15 02:05:05
Source code size: 1837 bytes / 59 lines
Pitched / IR pitched: No / No
Views / Downloads: 193 / 3338
Version history: 7 change(s)
Referenced in: [show references]