Warning: session_start(): open(/var/lib/php/sessions/sess_9gcjhq12u3eji1mdqmfuifsh9h, O_RDWR) failed: No space left on device (28) in /var/www/tb-usercake/models/config.php on line 51
Warning: session_start(): Failed to read session data: files (path: /var/lib/php/sessions) in /var/www/tb-usercake/models/config.php on line 51
!7
sclass SearchResult {
S snippetID;
S title;
int occurrences;
sS _fieldOrder = "snippetID title";
}
cmodule FullTextSnippetSearch > DynTableWithInput2 {
switchable int maxResults = 1000;
switchable int maxTextLength = 100000;
transient S status;
JComponent mainComponent() {
ret northAndCenterWithMargin(dm_rightAlignedLabel status(), super.mainComponent());
}
start {
dontPersist();
//thread { warmUp(); }
}
void calc {
setList(search(input, true));
}
void warmUp enter {
benchFor5Seconds(r { hijackPrint(r { search("this is cool", false) }) });
}
L search(S input, bool setStatus) {
S mod = dm_require("#1028945/CacheAllSnippets");
SS data = cast dm_rcall getData(mod);
SS titles = cast dm_rcall getTitles(mod);
S index = dm_require("#1029043/SnippetsDeepWordPairIndex");
long nanos = nanoTime();
S query = upper(input);
Iterable*virtual Pair>*/O> pre = cast dm_call(index, 'snippetPreSearch_withPositions, query);
long nanos1 = nanoTime()-nanos;
new L out;
if (pre == null) {
if (setStatus) print("No pres");
pre = mapI(keys(data), snippetID -> pair(snippetID, null));
}
int badPres = 0;
if (nempty(query)) {
fOr ping (O entry : pre) {
Pair> p = quickImportPair(entry);
S snippetID = p.a;
Cl positions = p.b;
S text = data.get(snippetID);
continue if l(text) > maxTextLength;
int n = 0;
if (positions == null)
n = countOccurrences(text, query);
else
for (int i : positions)
if (regionMatches(text, i, query, 0, l(query)))
++n;
else
++badPres;
bool found = n > 0;
if (found) {
S title = titles.get(snippetID);
new SearchResult r;
r.snippetID = snippetID;
r.title = title;
r.occurrences = n;
out.add(r);
if (l(out) >= maxResults) break;
}
}
}
//sortInPlaceByCalculatedFieldDesc(out, r -> r.occurrences);
nanos = max(nanoTime()-nanos, 0);
if (setStatus) {
print("Bad pres: " + badPres);
setField(status := empty(query) ? " " : "Found " + addPlusToCount(maxResults, l(out), nSnippets(out) + " in "
+ formatDouble(nanoSecondsToMilliseconds(nanos1), 3)
+ " / " + formatDouble(nanoSecondsToMilliseconds(nanos), 3)
+ " ms"));
}
ret out;
}
}