!7 sclass SimpleSnippetSearch extends DynModule { S query; L result; bool fullTextSearch; transient int maxInputLength = 120; transient int maxResults = 100; transient WaitForStableValue waitForStableValue = new(1.0); transient volatile bool calculating; transient JTable table; transient ReliableSingleThread rst; transient SimpleLiveValue lvQuery = stringLiveValue(); transient SimpleLiveValue lvResultsTitle = stringLiveValue(); visualize { SimpleLiveValue lvFullTextSearch = dm_fieldLiveValue('fullTextSearch); lvFullTextSearch.onChange(r forceNewSearch); ret withRightAlignedButtons( jLiveValueCheckBox("Full Text Search", lvFullTextSearch), jLiveValueSection(lvResultsTitle, dataToTable_uneditable(result, table = sexyTable()))); } void forceNewSearch { setField(query := null); } start { lvQuery.set(query); doEvery(500, r update); } void update { lock programLock(); S s = dm_getInterestingString(); if (nempty(s) && l(s) <= maxInputLength) waitForStableValue.set(s); fS q = waitForStableValue!; if (nempty(q) && neq(q, query) && allowedToSearch()) dm_q().add(r { calc(q) }); } void calc(S q) { if (eq(query, q)) ret; query = q; result = null; lvQuery.set(q); tempSetField(this, calculating := true); tbSearch_quick.set(!fullTextSearch); tbSearch_html.set("want"); // We want the HTML too L l = tbSearch(maxResults, q); S html = tbSearch_html!; S desc = regexpExtractIC("Found (\\d+\\+?) snippets?", html); lvResultsTitle.set(or(desc, "No snippet results") + " for " + quote(q)); result = map(l, func(Snippet s) -> SS { litorderedmap("ID + Title" := snippetWithTitle(s) /*, "Type" := s.type*/ )}); JTable t = table; if (t != null) dataToTable_uneditable(result, t); } bool allowedToSearch() { true; } }