aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/SearchUtil.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/util/SearchUtil.ts')
-rw-r--r--src/client/util/SearchUtil.ts94
1 files changed, 49 insertions, 45 deletions
diff --git a/src/client/util/SearchUtil.ts b/src/client/util/SearchUtil.ts
index 79759a71d..d154c48a4 100644
--- a/src/client/util/SearchUtil.ts
+++ b/src/client/util/SearchUtil.ts
@@ -24,51 +24,57 @@ export namespace SearchUtil {
export interface SearchParams {
hl?: string;
- "hl.fl"?: string;
+ 'hl.fl'?: string;
start?: number;
rows?: number;
fq?: string;
sort?: string;
- allowAliases?: boolean;
- onlyAliases?: boolean;
- "facet"?: string;
- "facet.field"?: string;
+ allowEmbeddings?: boolean;
+ onlyEmbeddings?: boolean;
+ facet?: string;
+ 'facet.field'?: string;
}
export function Search(query: string, returnDocs: true, options?: SearchParams): Promise<DocSearchResult>;
export function Search(query: string, returnDocs: false, options?: SearchParams): Promise<IdSearchResult>;
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");
+ query = query || '*'; //If we just have a filter query, search for * as the query
+ const rpquery = Utils.prepend('/dashsearch');
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;
+ if (options.onlyEmbeddings) {
+ const header = query.match(/_[atnb]?:/) ? replacedQuery : 'DEFAULT:' + replacedQuery;
replacedQuery = `{!join from=id to=proto_i}* AND ${header}`;
}
//console.log("Q: " + replacedQuery + " fq: " + options.fq);
const gotten = await rp.get(rpquery, { qs: { ...options, q: replacedQuery } });
- const result: IdSearchResult = gotten.startsWith("<") ? { ids: [], docs: [], numFound: 0, lines: [] } : JSON.parse(gotten);
+ const result: IdSearchResult = gotten.startsWith('<') ? { ids: [], docs: [], numFound: 0, lines: [] } : JSON.parse(gotten);
if (!returnDocs) {
return result;
}
const { ids, highlighting } = result;
- const txtresult = query !== "*" && JSON.parse(await rp.get(Utils.prepend("/textsearch"), {
- qs: { ...options, q: query.replace(/^[ \+\?\*\|]*/, "") }, // a leading '+' leads to a server crash since findInFiles doesn't handle regex failures
- }));
+ const txtresult =
+ query !== '*' &&
+ JSON.parse(
+ await rp.get(Utils.prepend('/textsearch'), {
+ qs: { ...options, q: query.replace(/^[ \+\?\*\|]*/, '') }, // a leading '+' leads to a server crash since findInFiles doesn't handle regex failures
+ })
+ );
const fileids = txtresult ? txtresult.ids : [];
const newIds: string[] = [];
const newLines: string[][] = [];
- if (fileids) {
- await Promise.all(fileids.map(async (tr: string, i: number) => {
- const docQuery = "fileUpload_t:" + tr.substr(0, 7); //If we just have a filter query, search for * as the query
- const docResult = JSON.parse(await rp.get(Utils.prepend("/dashsearch"), { qs: { ...options, q: docQuery } }));
- newIds.push(...docResult.ids);
- newLines.push(...docResult.ids.map((dr: any) => txtresult.lines[i]));
- }));
- }
-
+ // bcz: we stopped storing fileUpload id's, so this won't find anything
+ // if (fileids) {
+ // await Promise.all(
+ // fileids.map(async (tr: string, i: number) => {
+ // const docQuery = 'fileUpload_t:' + tr.substr(0, 7); //If we just have a filter query, search for * as the query
+ // const docResult = JSON.parse(await rp.get(Utils.prepend('/dashsearch'), { qs: { ...options, q: docQuery } }));
+ // newIds.push(...docResult.ids);
+ // newLines.push(...docResult.ids.map((dr: any) => txtresult.lines[i]));
+ // })
+ // );
+ // }
const theDocs: Doc[] = [];
const theLines: string[][] = [];
@@ -86,7 +92,7 @@ export namespace SearchUtil {
const docs = ids.map((id: string) => docMap[id]).map(doc => doc as Doc);
for (let i = 0; i < ids.length; i++) {
const testDoc = docs[i];
- if (testDoc instanceof Doc && testDoc.type !== DocumentType.KVP && (options.allowAliases || testDoc.proto === undefined || theDocs.findIndex(d => Doc.AreProtosEqual(d, testDoc)) === -1)) {
+ if (testDoc instanceof Doc && testDoc.type !== DocumentType.KVP && (options.allowEmbeddings || testDoc.proto === undefined || theDocs.findIndex(d => Doc.AreProtosEqual(d, testDoc)) === -1)) {
theDocs.push(testDoc);
theLines.push([]);
} else {
@@ -97,48 +103,46 @@ export namespace SearchUtil {
return { docs: theDocs, numFound: Math.max(0, result.numFound), highlighting, lines: theLines };
}
- export async function GetAliasesOfDocument(doc: Doc): Promise<Doc[]>;
- export async function GetAliasesOfDocument(doc: Doc, returnDocs: false): Promise<string[]>;
- export async function GetAliasesOfDocument(doc: Doc, returnDocs = true): Promise<Doc[] | string[]> {
+ export async function GetEmbeddingsOfDocument(doc: Doc): Promise<Doc[]>;
+ export async function GetEmbeddingsOfDocument(doc: Doc, returnDocs: false): Promise<string[]>;
+ export async function GetEmbeddingsOfDocument(doc: Doc, returnDocs = true): Promise<Doc[] | string[]> {
const proto = Doc.GetProto(doc);
const protoId = proto[Id];
if (returnDocs) {
- return (await Search("", returnDocs, { fq: `proto_i:"${protoId}"`, allowAliases: true })).docs;
+ return (await Search('', returnDocs, { fq: `proto_i:"${protoId}"`, allowEmbeddings: true })).docs;
} else {
- return (await Search("", returnDocs, { fq: `proto_i:"${protoId}"`, allowAliases: true })).ids;
+ return (await Search('', returnDocs, { fq: `proto_i:"${protoId}"`, allowEmbeddings: true })).ids;
}
// return Search(`{!join from=id to=proto_i}id:${protoId}`, true);
}
export async function GetViewsOfDocument(doc: Doc): Promise<Doc[]> {
- const results = await Search("", true, { fq: `proto_i:"${doc[Id]}"` });
+ const results = await Search('', true, { fq: `proto_i:"${doc[Id]}"` });
return results.docs;
}
- export async function GetContextsOfDocument(doc: Doc): Promise<{ contexts: Doc[], aliasContexts: Doc[] }> {
- const docContexts = (await Search("", true, { fq: `data_l:"${doc[Id]}"` })).docs;
- const aliases = await GetAliasesOfDocument(doc, false);
- const aliasContexts = (await Promise.all(aliases.map(doc => Search("", true, { fq: `data_l:"${doc}"` }))));
- const contexts = { contexts: docContexts, aliasContexts: [] as Doc[] };
- aliasContexts.forEach(result => contexts.aliasContexts.push(...result.docs));
+ export async function GetContextsOfDocument(doc: Doc): Promise<{ contexts: Doc[]; embeddingContexts: Doc[] }> {
+ const docContexts = (await Search('', true, { fq: `data_l:"${doc[Id]}"` })).docs;
+ const embeddings = await GetEmbeddingsOfDocument(doc, false);
+ const embeddingContexts = await Promise.all(embeddings.map(doc => Search('', true, { fq: `data_l:"${doc}"` })));
+ const contexts = { contexts: docContexts, embeddingContexts: [] as Doc[] };
+ embeddingContexts.forEach(result => contexts.embeddingContexts.push(...result.docs));
return contexts;
}
- export async function GetContextIdsOfDocument(doc: Doc): Promise<{ contexts: string[], aliasContexts: string[] }> {
- const docContexts = (await Search("", false, { fq: `data_l:"${doc[Id]}"` })).ids;
- const aliases = await GetAliasesOfDocument(doc, false);
- const aliasContexts = (await Promise.all(aliases.map(doc => Search("", false, { fq: `data_l:"${doc}"` }))));
- const contexts = { contexts: docContexts, aliasContexts: [] as string[] };
- aliasContexts.forEach(result => contexts.aliasContexts.push(...result.ids));
+ export async function GetContextIdsOfDocument(doc: Doc): Promise<{ contexts: string[]; embeddingContexts: string[] }> {
+ const docContexts = (await Search('', false, { fq: `data_l:"${doc[Id]}"` })).ids;
+ const embeddings = await GetEmbeddingsOfDocument(doc, false);
+ const embeddingContexts = await Promise.all(embeddings.map(doc => Search('', false, { fq: `data_l:"${doc}"` })));
+ const contexts = { contexts: docContexts, embeddingContexts: [] as string[] };
+ embeddingContexts.forEach(result => contexts.embeddingContexts.push(...result.ids));
return contexts;
}
export async function GetAllDocs() {
- const query = "*";
+ const query = '*';
const response = await rp.get(Utils.prepend('/dashsearch'), {
- qs:
- { start: 0, rows: 10000, q: query },
-
+ qs: { start: 0, rows: 10000, q: query },
});
const result: IdSearchResult = JSON.parse(response);
const { ids, numFound, highlighting } = result;