aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorbobzel <zzzman@gmail.com>2020-08-20 12:12:19 -0400
committerbobzel <zzzman@gmail.com>2020-08-20 12:12:19 -0400
commitaa626240bff72456dccc7f91e433135e393cb161 (patch)
tree206143234c9994125a10492884cda41fb27b407b /src
parentc4c9c2e7ec10e19ee9fe9c0c93c4d7fe61328171 (diff)
more searchBox fixes.
Diffstat (limited to 'src')
-rw-r--r--src/client/util/SearchUtil.ts2
-rw-r--r--src/client/views/collections/CollectionSubView.tsx23
-rw-r--r--src/client/views/search/SearchBox.tsx62
3 files changed, 20 insertions, 67 deletions
diff --git a/src/client/util/SearchUtil.ts b/src/client/util/SearchUtil.ts
index ce96ab67b..afa8ff575 100644
--- a/src/client/util/SearchUtil.ts
+++ b/src/client/util/SearchUtil.ts
@@ -85,6 +85,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--;
}
}
diff --git a/src/client/views/collections/CollectionSubView.tsx b/src/client/views/collections/CollectionSubView.tsx
index 075be41fd..a1dd905c2 100644
--- a/src/client/views/collections/CollectionSubView.tsx
+++ b/src/client/views/collections/CollectionSubView.tsx
@@ -138,37 +138,24 @@ export function CollectionSubView<T, X>(schemaCtor: (doc: Doc) => T, moreProps?:
const docRangeFilters = this.props.ignoreFields?.includes("_docRangeFilters") ? [] : Cast(this.props.Document._docRangeFilters, listSpec("string"), []);
console.log(searchDocs);
searchDocs = DocUtils.FilterDocs(searchDocs, this.docFilters(), docRangeFilters, viewSpecScript);
- console.log(this.docFilters());
- console.log(searchDocs);
childDocs.forEach((d) => {
if (d.data !== undefined) {
let newdocs = DocListCast(d.data);
if (newdocs.length > 0) {
- let displaycheck: boolean | undefined = undefined;
+ let displaycheck = false;
let newarray: Doc[] = [];
while (newdocs.length > 0) {
newarray = [];
newdocs.forEach((t) => {
- if (d.data !== undefined) {
- const newdocs = DocListCast(t.data);
- newdocs.forEach((newdoc) => {
- newarray.push(newdoc);
- });
- }
- if (searchDocs.includes(t)) {
- displaycheck = true;
- }
+ DocListCast(t.data).forEach((newdoc) => newarray.push(newdoc));
+ displaycheck = displaycheck || searchDocs.includes(t);
});
newdocs = newarray;
}
- if (displaycheck === true) {
- docsforFilter.push(d);
- }
+ displaycheck && docsforFilter.push(d);
}
}
- if (searchDocs.includes(d)) {
- docsforFilter.push(d);
- }
+ searchDocs.includes(d) && docsforFilter.push(d);
});
return docsforFilter;
}
diff --git a/src/client/views/search/SearchBox.tsx b/src/client/views/search/SearchBox.tsx
index e779435e5..1b5f5c861 100644
--- a/src/client/views/search/SearchBox.tsx
+++ b/src/client/views/search/SearchBox.tsx
@@ -24,18 +24,7 @@ import { DocumentView } from '../nodes/DocumentView';
import { FieldView, FieldViewProps } from '../nodes/FieldView';
import "./SearchBox.scss";
-export const searchSchema = createSchema({
- id: "string",
- Document: Doc,
- searchQuery: "string",
-});
-
-export enum Keys {
- TITLE = "title",
- AUTHOR = "author",
- DATA = "data",
- TEXT = "text"
-}
+export const searchSchema = createSchema({ Document: Doc });
type SearchBoxDocument = makeInterface<[typeof documentSchema, typeof searchSchema]>;
const SearchBoxDocument = makeInterface(documentSchema, searchSchema);
@@ -55,6 +44,7 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
private _maxSearchIndex: number = 0;
private _curRequest?: Promise<any> = undefined;
private _disposers: { [name: string]: IReactionDisposer } = {};
+ private _blockedTypes = [DocumentType.PRESELEMENT, DocumentType.KVP, DocumentType.DOCHOLDER, DocumentType.SEARCH, DocumentType.SEARCHITEM, DocumentType.FONTICON, DocumentType.BUTTON, DocumentType.SCRIPTING];
private currentSelectedCollection: DocumentView | undefined = undefined;
private docsforfilter: Doc[] = [];
@@ -105,10 +95,7 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
if (this.currentSelectedCollection) {
this.doLoop(this.currentSelectedCollection, undefined);
}
- this._results.forEach(result => {
- Doc.UnBrushDoc(result[0]);
- result[0].searchMatch = undefined;
- });
+ this.closeSearch(false);
if (this.currentSelectedCollection !== undefined) {
this.currentSelectedCollection.props.Document._searchDocs = new List<Doc>([]);
@@ -196,23 +183,18 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
}
}
}
-
}
return query.replace(/-\s+/g, '');
}
-
@action
filterDocsByType(docs: Doc[]) {
const finalDocs: Doc[] = [];
- const blockedTypes: string[] = [DocumentType.PRESELEMENT, DocumentType.DOCHOLDER, DocumentType.SEARCH, DocumentType.SEARCHITEM, DocumentType.FONTICON, DocumentType.BUTTON, DocumentType.SCRIPTING];
docs.forEach(doc => {
- const layoutresult = Cast(doc.type, "string");
- if (layoutresult && !blockedTypes.includes(layoutresult)) {
- if (layoutresult && this._icons.includes(layoutresult)) {
- finalDocs.push(doc);
- }
+ const layoutresult = StrCast(doc.type, "string") as DocumentType;
+ if (layoutresult && !this._blockedTypes.includes(layoutresult) && this._icons.includes(layoutresult)) {
+ finalDocs.push(doc);
}
});
return finalDocs;
@@ -244,7 +226,7 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
searchCollection(query: string) {
- const selectedCollection: DocumentView = SelectionManager.SelectedDocuments()[0];
+ const selectedCollection = SelectionManager.SelectedDocuments()[0];
query = query.toLowerCase();
if (selectedCollection !== undefined) {
@@ -296,25 +278,10 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
// then by the time the options button is clicked, all of the fields should be in place. If a new field is added while this menu
// is displayed (unlikely) it won't show up until something else changes.
//TODO Types
- Doc.GetAllPrototypes(doc).map
- (proto => Object.keys(proto).forEach(key => keys[key] = false));
+ Doc.GetAllPrototypes(doc).map(proto => Object.keys(proto).forEach(key => keys[key] = false));
return Array.from(Object.keys(keys));
}
-
- basicFieldFilters(query: string, type: string): string {
- let mod = "";
- switch (type) {
- case Keys.AUTHOR: mod = " author_t:"; break;
- case Keys.TITLE: mod = " title_t:"; break;
- case Keys.TEXT: mod = " text_t:"; break;
- }
-
- const newWords: string[] = [];
- query.split(" ").forEach(word => newWords.push(mod + word));
- return newWords.join(" ");
- }
-
@action
submitSearch = async (reset?: boolean) => {
if (this.currentSelectedCollection !== undefined) {
@@ -332,10 +299,7 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
let query = StrCast(this.layoutDoc._searchString);
Doc.SetSearchQuery(query);
this._searchFullDB ? query = this.getFinalQuery(query) : console.log("local");
- this._results.forEach(result => {
- Doc.UnBrushDoc(result[0]);
- result[0].searchMatch = undefined;
- });
+ this.closeSearch(false);
this._results = [];
this._resultsSet.clear();
this._visibleElements = [];
@@ -358,11 +322,10 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
}
private get filterQuery() {
- const types = ["preselement", "docholder", "search", "searchitem", "fonticonbox"]; // this.filterTypes;
const baseExpr = "NOT system_b:true";
const authorExpr = this._searchFullDB === "My Stuff" ? ` author_t:${Doc.CurrentUserEmail}` : undefined;
const includeDeleted = this._deletedDocsStatus ? "" : " NOT deleted_b:true";
- const typeExpr = this._onlyAliases ? "NOT {!join from=id to=proto_i}type_t:*" : `(type_t:* OR {!join from=id to=proto_i}type_t:*) ${types.map(type => `NOT ({!join from=id to=proto_i}type_t:${type}) AND NOT type_t:${type}`).join(" AND ")}`;
+ const typeExpr = this._onlyAliases ? "NOT {!join from=id to=proto_i}type_t:*" : `(type_t:* OR {!join from=id to=proto_i}type_t:*) ${this._blockedTypes.map(type => `NOT ({!join from=id to=proto_i}type_t:${type}) AND NOT type_t:${type}`).join(" AND ")}`;
// fq: type_t:collection OR {!join from=id to=proto_i}type_t:collection q:text_t:hello
const query = [baseExpr, authorExpr, includeDeleted, typeExpr].filter(q => q).join(" AND ").replace(/AND $/, "");
return query;
@@ -380,6 +343,7 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
const headers = Cast(this.props.Document._schemaHeaders, listSpec(SchemaHeaderField), []);
return headers.reduce((p: Opt<string>, header: SchemaHeaderField) => p || (header.desc !== undefined && suffixMap(header.type) ? (header.heading + suffixMap(header.type) + (header.desc ? " desc" : " asc")) : undefined), undefined);
}
+
getResults = async (query: string) => {
this._lockPromise && (await this._lockPromise);
this._lockPromise = new Promise(async res => {
@@ -467,12 +431,12 @@ export class SearchBox extends ViewBoxBaseComponent<FieldViewProps, SearchBoxDoc
}
@action.bound
- closeSearch = () => {
+ closeSearch = (closesearchbar = true) => {
this._results.forEach(result => {
Doc.UnBrushDoc(result[0]);
result[0].searchMatch = undefined;
});
- this._searchbarOpen = false;
+ closesearchbar && (this._searchbarOpen = false);
}
@action.bound