diff options
author | Lionel Han <47760119+IGoByJoe@users.noreply.github.com> | 2020-09-04 19:02:50 -0700 |
---|---|---|
committer | Lionel Han <47760119+IGoByJoe@users.noreply.github.com> | 2020-09-04 19:02:50 -0700 |
commit | e11c71a94016e3fe2529d0523fd62401baf90093 (patch) | |
tree | 3364d6a9ab147247b90ce9e390f4aef945afd0c5 /src/client/util/SearchUtil.ts | |
parent | 4767a10336309c679da60fd244548414c055ac50 (diff) | |
parent | 2ef7900d1210bc0e5261e1d1f8fd1ba5f3a0ee4c (diff) |
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web into new_audio
Diffstat (limited to 'src/client/util/SearchUtil.ts')
-rw-r--r-- | src/client/util/SearchUtil.ts | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/src/client/util/SearchUtil.ts b/src/client/util/SearchUtil.ts index b63fc8991..b09eff849 100644 --- a/src/client/util/SearchUtil.ts +++ b/src/client/util/SearchUtil.ts @@ -23,12 +23,14 @@ export namespace SearchUtil { } export interface SearchParams { - hl?: boolean; + hl?: string; "hl.fl"?: string; start?: number; rows?: number; fq?: string; + sort?: string; allowAliases?: boolean; + onlyAliases?: boolean; "facet"?: string; "facet.field"?: string; } @@ -37,8 +39,12 @@ 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"); - const replacedQuery = query.replace(/type_t:([^ )])/g, (substring, arg) => `{!join from=id to=proto_i}type_t:${arg}`); - const gotten = await rp.get(rpquery, { qs: { ...options, sort: "lastModified_d desc", q: replacedQuery } }); + let replacedQuery = query.replace(/type_t:([^ )])/g, (substring, arg) => `{!join from=id to=proto_i}*:* AND ${arg}`); + if (options.onlyAliases) { + const header = query.match(/_[atnb]?:/) ? replacedQuery : "DEFAULT:" + replacedQuery; + replacedQuery = `{!join from=id to=proto_i}${header}`; + } + const gotten = await rp.get(rpquery, { qs: { ...options, q: replacedQuery } }); const result: IdSearchResult = gotten.startsWith("<") ? { ids: [], docs: [], numFound: 0, lines: [] } : JSON.parse(gotten); if (!returnDocs) { return result; @@ -80,6 +86,8 @@ export namespace SearchUtil { if (testDoc instanceof Doc && testDoc.type !== DocumentType.KVP && (options.allowAliases || testDoc.proto === undefined || theDocs.findIndex(d => Doc.AreProtosEqual(d, testDoc)) === -1)) { theDocs.push(testDoc); theLines.push([]); + } else { + result.numFound--; } } |