From 4df85ecd5026127c27b147b34398822307715e54 Mon Sep 17 00:00:00 2001 From: Bob Zeleznik Date: Tue, 10 Sep 2019 21:36:42 -0400 Subject: fixed search highlighting --- .../views/collections/CollectionTreeView.tsx | 1 + src/client/views/nodes/DocumentView.tsx | 13 ++++++-- src/client/views/search/SearchBox.tsx | 38 +++++++++++----------- src/client/views/search/SearchItem.tsx | 12 ++++--- src/server/Search.ts | 3 -- src/server/index.ts | 3 -- 6 files changed, 38 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/client/views/collections/CollectionTreeView.tsx b/src/client/views/collections/CollectionTreeView.tsx index 50f03005c..e31fa0b40 100644 --- a/src/client/views/collections/CollectionTreeView.tsx +++ b/src/client/views/collections/CollectionTreeView.tsx @@ -373,6 +373,7 @@ class TreeView extends React.Component { style={{ color: this.props.document.isMinimized ? "red" : "black", background: Doc.IsBrushed(this.props.document) ? "#06121212" : "0", + fontWeight: this.props.document.search_string ? "bold" : undefined, outline: BoolCast(this.props.document.workspaceBrush) ? "dashed 1px #06123232" : undefined, pointerEvents: this.props.active() || SelectionManager.GetIsDragging() ? "all" : "none" }} > diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx index 1e755f121..73426b3dc 100644 --- a/src/client/views/nodes/DocumentView.tsx +++ b/src/client/views/nodes/DocumentView.tsx @@ -780,6 +780,10 @@ export class DocumentView extends DocComponent(Docu let fullDegree = Doc.isBrushedHighlightedDegree(this.props.Document); let borderRounding = StrCast(Doc.GetProto(this.props.Document).borderRounding); let localScale = this.props.ScreenToLocalTransform().Scale * fullDegree; + let searchHighlight = (!this.props.Document.search_fields ? (null) : +
+ {StrCast(this.props.Document.search_fields)} +
); return (
(Docu onDrop={this.onDrop} onContextMenu={this.onContextMenu} onPointerDown={this.onPointerDown} onClick={this.onClick} onPointerEnter={this.onPointerEnter} onPointerLeave={this.onPointerLeave} > - {!showTitle && !showCaption ? this.contents : + {!showTitle && !showCaption ? + this.props.Document.search_fields ?
+ {this.contents} + {searchHighlight} +
: + this.contents :
-
{this.contents}
@@ -828,6 +836,7 @@ export class DocumentView extends DocComponent(Docu
} + {searchHighlight}
} diff --git a/src/client/views/search/SearchBox.tsx b/src/client/views/search/SearchBox.tsx index 2e29838e6..b30fd83e8 100644 --- a/src/client/views/search/SearchBox.tsx +++ b/src/client/views/search/SearchBox.tsx @@ -1,25 +1,23 @@ -import * as React from 'react'; -import { observer } from 'mobx-react'; -import { observable, action, runInAction, flow, computed } from 'mobx'; -import "./SearchBox.scss"; -import "./FilterBox.scss"; -import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; -import { faTimes } from '@fortawesome/free-solid-svg-icons'; import { library } from '@fortawesome/fontawesome-svg-core'; -import { SetupDrag } from '../../util/DragManager'; -import { Docs } from '../../documents/Documents'; -import { NumCast, Cast } from '../../../new_fields/Types'; -import { Doc } from '../../../new_fields/Doc'; -import { SearchItem } from './SearchItem'; +import { faTimes } from '@fortawesome/free-solid-svg-icons'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; +import { action, computed, observable, runInAction } from 'mobx'; +import { observer } from 'mobx-react'; +import * as React from 'react'; import * as rp from 'request-promise'; +import { Doc } from '../../../new_fields/Doc'; import { Id } from '../../../new_fields/FieldSymbols'; -import { SearchUtil } from '../../util/SearchUtil'; +import { Cast, NumCast } from '../../../new_fields/Types'; import { RouteStore } from '../../../server/RouteStore'; -import { FilterBox } from './FilterBox'; -import { ReadStream } from 'fs'; -import * as $ from 'jquery'; -import { MainView } from '../MainView'; import { Utils } from '../../../Utils'; +import { Docs } from '../../documents/Documents'; +import { SetupDrag } from '../../util/DragManager'; +import { SearchUtil } from '../../util/SearchUtil'; +import { MainView } from '../MainView'; +import { FilterBox } from './FilterBox'; +import "./FilterBox.scss"; +import "./SearchBox.scss"; +import { SearchItem } from './SearchItem'; library.add(faTimes); @@ -304,14 +302,16 @@ export class SearchBox extends React.Component { this.getResults(this._searchString); if (i < this._results.length) result = this._results[i]; if (result) { - this._visibleElements[i] = ; + let highlights = Array.from([...Array.from(new Set(result[1]).values())]).filter(v => v !== "search_string"); + this._visibleElements[i] = ; this._isSearch[i] = "search"; } } else { result = this._results[i]; if (result) { - this._visibleElements[i] = ; + let highlights = Array.from([...Array.from(new Set(result[1]).values())]).filter(v => v !== "search_string"); + this._visibleElements[i] = ; this._isSearch[i] = "search"; } } diff --git a/src/client/views/search/SearchItem.tsx b/src/client/views/search/SearchItem.tsx index 0b722c086..30e0454f3 100644 --- a/src/client/views/search/SearchItem.tsx +++ b/src/client/views/search/SearchItem.tsx @@ -136,8 +136,13 @@ export class SearchItem extends React.Component { @observable _useIcons = true; @observable _displayDim = 50; + componentDidMount() { + this.props.doc.search_string = this.props.query; + this.props.doc.search_fields = this.props.highlighting.join(", "); + } componentWillUnmount() { this.props.doc.search_string = undefined; + this.props.doc.search_fields = undefined; } //@computed @@ -177,7 +182,6 @@ export class SearchItem extends React.Component { ContentScaling={scale} /> ; - this.props.doc.search_string = this.props.query; return docview; } let button = layoutresult.indexOf(DocumentType.PDF) !== -1 ? faFilePdf : @@ -231,8 +235,7 @@ export class SearchItem extends React.Component { Doc.BrushDoc(doc2); } } else { - DocumentManager.Instance.getAllDocumentViews(this.props.doc).forEach(element => - Doc.BrushDoc(element.props.Document)); + Doc.BrushDoc(this.props.doc); } } @@ -246,8 +249,7 @@ export class SearchItem extends React.Component { Doc.UnBrushDoc(doc2); } } else { - DocumentManager.Instance.getAllDocumentViews(this.props.doc). - forEach(element => Doc.UnBrushDoc(element.props.Document)); + Doc.UnBrushDoc(this.props.doc); } } diff --git a/src/server/Search.ts b/src/server/Search.ts index 4a408405a..723dc101b 100644 --- a/src/server/Search.ts +++ b/src/server/Search.ts @@ -32,13 +32,10 @@ export class Search { public async search(query: any) { try { - console.log("SEARCH " + query + " " + (this.url + "dash/select") + " " + query.q); - console.log(query); const searchResults = JSON.parse(await rp.get(this.url + "dash/select", { qs: query })); const { docs, numFound } = searchResults.response; - console.log("RESULTS " + numFound); const ids = docs.map((field: any) => field.id); return { ids, numFound, highlighting: searchResults.highlighting }; } catch { diff --git a/src/server/index.ts b/src/server/index.ts index 149bacf0f..50ce2b14e 100644 --- a/src/server/index.ts +++ b/src/server/index.ts @@ -198,15 +198,12 @@ const solrURL = "http://localhost:8983/solr/#/dash"; app.get("/search", async (req, res) => { const solrQuery: any = {}; - console.log("GOT SEARCH"); ["q", "fq", "start", "rows", "hl", "hl.fl"].forEach(key => solrQuery[key] = req.query[key]); if (solrQuery.q === undefined) { res.send([]); return; } - console.log("CALLING SEARCH") let results = await Search.Instance.search(solrQuery); - console.log("RETURNING SEARCH") res.send(results); }); -- cgit v1.2.3-70-g09d2