more catalog integration experiements / elastic-builder
authorBill Erickson <berickxx@gmail.com>
Fri, 6 Sep 2019 14:37:38 +0000 (10:37 -0400)
committerBill Erickson <berickxx@gmail.com>
Wed, 27 Oct 2021 15:47:20 +0000 (11:47 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/package.json
Open-ILS/src/eg2/src/app/share/catalog/catalog-url.service.ts
Open-ILS/src/eg2/src/app/share/catalog/catalog.service.ts
Open-ILS/src/eg2/src/app/share/catalog/elastic-search-context.ts
Open-ILS/src/eg2/src/app/share/catalog/search-context.ts

index a2500f7..f051d60 100644 (file)
@@ -33,6 +33,7 @@
     "@nguniversal/express-engine": "^10.0.1",
     "bootstrap-css-only": "^4.4.1",
     "core-js": "^3.6.5",
+    "elastic-builder": "^2.4.0",
     "file-saver": "^2.0.2",
     "material-design-icons": "^3.0.1",
     "moment": "^2.27.0",
index ea9a272..683947e 100644 (file)
@@ -5,7 +5,6 @@ import {CatalogSearchContext, CatalogBrowseContext, CatalogMarcContext,
    CatalogTermContext, FacetFilter} from './search-context';
 import {CATALOG_CCVM_FILTERS} from './search-context';
 import {HashParams} from '@eg/share/util/hash-params';
-import {ElasticSearchContext} from './elastic-search-context';
 
 @Injectable()
 export class CatalogUrlService {
@@ -145,9 +144,7 @@ export class CatalogUrlService {
      * Creates a new search context from the active route params.
      */
     fromUrlParams(params: ParamMap): CatalogSearchContext {
-        //const context = new CatalogSearchContext();
-        // TODO: hard code for now
-        const context = new ElasticSearchContext();
+        const context = new CatalogSearchContext();
 
         this.applyUrlParams(context, params);
 
index aca5380..fea3815 100644 (file)
@@ -119,8 +119,6 @@ export class CatalogService {
         let method = 'open-ils.search.biblio.marc';
         if (ctx.isStaff) { method += '.staff'; }
 
-        const method = ctx.getApiName();
-
         const queryStruct = ctx.compileMarcSearchArgs();
 
         return this.net.request('open-ils.search', method, queryStruct)
@@ -136,6 +134,7 @@ export class CatalogService {
 
     termSearch(ctx: CatalogSearchContext): Promise<void> {
 
+        let method = 'open-ils.search.biblio.multiclass.query';
         let fullQuery;
 
         if (ctx.identSearch.isSearchable()) {
@@ -144,25 +143,24 @@ export class CatalogService {
         } else {
             fullQuery = ctx.compileTermSearchQuery();
 
+            if (ctx.termSearch.groupByMetarecord
+                && !ctx.termSearch.fromMetarecord) {
+                method = 'open-ils.search.metabib.multiclass.query';
+            }
+
             if (ctx.termSearch.hasBrowseEntry) {
                 this.fetchBrowseEntry(ctx);
             }
         }
 
-        console.debug('search query', JSON.stringify(fullQuery));
+        // TODO XXX TESTING
+        method = 'open-ils.search.elastic.bib_search';
+        fullQuery = ctx.compileElasticSearchQuery();
 
-        let method = ctx.getApiName();
-        if (method === null) {
-            method = 'open-ils.search.biblio.multiclass.query';
-    
-            if (ctx.termSearch.groupByMetarecord 
-            && !ctx.termSearch.fromMetarecord) {
-                method = 'open-ils.search.metabib.multiclass.query';
-            }
-    
-            if (ctx.isStaff) {
-                method += '.staff';
-            }
+        console.debug(`search query: ${fullQuery}`);
+
+        if (ctx.isStaff) {
+            method += '.staff';
         }
 
         return this.net.request(
index bf4cd6d..6c8ab24 100644 (file)
@@ -135,8 +135,10 @@ export class ElasticSearchContext extends CatalogSearchContext {
 
     newParams(): ElasticSearchParams {
         const params = new ElasticSearchParams();
+        /*
         params.limit = this.pager.limit;
         params.offset = this.pager.offset;
+        */
         params.search_org = this.searchOrg.id()
 
         if (this.sort) {
@@ -167,6 +169,7 @@ export class ElasticSearchContext extends CatalogSearchContext {
         return params;
     }
 
+    /*
     getApiName(): string {
 
         // Elastic covers only a subset of available search types.
@@ -186,5 +189,6 @@ export class ElasticSearchContext extends CatalogSearchContext {
         // Fall back to existing APIs.
         return super.getApiName();
     }
+    */
 }
 
index e8c1534..60338d7 100644 (file)
@@ -3,6 +3,8 @@ import {IdlObject} from '@eg/core/idl.service';
 import {Pager} from '@eg/share/util/pager';
 import {ArrayUtil} from '@eg/share/util/array';
 
+import {RequestBodySearch, MatchQuery} from 'elastic-builder';
+
 // CCVM's we care about in a catalog context
 // Don't fetch them all because there are a lot.
 export const CATALOG_CCVM_FILTERS = [
@@ -574,7 +576,7 @@ export class CatalogSearchContext {
         return query;
     }
 
-    compileTermSearchQuery(): any {
+    compileTermSearchQuery(): string {
         const ts = this.termSearch;
         let str = '';
 
@@ -679,6 +681,41 @@ export class CatalogSearchContext {
         return str;
     }
 
+    compileElasticSearchQuery(): any {
+        const search = new RequestBodySearch();
+        search.query(new MatchQuery('body', 'hello, ma!'));
+
+        const ts = this.termSearch;
+
+        ts.joinOp.forEach((op, idx) => {
+            let matchOp = 'match';
+
+            switch (ts.matchOp[idx]) {
+                case 'phrase':
+                    matchOp = 'match_phrase';
+                    break;
+                case 'nocontains':
+                    matchOp = 'must_not';
+                    break;
+                case 'exact':
+                    matchOp = 'term';
+                    break;
+                case 'starts':
+                    matchOp = 'match_phrase_prefix';
+                    break;
+            }
+
+            params.searches.push({
+                field: ts.fieldClass[idx],
+                match_op: matchOp,
+                value: ts.query[idx]
+            });
+
+        });
+
+        console.log(JSON.stringify(search));
+    }
+
     // A search context can collect enough data for multiple search
     // types to be searchable (e.g. users navigate through parts of a
     // search form).  Calling this method and providing a search type
@@ -737,9 +774,5 @@ export class CatalogSearchContext {
                 break;
         }
     }
-
-    getApiName(): string {
-        return null;
-    }
 }