From ac5242eae298bddba2aaf65129dcf86b2e80605c 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 f683930508..85435f62b7 100644 --- a/Open-ILS/src/eg2/package.json +++ b/Open-ILS/src/eg2/package.json @@ -37,6 +37,7 @@ "moment": "^2.29.1", "moment-timezone": "^0.5.33", "ngx-cookie": "^5.0.2", + "elastic-builder": "^2.4.0", "rxjs": "^6.6.2", "zone.js": "^0.11.4", "ts-md5": "^1.2.9" 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 ea9a272567..683947e441 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 { @@ -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); 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 aca538041d..fea381551c 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 @@ -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 { + 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( 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 e8c1534acc..60338d7d85 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 = [ @@ -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; - } } -- 2.11.0