From a1d6cf23a902215b91433d26724a75a1844bd4dd Mon Sep 17 00:00:00 2001 From: Andy Rickert Date: Tue, 12 May 2020 23:02:23 -0700 Subject: setting up facets --- src/client/util/SearchUtil.ts | 2 + src/client/views/search/SearchBox.tsx | 63 +++++++++++++++------- src/client/views/search/SearchItem.tsx | 11 ++-- .../authentication/models/current_user_utils.ts | 1 - 4 files changed, 54 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/client/util/SearchUtil.ts b/src/client/util/SearchUtil.ts index 6501da34a..c2be385ae 100644 --- a/src/client/util/SearchUtil.ts +++ b/src/client/util/SearchUtil.ts @@ -35,7 +35,9 @@ export namespace SearchUtil { export async function Search(query: string, returnDocs: boolean, options: SearchParams = {}) { query = query || "*"; //If we just have a filter query, search for * as the query const rpquery = Utils.prepend("/dashsearch"); + console.log(query); const gotten = await rp.get(rpquery, { qs: { ...options, q: query } }); + console.log(gotten); const result: IdSearchResult = gotten.startsWith("<") ? { ids: [], docs: [], numFound: 0, lines: [] } : JSON.parse(gotten); if (!returnDocs) { return result; diff --git a/src/client/views/search/SearchBox.tsx b/src/client/views/search/SearchBox.tsx index e784580e5..632bcd211 100644 --- a/src/client/views/search/SearchBox.tsx +++ b/src/client/views/search/SearchBox.tsx @@ -116,12 +116,26 @@ export class SearchBox extends ViewBoxBaseComponent { console.log(this.setupButtons); if (this.setupButtons==false){ - console.log("Yuh"); this.setupDocTypeButtons(); this.setupKeyButtons(); this.setupDefaultButtons(); @@ -144,7 +158,7 @@ export class SearchBox extends ViewBoxBaseComponent { - this._searchString = StrCast(sq); + this.layoutDoc._searchString = StrCast(sq); this.submitSearch(); }); } @@ -156,7 +170,7 @@ export class SearchBox extends ViewBoxBaseComponent) { - this._searchString = e.target.value; + this.layoutDoc._searchString = e.target.value; this._openNoResults = false; this._results = []; @@ -341,9 +355,9 @@ export class SearchBox extends ViewBoxBaseComponent { - console.log(this._searchString); + console.log(StrCast(this.layoutDoc._searchString)); this.dataDoc[this.fieldKey] = new List([]); - const query = this._searchString; + const query = StrCast(this.layoutDoc._searchString); this.getFinalQuery(query); this._results = []; this._resultsSet.clear(); @@ -438,7 +452,7 @@ export class SearchBox extends ViewBoxBaseComponent(); startDragCollection = async () => { - const res = await this.getAllResults(this.getFinalQuery(this._searchString)); + const res = await this.getAllResults(this.getFinalQuery(StrCast(this.layoutDoc._searchString))); const filtered = this.filterDocsByType(res.docs); const docs = filtered.map(doc => { const isProto = Doc.GetT(doc, "isPrototype", "boolean", true); @@ -478,7 +492,7 @@ export class SearchBox extends ViewBoxBaseComponent= this._results.length) { - this.getResults(this._searchString); + this.getResults(StrCast(this.layoutDoc._searchString)); if (i < this._results.length) result = this._results[i]; if (result) { const highlights = Array.from([...Array.from(new Set(result[1]).values())]); - result[0].query=this._searchString; + result[0].query=StrCast(this.layoutDoc._searchString); //Make alias result[0].lines=new List(result[2]); - result[0].highlighting=new List(highlights); + result[0].highlighting=highlights.join(", "); - this._visibleElements[i] = ; + this._visibleDocuments[i] = result[0]; + //; result[0].targetDoc=result[0]; Doc.AddDocToList(this.dataDoc, this.props.fieldKey, result[0]); this._isSearch[i] = "search"; @@ -569,11 +584,12 @@ export class SearchBox extends ViewBoxBaseComponent(result[2]); - result[0].highlighting=new List(highlights); + result[0].highlighting=highlights.join(", "); - this._visibleElements[i] = ; + //this._visibleElements[i] = ; + this._visibleDocuments[i]=result[0]; result[0].targetDoc=result[0]; Doc.AddDocToList(this.dataDoc, this.props.fieldKey, result[0]) this._isSearch[i] = "search"; @@ -901,7 +917,9 @@ export class SearchBox extends ViewBoxBaseComponent this.layoutDoc._viewType === CollectionViewType.Stacking ? Cast(Doc.UserDoc().searchItemTemplate, Doc, null) : undefined; + @computed get searchItemTemplate() { return Cast(Doc.UserDoc().searchItemTemplate, Doc, null); } + + childLayoutTemplate = () => this.layoutDoc._viewType === CollectionViewType.Stacking ? this.searchItemTemplate: undefined; getTransform = () => { return this.props.ScreenToLocalTransform().translate(-5, -65);// listBox padding-left and pres-box-cont minHeight } @@ -923,10 +941,10 @@ export class SearchBox extends ViewBoxBaseComponent
- this._searchString ? this.startDragCollection() : undefined)} ref={this.collectionRef} title="Drag Results as Collection"> + StrCast(this.layoutDoc._searchString) ? this.startDragCollection() : undefined)} ref={this.collectionRef} title="Drag Results as Collection"> - @@ -980,4 +998,13 @@ export class SearchBox extends ViewBoxBaseComponent { - // I dont think this is the best functionality because clicking the name of the collection does that. Change it back if you'd like DocumentManager.Instance.jumpToDocument(this.targetDoc, false); } @observable _useIcons = true; @observable _displayDim = 50; + @computed get query() { return StrCast(this.lookupField("query")); } + componentDidMount() { - Doc.SetSearchQuery(StrCast(this.targetDoc.query)); + + console.log(this.query); + Doc.SetSearchQuery(this.query); this.targetDoc.searchMatch = true; } componentWillUnmount() { this.targetDoc.searchMatch = undefined; } - //@computed @action public DocumentIcon() { const layoutresult = StrCast(this.targetDoc.type); @@ -308,7 +310,8 @@ export class SearchItem extends ViewBoxBaseComponent
{StrCast(this.targetDoc.title)}
- {/*
{this.props.highlighting!.length ? "Matched fields:" + this.targetDoc.highlighting!.join(", ") : this.props.lines.length ? this.props.lines[0] : ""}
*/} +
{StrCast(this.targetDoc.highlighting).length ? "Matched fields:" + StrCast(this.targetDoc.highlighting) : //this.props.lines.length ? this.props.lines[0] : + ""}
{/* {this.props.lines!.filter((m, i) => i).map((l, i) =>
`${l}`
)} */}
diff --git a/src/server/authentication/models/current_user_utils.ts b/src/server/authentication/models/current_user_utils.ts index 782582930..bc024356d 100644 --- a/src/server/authentication/models/current_user_utils.ts +++ b/src/server/authentication/models/current_user_utils.ts @@ -633,7 +633,6 @@ export class CurrentUserUtils { // the initial presentation Doc to use static setupDefaultPresentation(doc: Doc) { - doc.searchItemTemplate = new PrefetchProxy(Docs.Create.SearchItemBoxDocument({ title: "search item template", backgroundColor: "transparent", _xMargin: 5, _height: 46, isTemplateDoc: true, isTemplateForField: "data" })); if (doc["template-presentation"] === undefined) { doc["template-presentation"] = new PrefetchProxy(Docs.Create.PresElementBoxDocument({ title: "pres element template", backgroundColor: "transparent", _xMargin: 5, _height: 46, isTemplateDoc: true, isTemplateForField: "data" -- cgit v1.2.3-70-g09d2