exact/prefix leverage new field class indexes
authorBill Erickson <berickxx@gmail.com>
Wed, 18 Sep 2019 16:01:25 +0000 (12:01 -0400)
committerBill Erickson <berickxx@gmail.com>
Fri, 17 Jan 2020 19:36:02 +0000 (14:36 -0500)
No need to fetch the bib fields anymore, since we can use the new meta
indexes for term searches.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/share/catalog/catalog.service.ts
Open-ILS/src/eg2/src/app/share/catalog/elastic.service.ts

index d9f297f..5a7ca99 100644 (file)
@@ -293,22 +293,20 @@ export class CatalogService {
         return facetData;
     }
 
-    fetchCcvms(): Promise<any> {
+    fetchCcvms(): Promise<void> {
 
-        // 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();
+            });
         });
     }
 
index 2f18521..ae81d97 100644 (file)
@@ -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<any> {
-
-        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;
+        }
     }
 }