From e23cb36795dd490730f1ff5c06081ce777133433 Mon Sep 17 00:00:00 2001 From: Andy Rickert Date: Thu, 18 Jun 2020 16:09:50 -0400 Subject: refactored bucket algorithm to run much much faster --- src/client/views/search/SearchBox.tsx | 161 ++++++++++++++++----------------- src/client/views/search/SearchItem.tsx | 13 +-- 2 files changed, 83 insertions(+), 91 deletions(-) (limited to 'src') diff --git a/src/client/views/search/SearchBox.tsx b/src/client/views/search/SearchBox.tsx index 8ca3c8e95..746f32237 100644 --- a/src/client/views/search/SearchBox.tsx +++ b/src/client/views/search/SearchBox.tsx @@ -268,15 +268,15 @@ export class SearchBox extends ViewBoxBaseComponent { const layoutresult = Cast(doc.type, "string"); + if (layoutresult && !blockedTypes.includes(layoutresult)){ if (layoutresult && this._icons.includes(layoutresult)) { finalDocs.push(doc); } + } }); return finalDocs; } @@ -408,6 +408,7 @@ export class SearchBox extends ViewBoxBaseComponent; getResults = async (query: string) => { + console.log("Get"); if (this.lockPromise) { await this.lockPromise; } @@ -517,12 +519,25 @@ export class SearchBox extends ViewBoxBaseComponent highlights[doc[Id]] = highlightList[index]); const filteredDocs = this.filterDocsByType(docs); + runInAction(() => { - filteredDocs.forEach(doc => { + filteredDocs.forEach((doc,i) => { const index = this._resultsSet.get(doc); const highlight = highlights[doc[Id]]; const line = lines.get(doc[Id]) || []; const hlights = highlight ? Object.keys(highlight).map(key => key.substring(0, key.length - 2)) : []; + if (this.findCommonElements(hlights)){ + } + else{ + const layoutresult = Cast(doc.type, "string"); + if (layoutresult){ + if(this.new_buckets[layoutresult]===undefined){ + this.new_buckets[layoutresult]=1; + } + else { + this.new_buckets[layoutresult]=this.new_buckets[layoutresult]+1; + } + } if (index === undefined) { this._resultsSet.set(doc, this._results.length); this._results.push([doc, hlights, line]); @@ -530,6 +545,7 @@ export class SearchBox extends ViewBoxBaseComponent3 && this.expandedBucket===false){ + this.makenewbuckets(); + } this.resultsScrolled(); - res(); }); return this.lockPromise; @@ -652,8 +670,6 @@ export class SearchBox extends ViewBoxBaseComponent(this._numTotalResults === -1 ? 0 : this._numTotalResults); } - - for (let i = 0; i < this._numTotalResults; i++) { //if the index is out of the window then put a placeholder in //should ones that have already been found get set to placeholders? @@ -666,44 +682,50 @@ export class SearchBox extends ViewBoxBaseComponent= this._results.length) { this.getResults(StrCast(this.layoutDoc._searchString)); if (i < this._results.length) result = this._results[i]; if (result) { - if (!this.blockedTypes.includes(StrCast(result[0].type))){ - - if(this.new_buckets[StrCast(result[0].type)]===undefined){ - this.new_buckets[StrCast(result[0].type)]=1; - } - else { - this.new_buckets[StrCast(result[0].type)]=this.new_buckets[StrCast(result[0].type)]+1; - } const highlights = Array.from([...Array.from(new Set(result[1]).values())]); let lines = new List(result[2]); result[0]._height=46; result[0].lines=lines; result[0].highlighting=highlights.join(", "); this._visibleDocuments[i] = result[0]; - - this._isSearch[i] = "search"; - } - } - + this._isSearch[i] = "search"; + if (this._numTotalResults>3 && this.expandedBucket===false){ + let doctype = StrCast(result[0].type); + console.log(doctype); + if (doctype=== this.firststring){ + if (this.bucketcount[1]<3){ + result[0].parent= this.buckets![1]; + Doc.AddDocToList(this.buckets![1], this.props.fieldKey, result[0]); + this.bucketcount[1]+=1; + } + } + else if (doctype=== this.secondstring){ + if (this.bucketcount[2]<3){ + result[0].parent= this.buckets![2]; + Doc.AddDocToList(this.buckets![2], this.props.fieldKey, result[0]); + this.bucketcount[2]+=1; + } + } + else if (this.bucketcount[0]<3){ + //Doc.AddDocToList(this.buckets![0], this.props.fieldKey, result[0]); + //this.bucketcount[0]+=1; + Doc.AddDocToList(this.dataDoc, this.props.fieldKey, result[0]); + } + } + else { + Doc.AddDocToList(this.dataDoc, this.props.fieldKey, result[0]); + } + } } else { result = this._results[i]; if (result) { - if (!this.blockedTypes.includes(StrCast(result[0].type))){ - if(this.new_buckets[StrCast(result[0].type)]===undefined){ - this.new_buckets[StrCast(result[0].type)]=1; - } - else { - this.new_buckets[StrCast(result[0].type)]=this.new_buckets[StrCast(result[0].type)]+1; - } const highlights = Array.from([...Array.from(new Set(result[1]).values())]); - let lines = new List(result[2]); result[0]._height=46; result[0].lines= lines; @@ -711,45 +733,38 @@ export class SearchBox extends ViewBoxBaseComponent3 && this.expandedBucket===false){ + + if (StrCast(result[0].type)=== this.firststring){ + if (this.bucketcount[1]<3){ + result[0].parent= this.buckets![1]; + Doc.AddDocToList(this.buckets![1], this.props.fieldKey, result[0]); + this.bucketcount[1]+=1; + } + } + else if (StrCast(result[0].type)=== this.secondstring){ + if (this.bucketcount[2]<3){ + result[0].parent= this.buckets![2]; + Doc.AddDocToList(this.buckets![2], this.props.fieldKey, result[0]); + this.bucketcount[2]+=1; + } + } + else if (this.bucketcount[0]<3){ + //Doc.AddDocToList(this.buckets![0], this.props.fieldKey, result[0]); + //this.bucketcount[0]+=1; + Doc.AddDocToList(this.dataDoc, this.props.fieldKey, result[0]); + } } + else { + Doc.AddDocToList(this.dataDoc, this.props.fieldKey, result[0]); } } + } } } } } if (this._numTotalResults>3 && this.expandedBucket===false){ - this.makenewbuckets(); - for (let i = 0; i < this._numTotalResults; i++) { - let result = this._results[i]; - if (!this.blockedTypes.includes(StrCast(result[0].type))){ - if (this._isSearch[i] === "search" && (this._isSorted[i]===undefined ||this._isSorted[i]==="placeholder" )) { - if (StrCast(result[0].type)=== this.firststring && this.bucketcount[1]<3){ - result[0].parent= this.buckets![1]; - Doc.AddDocToList(this.buckets![1], this.props.fieldKey, result[0]); - this.bucketcount[1]+=1; - } - else if (StrCast(result[0].type)=== this.secondstring && this.bucketcount[2]<3){ - result[0].parent= this.buckets![2]; - Doc.AddDocToList(this.buckets![2], this.props.fieldKey, result[0]); - this.bucketcount[2]+=1; - } - else if (this.bucketcount[0]<3){ - //Doc.AddDocToList(this.buckets![0], this.props.fieldKey, result[0]); - //this.bucketcount[0]+=1; - const highlights = Array.from([...Array.from(new Set(result[1]).values())]); - let lines = new List(result[2]); - result[0]._height=46; - result[0].lines= lines; - result[0].highlighting=highlights.join(", "); - Doc.AddDocToList(this.dataDoc, this.props.fieldKey, result[0]); - } - - this._isSorted[i]="sorted"; - } - } - } - if (this.buckets![0]){ this.buckets![0]._height = this.bucketcount[0]*55 + 25; } @@ -759,24 +774,7 @@ export class SearchBox extends ViewBoxBaseComponent(result[2]); - result[0]._height=46; - result[0].lines= lines; - result[0].highlighting=highlights.join(", "); - Doc.AddDocToList(this.dataDoc, this.props.fieldKey, result[0]); - } - } - } - } - + } if (this._maxSearchIndex >= this._numTotalResults) { this._visibleElements.length = this._results.length; this._visibleDocuments.length = this._results.length; @@ -784,10 +782,11 @@ export class SearchBox extends ViewBoxBaseComponent arr2.includes(item)) + } - blockedTypes:string[]= ["preselement","docholder","collection","search","searchitem", "script", "fonticonbox", "button", "label"]; - blockedFields: string[]= ["layout"]; - @computed get resFull() { return this._numTotalResults <= 8; } diff --git a/src/client/views/search/SearchItem.tsx b/src/client/views/search/SearchItem.tsx index 8bbc3180c..356100a90 100644 --- a/src/client/views/search/SearchItem.tsx +++ b/src/client/views/search/SearchItem.tsx @@ -184,10 +184,6 @@ export class SearchItem extends ViewBoxBaseComponent this.rootDoc.searchIndex, - search => {console.log(NumCast(search));this.searchPos=NumCast(search) },{ fireImmediately: true } - ); this._reactionDisposer2 = reaction( () => this._useIcons, el=> { @@ -224,16 +220,13 @@ export class SearchItem extends ViewBoxBaseComponent this.rootDoc!.searchMatch = true, 0); this.rootDoc.searchIndex=NumCast(this.rootDoc.searchIndex); - - this.searchPos=NumCast(this.rootDoc!.searchIndex); this.length=NumCast(this.rootDoc!.length); } @@ -327,7 +318,6 @@ export class SearchItem extends ViewBoxBaseComponent this.rootDoc!.searchMatch2 = true, 0); this.rootDoc.searchIndex=NumCast(this.rootDoc.searchIndex); - this.searchPos=NumCast(this.rootDoc!.searchIndex); this.length=NumCast(this.rootDoc!.length); } @@ -428,6 +418,9 @@ export class SearchItem extends ViewBoxBaseComponent