From 44e5bab27d58304d7f4c1d0f7342e5f8c4cd1b37 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Fri, 6 Sep 2019 10:37:38 -0400 Subject: [PATCH] more catalog integration experiements / elastic-builder Signed-off-by: Bill Erickson --- Open-ILS/src/eg2/package.json | 1 + .../src/app/share/catalog/catalog-url.service.ts | 5 +-- .../eg2/src/app/share/catalog/catalog.service.ts | 28 +++++++------- .../app/share/catalog/elastic-search-context.ts | 4 ++ .../eg2/src/app/share/catalog/search-context.ts | 43 +++++++++++++++++++--- 5 files changed, 57 insertions(+), 24 deletions(-) diff --git a/Open-ILS/src/eg2/package.json b/Open-ILS/src/eg2/package.json index 1c49d66eb9..e1f8d5c6f9 100644 --- a/Open-ILS/src/eg2/package.json +++ b/Open-ILS/src/eg2/package.json @@ -32,6 +32,7 @@ "@nguniversal/express-engine": "^8.1.1", "bootstrap-css-only": "^4.3.1", "core-js": "^3.3.2", + "elastic-builder": "^2.4.0", "file-saver": "^2.0.2", "material-design-icons": "^3.0.1", "moment": "^2.24.0", diff --git a/Open-ILS/src/eg2/src/app/share/catalog/catalog-url.service.ts b/Open-ILS/src/eg2/src/app/share/catalog/catalog-url.service.ts index 7c03489725..7b9698f2d3 100644 --- a/Open-ILS/src/eg2/src/app/share/catalog/catalog-url.service.ts +++ b/Open-ILS/src/eg2/src/app/share/catalog/catalog-url.service.ts @@ -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 { @@ -141,9 +140,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); 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 8cfbd91e62..f741fec3c2 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 @@ -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 { + 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 this.net.request( diff --git a/Open-ILS/src/eg2/src/app/share/catalog/elastic-search-context.ts b/Open-ILS/src/eg2/src/app/share/catalog/elastic-search-context.ts index bf4cd6d3ee..6c8ab247a8 100644 --- a/Open-ILS/src/eg2/src/app/share/catalog/elastic-search-context.ts +++ b/Open-ILS/src/eg2/src/app/share/catalog/elastic-search-context.ts @@ -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(); } + */ } diff --git a/Open-ILS/src/eg2/src/app/share/catalog/search-context.ts b/Open-ILS/src/eg2/src/app/share/catalog/search-context.ts index dfe461722a..a733d7643c 100644 --- a/Open-ILS/src/eg2/src/app/share/catalog/search-context.ts +++ b/Open-ILS/src/eg2/src/app/share/catalog/search-context.ts @@ -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 = [ @@ -558,7 +560,7 @@ export class CatalogSearchContext { return query; } - compileTermSearchQuery(): any { + compileTermSearchQuery(): string { const ts = this.termSearch; let str = ''; @@ -642,6 +644,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 @@ -693,9 +730,5 @@ export class CatalogSearchContext { break; } } - - getApiName(): string { - return null; - } } -- 2.11.0