From: Bill Erickson Date: Wed, 18 Sep 2019 16:01:25 +0000 (-0400) Subject: exact/prefix leverage new field class indexes X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=b62e8ba19b44d2b65ae18a28f86d74f17a817c49;p=working%2FEvergreen.git exact/prefix leverage new field class indexes No need to fetch the bib fields anymore, since we can use the new meta indexes for term searches. Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/eg2/src/app/share/catalog/catalog.service.ts b/Open-ILS/src/eg2/src/app/share/catalog/catalog.service.ts index 6393836e7e..a5f9773f27 100644 --- a/Open-ILS/src/eg2/src/app/share/catalog/catalog.service.ts +++ b/Open-ILS/src/eg2/src/app/share/catalog/catalog.service.ts @@ -352,22 +352,20 @@ export class CatalogService { return facetData; } - fetchCcvms(): Promise { + fetchCcvms(): Promise { - // XXX Putting the elastic initialization call here since - // the call is assumed to be run at page load time. - // TODO: migrate our fetch calls to generic init call. - - return this.elastic.init().then(ok => { - - if (Object.keys(this.ccvmMap).length) { - return Promise.resolve(); - } + if (Object.keys(this.ccvmMap).length) { + return Promise.resolve(); + } - return this.pcrud.search('ccvm', + return new Promise((resolve, reject) => { + this.pcrud.search('ccvm', {ctype : CATALOG_CCVM_FILTERS}, {}, {atomic: true, anonymous: true} - ).toPromise().then(list => this.compileCcvms(list)); + ).subscribe(list => { + this.compileCcvms(list); + resolve(); + }); }); } diff --git a/Open-ILS/src/eg2/src/app/share/catalog/elastic.service.ts b/Open-ILS/src/eg2/src/app/share/catalog/elastic.service.ts index 2f1852154a..ae81d976de 100644 --- a/Open-ILS/src/eg2/src/app/share/catalog/elastic.service.ts +++ b/Open-ILS/src/eg2/src/app/share/catalog/elastic.service.ts @@ -12,8 +12,6 @@ import {RequestBodySearch, MatchQuery, MultiMatchQuery, TermsQuery, Query, Sort, @Injectable() export class ElasticService { - bibFields: IdlObject[] = []; - constructor( private idl: IdlService, private net: NetService, @@ -21,17 +19,6 @@ export class ElasticService { private pcrud: PcrudService ) {} - init(): Promise { - - if (this.bibFields.length > 0) { - return Promise.resolve(); - } - - return this.pcrud.search('ebf', {search_field: 't'}) - .pipe(tap(field => this.bibFields.push(field))) - .toPromise(); - } - // Returns true if Elastic can provide search results. canSearch(ctx: CatalogSearchContext): boolean { @@ -40,8 +27,8 @@ export class ElasticService { if ( ctx.termSearch.isSearchable() && !ctx.termSearch.groupByMetarecord && !ctx.termSearch.fromMetarecord && - !ctx.termSearch.hasBrowseEntry) { - return true; + !ctx.termSearch.hasBrowseEntry) { + return true; } if (ctx.identSearch.isSearchable() @@ -113,7 +100,7 @@ export class ElasticService { search.sort(new Sort(parts[0], parts[1] ? 'desc' : 'asc')); } else { - + // Sort by match score by default. search.sort(new Sort('_score', 'desc')); } @@ -279,36 +266,19 @@ export class ElasticService { query.type('most_fields'); boolNode.mustNot(query); return; - } - // Under the covers, searches on a field class are OR searches - // across all fields within the class. Unlike MultiMatch - // searches (above) where this can be accomplished with field - // name wildcards, term/prefix searches require explicit field - // names. - const shoulds: Query[] = []; - - this.getSearchFieldsForClass(fieldClass).forEach(field => { - const fieldName = `${fieldClass}|${field.name()}`; - if (matchOp === 'exact') { - query = new TermQuery(fieldName, value); - } else if (matchOp === 'starts') { - query = new PrefixQuery(fieldName, value); - } - - shoulds.push(query); - }); - - // Wrap the 'shoulds' in a 'must' so that at least one of - // the shoulds must match for the group to match. - boolNode.must(new BoolQuery().should(shoulds)); - } + // "exact" and "starts" searches use term searches instead + // of full-text searches. + case 'exact': + query = new TermQuery(fieldClass, value); + boolNode.must(query); + return; - getSearchFieldsForClass(fieldClass: string): any[] { - return this.bibFields.filter(f => ( - f.search_field() === 't' && - f.search_group() === fieldClass - )); + case 'starts': + query = new PrefixQuery(fieldClass, value); + boolNode.must(query); + return; + } } }