From 4de037f13a60019ccb6068a94792114dba6a6c86 Mon Sep 17 00:00:00 2001 From: jvega190 Date: Fri, 8 Oct 2021 15:57:30 -0600 Subject: [PATCH 01/10] Upgrade to rxjs@^7.0.0 - Initial work - 5025 --- packages/content/package.json | 2 +- packages/content/src/NavigationService.ts | 25 +++++++++++------------ packages/redux/package.json | 2 +- packages/redux/src/epics/content.ts | 11 +++++----- packages/search/package.json | 2 +- yarn.lock | 18 ++++++++-------- 6 files changed, 30 insertions(+), 30 deletions(-) diff --git a/packages/content/package.json b/packages/content/package.json index c1bb447..02e5b48 100644 --- a/packages/content/package.json +++ b/packages/content/package.json @@ -29,7 +29,7 @@ "@craftercms/classes": "0.0.0-PLACEHOLDER", "@craftercms/models": "0.0.0-PLACEHOLDER", "@craftercms/utils": "0.0.0-PLACEHOLDER", - "rxjs": "^6.5.4" + "rxjs": "^7.0.0" }, "devDependencies": { "@rollup/plugin-commonjs": "^11.0.2", diff --git a/packages/content/src/NavigationService.ts b/packages/content/src/NavigationService.ts index e88ecc7..a1d4801 100644 --- a/packages/content/src/NavigationService.ts +++ b/packages/content/src/NavigationService.ts @@ -17,12 +17,11 @@ import { Observable } from 'rxjs'; import { crafterConf, SDKService } from '@craftercms/classes'; -import { CrafterConfig } from '@craftercms/models'; +import { CrafterConfig, NavigationItem } from '@craftercms/models'; import { composeUrl } from '@craftercms/utils'; -// TODO: Add correct return types -type ToDoGetNavTreeReturnType = Observable; -type ToDoGetNavBreadcrumbReturnType = Observable; +type NavTreeReturnType = Observable; +type NavBreadcrumbReturnType = Observable; /** * Returns the navigation tree with the specified depth for the specified store URL. @@ -30,11 +29,11 @@ type ToDoGetNavBreadcrumbReturnType = Observable; * @param {int} depth - the depth of the tree * @param {string} currentPageUrl - the URL of the current page */ -export function getNavTree(path: string): ToDoGetNavTreeReturnType; -export function getNavTree(path: string, depth: number): ToDoGetNavTreeReturnType; -export function getNavTree(path: string, depth: number, currentPageUrl: string): ToDoGetNavTreeReturnType; -export function getNavTree(path: string, depth: number, currentPageUrl: string, config: CrafterConfig): ToDoGetNavTreeReturnType; -export function getNavTree(path: string, depth: number = 1, currentPageUrl: string = '', config?: CrafterConfig): ToDoGetNavTreeReturnType { +export function getNavTree(path: string): NavTreeReturnType; +export function getNavTree(path: string, depth: number): NavTreeReturnType; +export function getNavTree(path: string, depth: number, currentPageUrl: string): NavTreeReturnType; +export function getNavTree(path: string, depth: number, currentPageUrl: string, config: CrafterConfig): NavTreeReturnType; +export function getNavTree(path: string, depth: number = 1, currentPageUrl: string = '', config?: CrafterConfig): NavTreeReturnType { config = crafterConf.mix(config); const requestURL = composeUrl(config, config.endpoints.GET_NAV_TREE); return SDKService.httpGet(requestURL, { @@ -50,10 +49,10 @@ export function getNavTree(path: string, depth: number = 1, currentPageUrl: stri * @param {string} path - the current URL used to build the breadcrumb * @param {string} root - the root URL, basically the starting point of the breadcrumb */ -export function getNavBreadcrumb(path: string): ToDoGetNavBreadcrumbReturnType; -export function getNavBreadcrumb(path: string, root: string): ToDoGetNavBreadcrumbReturnType; -export function getNavBreadcrumb(path: string, root: string, config: CrafterConfig): ToDoGetNavBreadcrumbReturnType; -export function getNavBreadcrumb(path: string, root: string = '', config?: CrafterConfig): ToDoGetNavBreadcrumbReturnType { +export function getNavBreadcrumb(path: string): NavBreadcrumbReturnType; +export function getNavBreadcrumb(path: string, root: string): NavBreadcrumbReturnType; +export function getNavBreadcrumb(path: string, root: string, config: CrafterConfig): NavBreadcrumbReturnType; +export function getNavBreadcrumb(path: string, root: string = '', config?: CrafterConfig): NavBreadcrumbReturnType { config = crafterConf.mix(config); const requestURL = composeUrl(config, config.endpoints.GET_BREADCRUMB); return SDKService.httpGet(requestURL, { diff --git a/packages/redux/package.json b/packages/redux/package.json index 6fa00dc..5b35dc1 100644 --- a/packages/redux/package.json +++ b/packages/redux/package.json @@ -29,7 +29,7 @@ "@craftercms/content": "0.0.0-PLACEHOLDER", "redux": "^4.0.5", "redux-observable": "^1.2.0", - "rxjs": "^6.5.4" + "rxjs": "^7.0.0" }, "devDependencies": { "@rollup/plugin-commonjs": "^11.0.2", diff --git a/packages/redux/src/epics/content.ts b/packages/redux/src/epics/content.ts index 99e0c16..9f1d007 100644 --- a/packages/redux/src/epics/content.ts +++ b/packages/redux/src/epics/content.ts @@ -34,6 +34,7 @@ import { GET_NAV_BREADCRUMB, getNavBreadcrumbComplete } from '../actions/content'; +import { Item, NavigationItem } from "@craftercms/models"; export const getItemEpic = (action$: Observable) => action$.pipe( @@ -41,7 +42,7 @@ export const getItemEpic = mergeMap(({ payload }) => ContentStoreService.getItem(payload) .pipe( - map(item => getItemComplete({ + map((item: Item) => getItemComplete({ item, url: payload })), @@ -74,7 +75,7 @@ export const getChildrenEpic = mergeMap(({ payload }) => ContentStoreService.getChildren(payload) .pipe( - map(children => getChildrenComplete({ + map((children: Item[]) => getChildrenComplete({ children, url: payload })), @@ -90,7 +91,7 @@ export const getTreeEpic = mergeMap(({ payload }) => ContentStoreService.getTree(payload.url, payload.depth) .pipe( - map(tree => getTreeComplete({ + map((tree: Item) => getTreeComplete({ tree, url: payload.url })), @@ -106,7 +107,7 @@ export const getNavEpic = mergeMap(({ payload }) => NavigationService.getNavTree(payload.url, payload.depth, payload.currentPageUrl) .pipe( - map(nav => getNavComplete({ + map((nav: NavigationItem) => getNavComplete({ nav, url: payload.url })), @@ -122,7 +123,7 @@ export const getNavBreadcrumbEpic = mergeMap(({ payload }) => NavigationService.getNavBreadcrumb(payload.url, payload.root) .pipe( - map(breadcrumb => getNavBreadcrumbComplete({ + map((breadcrumb: NavigationItem[]) => getNavBreadcrumbComplete({ breadcrumb, url: payload.url })), diff --git a/packages/search/package.json b/packages/search/package.json index 991a7bb..443f9b8 100644 --- a/packages/search/package.json +++ b/packages/search/package.json @@ -29,7 +29,7 @@ "@craftercms/classes": "0.0.0-PLACEHOLDER", "@craftercms/models": "0.0.0-PLACEHOLDER", "@craftercms/utils": "0.0.0-PLACEHOLDER", - "rxjs": "^6.5.4", + "rxjs": "^7.0.0", "url-search-params-polyfill": "^5.0.0", "uuid": "^3.4.0" }, diff --git a/yarn.lock b/yarn.lock index 7c4573c..1a80779 100644 --- a/yarn.lock +++ b/yarn.lock @@ -842,12 +842,12 @@ rollup@^1.31.1: "@types/node" "*" acorn "^7.1.0" -rxjs@^6.5.4: - version "6.5.4" - resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-6.5.4.tgz#e0777fe0d184cec7872df147f303572d414e211c" - integrity sha512-naMQXcgEo3csAEGvw/NydRA0fuS2nDZJiw1YUWFKU7aPPAPGZEsD4Iimit96qwCieH6y614MCLYwdkrWx7z/7Q== +rxjs@^7.0.0: + version "7.4.0" + resolved "https://registry.yarnpkg.com/rxjs/-/rxjs-7.4.0.tgz#a12a44d7eebf016f5ff2441b87f28c9a51cebc68" + integrity sha512-7SQDi7xeTMCJpqViXh8gL/lebcwlp3d831F05+9B44A4B0WfsEwUQHR64gsH1kvJ+Ep/J9K2+n1hVl1CsGN23w== dependencies: - tslib "^1.9.0" + tslib "~2.1.0" semver@^5.7.0: version "5.7.1" @@ -977,10 +977,10 @@ to-regex-range@^5.0.1: dependencies: is-number "^7.0.0" -tslib@^1.9.0: - version "1.10.0" - resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a" - integrity sha512-qOebF53frne81cf0S9B41ByenJ3/IuH8yJKngAX35CmiZySA0khhkovshKK+jGCaMnVomla7gVlIcc3EvKPbTQ== +tslib@~2.1.0: + version "2.1.0" + resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.1.0.tgz#da60860f1c2ecaa5703ab7d39bc05b6bf988b97a" + integrity sha512-hcVC3wYEziELGGmEEXue7D75zbwIIVUMWAVbHItGPx0ziyXxrOMQx4rQEVEV45Ut/1IotuEvwqPopzIOkDMf0A== typescript@^4.1.2: version "4.1.2" From 0615cd92cd1994357d2e7e4162d76571286aeb4e Mon Sep 17 00:00:00 2001 From: jvega190 Date: Fri, 8 Oct 2021 16:12:39 -0600 Subject: [PATCH 02/10] Update PartialObserver import - 5025 --- packages/utils/src/types.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/utils/src/types.ts b/packages/utils/src/types.ts index a852f26..089b6c1 100644 --- a/packages/utils/src/types.ts +++ b/packages/utils/src/types.ts @@ -14,7 +14,7 @@ * along with this program. If not, see http://www.gnu.org/licenses/. */ -import { PartialObserver } from 'rxjs/index'; +import { PartialObserver } from 'rxjs'; export declare type ObserverOrNext = (value: T) => void | PartialObserver; From b6203c06e9262c4557fdd16ca73752637ce2e689 Mon Sep 17 00:00:00 2001 From: jvega190 Date: Mon, 11 Oct 2021 14:52:00 -0600 Subject: [PATCH 03/10] Upgrade to rxjs@^7.0.0 - 5025 --- packages/classes/src/SDKService.ts | 4 ++-- packages/redux/src/epics/search.ts | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/classes/src/SDKService.ts b/packages/classes/src/SDKService.ts index 0b00106..48108b7 100644 --- a/packages/classes/src/SDKService.ts +++ b/packages/classes/src/SDKService.ts @@ -23,13 +23,13 @@ import { LookupTable } from '@craftercms/models'; export function httpGet(requestURL: string, params: Object = {}, headers?: LookupTable): Observable { const searchParams = new URLSearchParams(params as URLSearchParams); return ajax.get(`${requestURL}?${searchParams.toString()}`, headers).pipe( - pluck('response') + pluck('response') ); } export function httpPost(requestURL: string, body: Object = {}, headers?: LookupTable): Observable { return ajax.post(requestURL, body, { 'Content-Type': 'application/json', ...headers }).pipe( - pluck('response') + pluck('response') ); } diff --git a/packages/redux/src/epics/search.ts b/packages/redux/src/epics/search.ts index 4da59c6..36fd622 100644 --- a/packages/redux/src/epics/search.ts +++ b/packages/redux/src/epics/search.ts @@ -32,7 +32,8 @@ export const searchEpic = mergeMap(({ payload }) => SearchService.search(payload, crafterConf.getConfig()) .pipe( - map(response => searchComplete({ + // TODO: Add search return type, and remove SOLR + map((response: any) => searchComplete({ response: response.response ? response.response : response, queryId: payload.uuid })), From 7bcee051f393141daa87b305b4994f8291b854d3 Mon Sep 17 00:00:00 2001 From: jvega190 Date: Tue, 12 Oct 2021 11:21:03 -0600 Subject: [PATCH 04/10] Upgrade to rxjs@^7.0.0, remove SOLR - 5025 --- packages/classes/src/config.ts | 1 - packages/models/src/CrafterConfig.ts | 1 - packages/redux/src/epics/search.ts | 6 +- packages/search/README.md | 23 ----- packages/search/search.ts | 1 - packages/search/src/SearchService.ts | 63 ++----------- packages/search/src/solr-query.ts | 132 --------------------------- packages/utils/src/types.ts | 2 +- 8 files changed, 14 insertions(+), 215 deletions(-) delete mode 100644 packages/search/src/solr-query.ts diff --git a/packages/classes/src/config.ts b/packages/classes/src/config.ts index 5fd18c3..c8fb238 100644 --- a/packages/classes/src/config.ts +++ b/packages/classes/src/config.ts @@ -30,7 +30,6 @@ const DEFAULTS: CrafterConfig = { GET_NAV_TREE: '/api/1/site/navigation/tree.json', GET_BREADCRUMB: '/api/1/site/navigation/breadcrumb.json', TRANSFORM_URL: '/api/1/site/url/transform.json', - SEARCH: 'crafter-search/api/2/search/search.json', ELASTICSEARCH: 'api/1/site/elasticsearch/search' }, contentTypeRegistry: {}, diff --git a/packages/models/src/CrafterConfig.ts b/packages/models/src/CrafterConfig.ts index 5dfaeef..99bdb97 100644 --- a/packages/models/src/CrafterConfig.ts +++ b/packages/models/src/CrafterConfig.ts @@ -33,7 +33,6 @@ export interface Endpoints { GET_NAV_TREE: string; GET_BREADCRUMB: string; TRANSFORM_URL: string; - SEARCH: string; ELASTICSEARCH: string; } diff --git a/packages/redux/src/epics/search.ts b/packages/redux/src/epics/search.ts index 36fd622..c5556c9 100644 --- a/packages/redux/src/epics/search.ts +++ b/packages/redux/src/epics/search.ts @@ -25,6 +25,7 @@ import { SEARCH, searchComplete } from '../actions/search'; +import {SearchResult} from "@craftercms/models/src/search"; export const searchEpic = (action$: Observable) => action$.pipe( @@ -32,9 +33,8 @@ export const searchEpic = mergeMap(({ payload }) => SearchService.search(payload, crafterConf.getConfig()) .pipe( - // TODO: Add search return type, and remove SOLR - map((response: any) => searchComplete({ - response: response.response ? response.response : response, + map((response: SearchResult) => searchComplete({ + response, queryId: payload.uuid })), catchError(() => of(searchComplete({ diff --git a/packages/search/README.md b/packages/search/README.md index a8381e8..5cd1689 100644 --- a/packages/search/README.md +++ b/packages/search/README.md @@ -129,29 +129,6 @@ Map model }); ``` -- Connect to Crafter Search to query for content with SOLR (crafter version: 3.0.x): - -```typescript - import { crafterConf } from '@craftercms/classes'; - import { search, createQuery } from '@craftercms/search'; - - //First, set the Crafter configuration to _cache_ your config. - //All subsequent calls to `getConfig` will use that configuration. - crafterConf.configure({ - baseUrl: 'http://localhost:8080', - site: 'editorial', - searchId: 'editorial' // if searchId is the same as site, this parameters is not needed - }) - - const query = createQuery('solr'); - query.query = "*:*"; - query.filterQueries = ['content-type:"/component/video"']; - - search(query).subscribe((results) => { - // ... - }); -``` - You may alternatively use a different config by supplying the config object at the service call invoking time ```typescript diff --git a/packages/search/search.ts b/packages/search/search.ts index 88f7fe2..c098e80 100644 --- a/packages/search/search.ts +++ b/packages/search/search.ts @@ -15,6 +15,5 @@ */ export * from './src/query'; -export * from './src/solr-query'; export * from './src/elastic-query'; export * from './src/SearchService'; diff --git a/packages/search/src/SearchService.ts b/packages/search/src/SearchService.ts index dd8f962..c10fb0b 100644 --- a/packages/search/src/SearchService.ts +++ b/packages/search/src/SearchService.ts @@ -20,28 +20,24 @@ import { composeUrl, SearchEngines } from '@craftercms/utils'; import { crafterConf, SDKService } from '@craftercms/classes'; import { CrafterConfig } from '@craftercms/models'; import { Query } from './query'; -import { SolrQuery } from '@craftercms/search'; import { ElasticQuery } from '@craftercms/search'; import uuid from 'uuid'; import 'url-search-params-polyfill'; - -// TODO: Add correct return types -type TodoSearchReturnType = Observable; +import { SearchResult } from "@craftercms/models/src/search"; /** * Does a full-text search and returns a Map model. * @param {Query} query - the query object */ -export function search(query: Query, config?: CrafterConfig): TodoSearchReturnType; -export function search(params: Object, config?: CrafterConfig): TodoSearchReturnType; -export function search(queryOrParams: Query | Object, config?: CrafterConfig): TodoSearchReturnType { +export function search(query: Query, config?: CrafterConfig): Observable; +export function search(params: Object, config?: CrafterConfig): Observable; +export function search(queryOrParams: Query | Object, config?: CrafterConfig): Observable { config = crafterConf.mix(config); let requestURL; const params = (queryOrParams instanceof Query) ? queryOrParams.params - : queryOrParams, - searchParams = new URLSearchParams(); + : queryOrParams; if (queryOrParams instanceof ElasticQuery) { requestURL = composeUrl(config, config.endpoints.ELASTICSEARCH) + '?crafterSite=' + config.site; @@ -50,68 +46,29 @@ export function search(queryOrParams: Query | Object, config?: CrafterConfig): T .pipe(map((response: any) => { return response.hits; })); - } else { - requestURL = composeUrl(config, config.endpoints.SEARCH); - - for (let param in params) { - if (params.hasOwnProperty(param)) { - if (Array.isArray(params[param])) { - for (let x = 0; x < params[param].length; x++) { - searchParams.append(param, params[param][x]); - } - } else { - searchParams.append(param, params[param]); - } - } - } - - searchParams.append('index_id', config.searchId ? config.searchId : config.site); - - return SDKService.httpGet(requestURL, searchParams, config.headers); } - } /** * Returns a new Query object */ -export function createQuery(): SolrQuery; -export function createQuery(searchEngine: SearchEngines): T; -export function createQuery(searchEngine: SearchEngines, params: Object): T; -export function createQuery(searchEngineOrParams: SearchEngines | Object = 'solr', params: Object = {}): T { + +export function createQuery(params: Object): T { let query, queryId = (params && params['uuid']) ? params['uuid'] - : uuid(), - engine = (typeof searchEngineOrParams === 'string') - ? (searchEngineOrParams).toLowerCase() - : 'solr'; - - if (typeof searchEngineOrParams !== 'string') { - params = searchEngineOrParams; - } - - switch (engine) { - case 'elastic': - case 'elasticsearch': - query = new ElasticQuery(); - break; - case 'solr': - default: - query = new SolrQuery(); - break; - } + : uuid(); + query = new ElasticQuery(); Object.assign(query.params, params); - query.uuid = queryId; return query; } /** - * Implementation of Search Service for Solr + * Implementation of Search Service for ElasticSearch */ export const SearchService = { search, diff --git a/packages/search/src/solr-query.ts b/packages/search/src/solr-query.ts deleted file mode 100644 index 5eadb12..0000000 --- a/packages/search/src/solr-query.ts +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (C) 2007-2021 Crafter Software Corporation. All Rights Reserved. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License version 3 - * as published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program. If not, see http://www.gnu.org/licenses/. - */ - -import { Query } from './query'; - -/** - * Query implementation for Solr - */ -export class SolrQuery extends Query { - - // Synonym of start, added for consistency with Java Search Client - /** - * Sets the offset of the results. - * @param {int} offset - Number of results to skip - */ - set offset(offset) { - this.start = offset; - } - - // Synonym of rows, added for consistency with Java Search Client - /** - * Sets the number of results to return. - * @param {int} numResults - Number of results to return - */ - set numResults(numResults) { - this.rows = numResults; - } - - /** - * Sets the offset of the results. - * @param {int} start - Number of results to skip - */ - set start(start) { - super.setParam('start', start); - } - - /** - * Sets the number of results to return. - * @param {int} rows - Number of results to return - */ - set rows(rows) { - super.setParam('rows', rows); - } - - /** - * Sets the actual query. - * @param {string} query - Solr query string - */ - set query(query) { - super.setParam('q', query); - } - - /** - * Sets the sort order. - * @param {string} sort - Sort order - */ - set sort(sort) { - super.setParam('sort', sort); - } - - /** - * Sets the fields that should be returned. - * @param {Array} fields - List of field names - */ - set fieldsToReturn(fields) { - super.setParam('fl', fields); - } - - /** - * Enables or disables highlighting in the results - * @param {string} highlight - Indicates if highlighting should be used - */ - set highlight(highlight) { - super.setParam('hl', highlight); - } - - /** - * Sets the field to apply highlighting in the results - * @param {string} fields - List of field names to use for highlighting - */ - set highlightFields(fields) { - this.highlight = true; - - super.setParam('hl.fl', fields); - } - - /** - * Sets the number of snippets to generate per field in highlighting - * @param {int} snippets - Number of snippets - */ - set highlightSnippets(snippets) { - super.setParam('hl.snippets', snippets); - } - - /** - * Sets the size of snippets to generate per field in highlighting - * @param {int} size - Size of snippets - */ - set highlightSnippetSize(size) { - super.setParam('hl.fragsize', size); - } - - /** - * Sets the filter queries used to reduce the search results - * @param {Array} queries - List of filter queries - */ - set filterQueries(queries) { - super.addParam('fq', queries); - } - - /** - * Sets if the additional Crafter Search filters should be disabled on query execution. - * @param {bool} disableAdditionalFilters - Indicates if additional filters should be used - */ - set disableAdditionalFilters(disableAdditionalFilters) { - super.setParam('disable_additional_filters', disableAdditionalFilters) - } - -} diff --git a/packages/utils/src/types.ts b/packages/utils/src/types.ts index 089b6c1..eb3f22d 100644 --- a/packages/utils/src/types.ts +++ b/packages/utils/src/types.ts @@ -18,4 +18,4 @@ import { PartialObserver } from 'rxjs'; export declare type ObserverOrNext = (value: T) => void | PartialObserver; -export declare type SearchEngines = 'solr' | 'elasticsearch'; +export declare type SearchEngines = 'elasticsearch'; From 38e7f94d214c70b7cc987dc1607cdcf4aac92d06 Mon Sep 17 00:00:00 2001 From: jvega190 Date: Tue, 12 Oct 2021 11:29:03 -0600 Subject: [PATCH 05/10] Add search model - 5025 --- packages/models/src/search.ts | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 packages/models/src/search.ts diff --git a/packages/models/src/search.ts b/packages/models/src/search.ts new file mode 100644 index 0000000..33ecbff --- /dev/null +++ b/packages/models/src/search.ts @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2007-2021 Crafter Software Corporation. All Rights Reserved. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + */ + +import { LookupTable } from "@craftercms/models"; + +export interface resultHit { + _id: string; + _index: string; + _score: string; + _source: LookupTable; + _type: string; +} + +export interface SearchResult { + hits: resultHit[]; + max_score: number; + total: { + relation: string; + value: number; + } +} From de640d12f13ba21e1c8922a402891d460a0b8d3f Mon Sep 17 00:00:00 2001 From: jvega190 Date: Wed, 13 Oct 2021 10:37:32 -0600 Subject: [PATCH 06/10] Update params to be optional - 5025 --- packages/search/src/SearchService.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/search/src/SearchService.ts b/packages/search/src/SearchService.ts index c10fb0b..24a5f75 100644 --- a/packages/search/src/SearchService.ts +++ b/packages/search/src/SearchService.ts @@ -53,7 +53,7 @@ export function search(queryOrParams: Query | Object, config?: CrafterConfig): O * Returns a new Query object */ -export function createQuery(params: Object): T { +export function createQuery(params?: Object): T { let query, queryId = (params && params['uuid']) From aca8c090bf90973bad06b5796593f2c145d62f6e Mon Sep 17 00:00:00 2001 From: jvega190 Date: Wed, 13 Oct 2021 10:38:51 -0600 Subject: [PATCH 07/10] Update epicMiddleWare setup (due to deprecation) - 5025 --- packages/redux/src/utils.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/packages/redux/src/utils.ts b/packages/redux/src/utils.ts index 0376c93..febb04a 100644 --- a/packages/redux/src/utils.ts +++ b/packages/redux/src/utils.ts @@ -49,10 +49,7 @@ export function createReduxStore(config: { namespaceCrafterState: false }, config); - const epicMiddleware = createEpicMiddleware( - config.epicsArray - ? combineEpics(...allEpics.concat(config.epicsArray)) - : combineEpics(...allEpics)); + const epicMiddleware = createEpicMiddleware(); const enhancers = config.reduxDevTools ? ((typeof window !== "undefined" && window['__REDUX_DEVTOOLS_EXTENSION_COMPOSE__']) || compose) @@ -68,13 +65,18 @@ export function createReduxStore(config: { ? [ epicMiddleware, ...config.additionalMiddleWare ] : [ epicMiddleware ]; - return createStore( + const store = createStore( config.reducerMixin ? combineReducers({ ...reducer, ...config.reducerMixin }) : combineReducers(reducer), enhancers(applyMiddleware(...middlewares)) ); + epicMiddleware.run(config.epicsArray + ? combineEpics(...allEpics.concat(config.epicsArray)) + : combineEpics(...allEpics)); + + return store; } /** From b2529b7cabe2b5af87d71df2472e1cdf909fdef3 Mon Sep 17 00:00:00 2001 From: jvega190 Date: Wed, 13 Oct 2021 10:42:36 -0600 Subject: [PATCH 08/10] Update test file - 5025 --- packages/search/test/index.spec.ts | 50 +++++++++++++++++++++++------- 1 file changed, 38 insertions(+), 12 deletions(-) diff --git a/packages/search/test/index.spec.ts b/packages/search/test/index.spec.ts index 2ef19f8..5a77377 100644 --- a/packages/search/test/index.spec.ts +++ b/packages/search/test/index.spec.ts @@ -19,7 +19,7 @@ import { SearchService } from '@craftercms/search'; import { crafterConf } from '@craftercms/classes'; import 'mocha'; import 'url-search-params-polyfill'; -import { SolrQuery } from '../src/solr-query'; +import { ElasticQuery } from '../src/elastic-query'; import mock from 'xhr-mock'; import MockRequest from "xhr-mock/lib/MockRequest"; @@ -42,14 +42,18 @@ describe('Search Client', () => { describe('search', () => { it('should find all documents', done => { - mock.get("http://localhost:8080/crafter-search/api/2/search/search.json?uuid=12345&q=*%3A*&index_id=editorial", + mock.post("http://localhost:8080/api/1/site/elasticsearch/search", (req: MockRequest, res: MockResponse) => { res.body(JSON.stringify(searchResponse)); return res; }); - const query = SearchService.createQuery('solr', { 'uuid': '12345' }); - query.query = "*:*"; + const query = SearchService.createQuery({ 'uuid': '12345' }); + query.query = { + "query" : { + "match_all" : {} + } + }; SearchService.search(query, crafterConf.getConfig()).toPromise().then(result => { assert.equal(result.response.numFound, searchResponse.response.numFound); done(); @@ -59,15 +63,37 @@ describe('Search Client', () => { }); it('should apply all filters', done => { - mock.get("http://localhost:8080/crafter-search/api/2/search/search.json?uuid=12345&q=*%3A*&fq=content-type%3A%2Fpage%2Farticle&fq=featured_b%3Atrue&index_id=editorial", - (req: MockRequest, res: MockResponse) => { - res.body(JSON.stringify(searchResponse)); - return res; - }); + mock.post("http://localhost:8080/api/1/site/elasticsearch/search", + (req: MockRequest, res: MockResponse) => { + res.body(JSON.stringify(searchResponse)); + return res; + }); - var query = SearchService.createQuery('solr', { 'uuid': '12345' }); - query.query = "*:*"; - query.filterQueries = ["content-type:/page/article", "featured_b:true"]; + var query = SearchService.createQuery({ 'uuid': '12345' }); + query.query = { + "query" : { + "bool": { + "filter": [ + { + "bool": { + "should": [ + { + "match": { + "content-type": "/page/article" + } + } + ], + } + }, + { + "match": { + "featured_b": true + } + } + ] + } + } + }; SearchService.search(query, crafterConf.getConfig()).toPromise().then(result => { assert.equal(result.response.numFound, searchResponse.response.numFound); done(); From d5d76d2ae1c0e7bf4828e0225a6bb796bb84189a Mon Sep 17 00:00:00 2001 From: jvega190 Date: Mon, 18 Oct 2021 14:42:00 -0600 Subject: [PATCH 09/10] PR review updates --- packages/models/models.ts | 1 + packages/models/src/search.ts | 4 ++-- packages/redux/src/epics/search.ts | 2 +- packages/search/README.md | 4 ++-- 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/packages/models/models.ts b/packages/models/models.ts index 68ccee7..15353cb 100644 --- a/packages/models/models.ts +++ b/packages/models/models.ts @@ -23,3 +23,4 @@ export * from './src/LookupTable'; export * from './src/ReduxStore'; export * from './src/message'; export * from './src/ContentInstance'; +export * from './src/search'; diff --git a/packages/models/src/search.ts b/packages/models/src/search.ts index 33ecbff..7abb4ca 100644 --- a/packages/models/src/search.ts +++ b/packages/models/src/search.ts @@ -16,7 +16,7 @@ import { LookupTable } from "@craftercms/models"; -export interface resultHit { +export interface SearchResultHit { _id: string; _index: string; _score: string; @@ -25,7 +25,7 @@ export interface resultHit { } export interface SearchResult { - hits: resultHit[]; + hits: SearchResultHit[]; max_score: number; total: { relation: string; diff --git a/packages/redux/src/epics/search.ts b/packages/redux/src/epics/search.ts index c5556c9..3e54830 100644 --- a/packages/redux/src/epics/search.ts +++ b/packages/redux/src/epics/search.ts @@ -25,7 +25,7 @@ import { SEARCH, searchComplete } from '../actions/search'; -import {SearchResult} from "@craftercms/models/src/search"; +import { SearchResult } from "@craftercms/models"; export const searchEpic = (action$: Observable) => action$.pipe( diff --git a/packages/search/README.md b/packages/search/README.md index 5cd1689..18d4984 100644 --- a/packages/search/README.md +++ b/packages/search/README.md @@ -103,7 +103,7 @@ Map model const fields = ['headline_s', 'blurb_t']; const contentTypes = ['/page/post', '/component/post']; search( - createQuery('elasticsearch', { + createQuery({ query: { 'bool': { 'filter': [ @@ -135,7 +135,7 @@ You may alternatively use a different config by supplying the config object at t import { search, createQuery } from '@craftercms/search'; //Create query - const query = createQuery('elasticsearch'); + const query = createQuery(); query.query = { "query" : { "match_all" : {} From 8f8dd22d9ce8b38464b53d492309191cf9e3f455 Mon Sep 17 00:00:00 2001 From: jvega190 Date: Tue, 19 Oct 2021 10:50:11 -0600 Subject: [PATCH 10/10] Update search configuration paragraph and example --- packages/search/README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/packages/search/README.md b/packages/search/README.md index 18d4984..f94eb36 100644 --- a/packages/search/README.md +++ b/packages/search/README.md @@ -84,7 +84,7 @@ Map model #### Examples -- Connect to Crafter Search to query for content with ELASTIC SEARCH (crafter version: 3.1.x): +- Connect to Crafter Search to query for content with ELASTIC SEARCH: ```typescript import { crafterConf } from '@craftercms/classes'; @@ -129,18 +129,17 @@ Map model }); ``` -You may alternatively use a different config by supplying the config object at the service call invoking time +You may use a different config by supplying the config object at the service call invoking time. ```typescript import { search, createQuery } from '@craftercms/search'; //Create query - const query = createQuery(); - query.query = { + const query = createQuery({ "query" : { "match_all" : {} } - }; + }); search(query, { baseUrl: 'http://localhost:8080', site: 'editorial' }).subscribe((results) => { // ...