aboutsummaryrefslogtreecommitdiff
path: root/src/client/views/search
diff options
context:
space:
mode:
authorStanley Yip <33562077+yipstanley@users.noreply.github.com>2019-07-17 14:56:45 +0000
committerGitHub <noreply@github.com>2019-07-17 14:56:45 +0000
commit253813f3ed75c5bbc08f32a1e822ff922bfe185b (patch)
tree78cb59565eb78955e089a11d96011da79e0c81c7 /src/client/views/search
parentcfc5a68c1d93f937ada7ba905265b159ec8be2a9 (diff)
parentba25d48d52f6db6021f5149e39021f651af22317 (diff)
Merge branch 'master' into small_fix_0716
Diffstat (limited to 'src/client/views/search')
-rw-r--r--src/client/views/search/SearchBox.tsx19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/client/views/search/SearchBox.tsx b/src/client/views/search/SearchBox.tsx
index 108492e90..8399605fb 100644
--- a/src/client/views/search/SearchBox.tsx
+++ b/src/client/views/search/SearchBox.tsx
@@ -24,7 +24,7 @@ export class SearchBox extends React.Component {
@observable private _resultsOpen: boolean = false;
@observable private _searchbarOpen: boolean = false;
@observable private _results: [Doc, string[]][] = [];
- private _resultsSet = new Set<Doc>();
+ private _resultsSet = new Map<Doc, number>();
@observable private _openNoResults: boolean = false;
@observable private _visibleElements: JSX.Element[] = [];
@@ -143,16 +143,23 @@ export class SearchBox extends React.Component {
this._numTotalResults = res.numFound;
}
- const highlighing = res.highlighting || {};
+ const highlighting = res.highlighting || {};
+ const highlightList = res.docs.map(doc => highlighting[doc[Id]]);
const docs = await Promise.all(res.docs.map(doc => Cast(doc.extendsDoc, Doc, doc as any)));
+ const highlights: typeof res.highlighting = {};
+ docs.forEach((doc, index) => highlights[doc[Id]] = highlightList[index]);
let filteredDocs = FilterBox.Instance.filterDocsByType(docs);
runInAction(() => {
// this._results.push(...filteredDocs);
filteredDocs.forEach(doc => {
- if (!this._resultsSet.has(doc)) {
- const highlight = highlighing[doc[Id]];
- this._results.push([doc, highlight ? Object.keys(highlight).map(key => key.substring(0, key.length - 2)) : []]);
- this._resultsSet.add(doc);
+ const index = this._resultsSet.get(doc);
+ const highlight = highlights[doc[Id]];
+ const hlights = highlight ? Object.keys(highlight).map(key => key.substring(0, key.length - 2)) : []
+ if (index === undefined) {
+ this._resultsSet.set(doc, this._results.length);
+ this._results.push([doc, hlights]);
+ } else {
+ this._results[index][1].push(...hlights);
}
});
});