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

85
LINES

< > BotCompany Repo | #1029017 // Instant Full-Text Snippet Search v4.1 [using deep double 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 (8538L/43K).

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 query = upper(input);
35  
    S index = dm_require("#1029010/SnippetsDeepDoubleWordIndex");
36  
    Iterable</*virtual Pair<S, Cl<S>>*/O> pre = cast dm_call(index, 'snippetsContainingTextIC_preSearch_withPositions, query);
37  
38  
    S mod = dm_require("#1028945/CacheAllSnippets");
39  
    SS data = cast dm_rcall getData(mod);
40  
    SS titles = cast dm_rcall getTitles(mod);
41  
    new L<SearchResult> out;
42  
    if (pre == null) {
43  
      if (setStatus) print("No pres");
44  
      pre = mapI(keys(data), snippetID -> pair(snippetID, null));
45  
    }
46  
    long nanos = 0;
47  
    int badPres = 0;
48  
    if (nempty(query)) {
49  
      nanos = nanoTime();
50  
      fOr ping (O entry : pre) {
51  
        Pair<S, Cl<Int>> p = quickImportPair(entry);
52  
        S snippetID = p.a;
53  
        Cl<Int> positions = p.b;
54  
        S text = data.get(snippetID);
55  
        continue if l(text) > maxTextLength;
56  
        int n = 0;
57  
        if (positions == null)
58  
          n = countOccurrences(text, query);
59  
        else
60  
          for (int i : positions)
61  
            if (regionMatches(text, i, query, 0, l(query)))
62  
              ++n;
63  
            else
64  
              ++badPres;
65  
        bool found = n > 0;
66  
        if (found) {
67  
          S title = titles.get(snippetID);
68  
          new SearchResult r;
69  
          r.snippetID = snippetID;
70  
          r.title = title;
71  
          r.occurrences = n;
72  
          out.add(r);
73  
          if (l(out) >= maxResults) break;
74  
        }
75  
      }
76  
      nanos = max(nanoTime()-nanos, 0);
77  
    }
78  
    //sortInPlaceByCalculatedFieldDesc(out, r -> r.occurrences);
79  
    if (setStatus) {
80  
      print("Bad pres: " + badPres);
81  
      setField(status := empty(query) ? " " : "Found " + addPlusToCount(maxResults, l(out), nSnippets(out) + " in " + formatDouble(nanoSecondsToMilliseconds(nanos), 3) + " ms"));
82  
    }
83  
    ret out;
84  
  }
85  
}

Author comment

Began life as a copy of #1029014

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: #1029017
Snippet name: Instant Full-Text Snippet Search v4.1 [using deep double word index, dev.]
Eternal ID of this version: #1029017/10
Text MD5: 84d93e9b4df60ca465c8433eefabf4de
Transpilation MD5: 6affa460b7a0b2b51859ba23b5dab8a5
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-16 22:58:39
Source code size: 2551 bytes / 85 lines
Pitched / IR pitched: No / No
Views / Downloads: 218 / 1752
Version history: 9 change(s)
Referenced in: [show references]