aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/search
diff options
context:
space:
mode:
authorusodhi <61431818+usodhi@users.noreply.github.com>2020-09-04 15:00:49 +0530
committerusodhi <61431818+usodhi@users.noreply.github.com>2020-09-04 15:00:49 +0530
commit1afe593b00b8002c24086d003d0e364260b80abd (patch)
tree672c96d6ccf7d68ac668a379b1c5a6ee6d393dbe /src/client/views/search
parentde49c6f52bf97f9b10008e8ca26e767b71b49abd (diff)
parent7f6f5acc59e772cb828b8e532e16d4c40465de65 (diff)
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into acls_uv
Diffstat (limited to 'src/client/views/search')
-rw-r--r--src/client/views/search/SearchBox.tsx42
1 files changed, 24 insertions, 18 deletions
diff --git a/src/client/views/search/SearchBox.tsx b/src/client/views/search/SearchBox.tsx
index 3d564f073..b37ae02c3 100644
--- a/src/client/views/search/SearchBox.tsx
+++ b/src/client/views/search/SearchBox.tsx
@@ -45,7 +45,7 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
private _maxSearchIndex: number = 0;
private _curRequest?: Promise<any> = undefined;
private _disposers: { [name: string]: IReactionDisposer } = {};
- private _blockedTypes = [DocumentType.PRESELEMENT, DocumentType.KVP, DocumentType.DOCHOLDER, DocumentType.SEARCH, DocumentType.SEARCHITEM, DocumentType.FONTICON, DocumentType.BUTTON, DocumentType.SCRIPTING];
+ private _blockedTypes = [DocumentType.PRESELEMENT, DocumentType.KVP, DocumentType.FILTER, DocumentType.DOCHOLDER, DocumentType.SEARCH, DocumentType.SEARCHITEM, DocumentType.FONTICON, DocumentType.BUTTON, DocumentType.SCRIPTING];
private docsforfilter: Doc[] | undefined = [];
private realTotalResults: number = 0;
@@ -179,6 +179,21 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
return finalDocs;
}
+ static foreachRecursiveDoc(docs: Doc[], func: (doc: Doc) => void) {
+ let newarray: Doc[] = [];
+ while (docs.length > 0) {
+ newarray = [];
+ docs.forEach(d => {
+ const fieldKey = Doc.LayoutFieldKey(d);
+ const annos = !Field.toString(Doc.LayoutField(d) as Field).includes("CollectionView");
+ const data = d[annos ? fieldKey + "-annotations" : fieldKey];
+ data && newarray.push(...DocListCast(data));
+ func(d);
+ });
+ docs = newarray;
+ }
+ }
+
@action
searchCollection(query: string) {
const selectedCollection = this.currentSelectedCollection;//SelectionManager.SelectedDocuments()[0];
@@ -186,23 +201,14 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
if (selectedCollection !== undefined) {
// this._currentSelectedCollection = selectedCollection;
- let docs = DocListCast(selectedCollection.dataDoc[Doc.LayoutFieldKey(selectedCollection.dataDoc)]);
+ const docs = DocListCast(selectedCollection.dataDoc[Doc.LayoutFieldKey(selectedCollection.dataDoc)]);
const found: [Doc, string[], string[]][] = [];
- let newarray: Doc[] = [];
-
- while (docs.length > 0) {
- newarray = [];
- docs.forEach((d) => {
- d.data && newarray.push(...DocListCast(d.data));
- const hlights = new Set<string>();
- this.documentKeys(d).forEach(key =>
- Field.toString(d[key] as Field).toLowerCase().includes(query) && hlights.add(key));
- if (Array.from(hlights.keys()).length > 0) {
- found.push([d, Array.from(hlights.keys()), []]);
- }
- });
- docs = newarray;
- }
+ SearchBox.foreachRecursiveDoc(docs, (doc: Doc) => {
+ const hlights = new Set<string>();
+ SearchBox.documentKeys(doc).forEach(key => Field.toString(doc[key] as Field).toLowerCase().includes(query) && hlights.add(key));
+ Array.from(hlights.keys()).length > 0 && found.push([doc, Array.from(hlights.keys()), []]);
+ });
+
this._results = found;
this.docsforfilter = this._results.map(r => r[0]);
this.setSearchFilter(selectedCollection, this.filter && found.length ? this.docsforfilter : undefined);
@@ -215,7 +221,7 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
}
- documentKeys(doc: Doc) {
+ static documentKeys(doc: Doc) {
const keys: { [key: string]: boolean } = {};
// bcz: ugh. this is untracked since otherwise a large collection of documents will blast the server for all their fields.
// then as each document's fields come back, we update the documents _proxies. Each time we do this, the whole schema will be