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

51
LINES

< > BotCompany Repo | #1028948 // Instant Full-Text Snippet Search

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

Uses 911K of libraries. Click here for Pure Java version (8389L/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  
    S mod = dm_require("#1028945/CacheAllSnippets");
26  
    SS data = cast dm_rcall getData(mod);
27  
    SS titles = cast dm_rcall getTitles(mod);
28  
    new L<SearchResult> out;
29  
    if (nempty(query)) {
30  
      time "Full-Text Search" {
31  
        fOr ping (S snippetID, text : data) {
32  
          S title = titles.get(snippetID);
33  
          int n = 
34  
            countOccurrencesIC(title, query)
35  
            + countOccurrences_optimizedForZero(text, query);
36  
          if (n > 0) {
37  
            new SearchResult r;
38  
            r.snippetID = snippetID;
39  
            r.title = title;
40  
            r.occurrences = n;
41  
            out.add(r);
42  
            if (l(out) >= maxResults) break;
43  
          }
44  
        }
45  
      }
46  
    }
47  
    sortInPlaceByCalculatedFieldDesc(out, r -> r.occurrences);
48  
    setField(status := empty(query) ? " " : "Found " + addPlusToCount(maxResults, l(out), nSnippets(out) + " in " + lastTiming() + " ms");
49  
    setList(out);
50  
  }
51  
}

Author comment

Began life as a copy of #1028144

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: #1028948
Snippet name: Instant Full-Text Snippet Search
Eternal ID of this version: #1028948/14
Text MD5: b613036888966ef7bc6a65f4abd29525
Transpilation MD5: 5700c76751359dfa825d2b4afb5ca987
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-12 20:30:50
Source code size: 1435 bytes / 51 lines
Pitched / IR pitched: No / No
Views / Downloads: 283 / 2744
Version history: 13 change(s)
Referenced in: [show references]