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>
Tue, 15 Oct 2019 18:09:56 +0000 (14:09 -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 4b6b8bc..1096651 100644 (file)
@@ -27,6 +27,7 @@
     "@nguniversal/express-engine": "^7.1.0",
     "bootstrap-css-only": "^4.2.1",
     "core-js": "^2.6.9",
+    "elastic-builder": "^2.4.0",
     "file-saver": "^2.0.2",
     "material-design-icons": "^3.0.1",
     "moment": "2.24.0",
index 94a6180..4c45a4e 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 {
@@ -140,9 +139,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 1b91d82..bb8bd24 100644 (file)
@@ -95,8 +95,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)
@@ -112,6 +110,7 @@ export class CatalogService {
 
     termSearch(ctx: CatalogSearchContext): Promise<void> {
 
+        let method = 'open-ils.search.biblio.multiclass.query';
         let fullQuery;
 
         if (ctx.identSearch.isSearchable()) {
@@ -120,25 +119,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 new Promise((resolve, reject) => {
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 223c877..56d31ac 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 = [
@@ -545,7 +547,7 @@ export class CatalogSearchContext {
         return query;
     }
 
-    compileTermSearchQuery(): any {
+    compileTermSearchQuery(): string {
         const ts = this.termSearch;
         let str = '';
 
@@ -629,6 +631,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
@@ -680,9 +717,5 @@ export class CatalogSearchContext {
                 break;
         }
     }
-
-    getApiName(): string {
-        return null;
-    }
 }