From 89e238c0072d1d83157b40b1a839e16d92f3396c Mon Sep 17 00:00:00 2001 From: Kawika Avilla Date: Sun, 25 Aug 2024 09:19:59 +0000 Subject: [PATCH] dql and lucene working again Signed-off-by: Kawika Avilla --- src/plugins/data/public/plugin.ts | 11 ++++++----- src/plugins/data/public/query/query_service.ts | 8 ++++++-- .../language_service/language_service.ts | 13 ++++--------- .../language_service/lib/dql_language.ts | 6 +++--- .../language_service/lib/lucene_language.ts | 6 +++--- .../query/query_string/query_string_manager.ts | 11 +++++------ src/plugins/data/public/query/types.ts | 2 ++ src/plugins/data/public/search/search_service.ts | 1 + src/plugins/data/public/search/types.ts | 1 + 9 files changed, 31 insertions(+), 28 deletions(-) diff --git a/src/plugins/data/public/plugin.ts b/src/plugins/data/public/plugin.ts index 09bdd96d58e2..ec267a20eee1 100644 --- a/src/plugins/data/public/plugin.ts +++ b/src/plugins/data/public/plugin.ts @@ -134,9 +134,15 @@ export class DataPublicPlugin expressions.registerFunction(opensearchaggs); expressions.registerFunction(indexPatternLoad); + const searchService = this.searchService.setup(core, { + usageCollection, + expressions, + }); + const queryService = this.queryService.setup({ uiSettings: core.uiSettings, storage: this.storage, + defaultSearchInterceptor: searchService.getDefaultSearchInterceptor(), }); uiActions.registerAction( @@ -157,11 +163,6 @@ export class DataPublicPlugin })) ); - const searchService = this.searchService.setup(core, { - usageCollection, - expressions, - }); - const uiService = this.uiService.setup(core, {}); const ac = this.autocomplete.setup(core); diff --git a/src/plugins/data/public/query/query_service.ts b/src/plugins/data/public/query/query_service.ts index 7264b2305ca7..95d1bd136f53 100644 --- a/src/plugins/data/public/query/query_service.ts +++ b/src/plugins/data/public/query/query_service.ts @@ -57,7 +57,11 @@ export class QueryService { state$!: ReturnType; - public setup({ storage, uiSettings }: QueryServiceSetupDependencies): IQuerySetup { + public setup({ + storage, + uiSettings, + defaultSearchInterceptor, + }: QueryServiceSetupDependencies): IQuerySetup { this.filterManager = new FilterManager(uiSettings); const timefilterService = new TimefilterService(); @@ -66,7 +70,7 @@ export class QueryService { storage, }); - this.queryStringManager = new QueryStringManager(storage, uiSettings); + this.queryStringManager = new QueryStringManager(storage, uiSettings, defaultSearchInterceptor); this.state$ = createQueryStateObservable({ filterManager: this.filterManager, diff --git a/src/plugins/data/public/query/query_string/language_service/language_service.ts b/src/plugins/data/public/query/query_string/language_service/language_service.ts index 6e6e60411b66..c4d2d85b8482 100644 --- a/src/plugins/data/public/query/query_string/language_service/language_service.ts +++ b/src/plugins/data/public/query/query_string/language_service/language_service.ts @@ -3,19 +3,14 @@ * SPDX-License-Identifier: Apache-2.0 */ -import { CoreStart } from 'opensearch-dashboards/public'; -import { UI_SETTINGS } from '../../../../common'; import { LanguageConfig } from './types'; import { getDQLLanguageConfig, getLuceneLanguageConfig } from './lib'; -import { getSearchService } from '../../../services'; +import { ISearchInterceptor } from '../../../search'; export class LanguageService { private languages: Map = new Map(); - constructor(private readonly uiSettings: CoreStart['uiSettings']) {} - - public async init(): Promise { - if (!this.uiSettings.get(UI_SETTINGS.QUERY_ENHANCEMENTS_ENABLED)) return; + constructor(private readonly defaultSearchInterceptor: ISearchInterceptor) { this.registerDefaultLanguages(); } @@ -23,8 +18,8 @@ export class LanguageService { * Registers default handlers for index patterns and indices. */ private registerDefaultLanguages() { - this.registerLanguage(getDQLLanguageConfig(getSearchService())); - this.registerLanguage(getLuceneLanguageConfig(getSearchService())); + this.registerLanguage(getDQLLanguageConfig(this.defaultSearchInterceptor)); + this.registerLanguage(getLuceneLanguageConfig(this.defaultSearchInterceptor)); } public registerLanguage(config: LanguageConfig): void { diff --git a/src/plugins/data/public/query/query_string/language_service/lib/dql_language.ts b/src/plugins/data/public/query/query_string/language_service/lib/dql_language.ts index d7498ee976f3..fef093f18554 100644 --- a/src/plugins/data/public/query/query_string/language_service/lib/dql_language.ts +++ b/src/plugins/data/public/query/query_string/language_service/lib/dql_language.ts @@ -4,13 +4,13 @@ */ import { LanguageConfig } from '../types'; -import { ISearchStart } from '../../../../search'; +import { ISearchInterceptor } from '../../../../search'; -export const getDQLLanguageConfig = (search: ISearchStart): LanguageConfig => { +export const getDQLLanguageConfig = (search: ISearchInterceptor): LanguageConfig => { return { id: 'kuery', title: 'DQL', - search: search.getDefaultSearchInterceptor(), + search, searchBar: { showDataSetsSelector: true, showDataSourcesSelector: false, diff --git a/src/plugins/data/public/query/query_string/language_service/lib/lucene_language.ts b/src/plugins/data/public/query/query_string/language_service/lib/lucene_language.ts index 344c50f7f92d..c22e194fac99 100644 --- a/src/plugins/data/public/query/query_string/language_service/lib/lucene_language.ts +++ b/src/plugins/data/public/query/query_string/language_service/lib/lucene_language.ts @@ -4,13 +4,13 @@ */ import { LanguageConfig } from '../types'; -import { ISearchStart } from '../../../../search'; +import { ISearchInterceptor } from '../../../../search'; -export const getLuceneLanguageConfig = (search: ISearchStart): LanguageConfig => { +export const getLuceneLanguageConfig = (search: ISearchInterceptor): LanguageConfig => { return { id: 'lucene', title: 'Lucene', - search: search.getDefaultSearchInterceptor(), + search, searchBar: { showDataSetsSelector: true, showDataSourcesSelector: false, diff --git a/src/plugins/data/public/query/query_string/query_string_manager.ts b/src/plugins/data/public/query/query_string/query_string_manager.ts index 9cc479f9ea84..e75df28eb8ba 100644 --- a/src/plugins/data/public/query/query_string/query_string_manager.ts +++ b/src/plugins/data/public/query/query_string/query_string_manager.ts @@ -35,6 +35,7 @@ import { Dataset, DataStorage, Query, TimeRange, UI_SETTINGS } from '../../../co import { createHistory, QueryHistory } from './query_history'; import { DatasetService, DatasetServiceContract } from './dataset_service'; import { LanguageService, LanguageServiceContract } from './language_service'; +import { ISearchInterceptor } from '../../search'; export class QueryStringManager { private query$: BehaviorSubject; @@ -44,12 +45,13 @@ export class QueryStringManager { constructor( private readonly storage: DataStorage, - private readonly uiSettings: CoreStart['uiSettings'] + private readonly uiSettings: CoreStart['uiSettings'], + private readonly defaultSearchInterceptor: ISearchInterceptor ) { this.query$ = new BehaviorSubject(this.getDefaultQuery()); this.queryHistory = createHistory({ storage }); this.datasetService = new DatasetService(uiSettings); - this.languageService = new LanguageService(uiSettings); + this.languageService = new LanguageService(this.defaultSearchInterceptor); } private getDefaultQueryString() { @@ -74,10 +76,7 @@ export class QueryStringManager { return { query, language: this.getDefaultLanguage(), - ...(this.uiSettings && - this.uiSettings.get(UI_SETTINGS.QUERY_ENHANCEMENTS_ENABLED) && { - dataset: this.datasetService?.getDefault(), - }), + dataset: this.datasetService?.getDefault(), }; } else { return query; diff --git a/src/plugins/data/public/query/types.ts b/src/plugins/data/public/query/types.ts index 4eaf7689d0a8..ee359f0939a2 100644 --- a/src/plugins/data/public/query/types.ts +++ b/src/plugins/data/public/query/types.ts @@ -7,6 +7,7 @@ import { IUiSettingsClient, SavedObjectsClientContract } from 'opensearch-dashbo import { Observable } from 'rxjs'; import { DataStorage } from '../../common'; import { IndexPattern, IndexPatternsService } from '../index_patterns'; +import { ISearchInterceptor } from '../search'; import { FilterManager } from './filter_manager'; import { QueryStringContract } from './query_string'; import { QueryStateChange, QueryState } from './state_sync'; @@ -35,6 +36,7 @@ export interface IQueryStart { export interface QueryServiceSetupDependencies { storage: DataStorage; uiSettings: IUiSettingsClient; + defaultSearchInterceptor: ISearchInterceptor; } /** @internal */ diff --git a/src/plugins/data/public/search/search_service.ts b/src/plugins/data/public/search/search_service.ts index 1b5323d5fda4..78a109a3ff06 100644 --- a/src/plugins/data/public/search/search_service.ts +++ b/src/plugins/data/public/search/search_service.ts @@ -127,6 +127,7 @@ export class SearchService implements Plugin { __enhance: (enhancements: SearchEnhancements) => { this.searchInterceptor = enhancements.searchInterceptor; }, + getDefaultSearchInterceptor: () => this.defaultSearchInterceptor, }; } diff --git a/src/plugins/data/public/search/types.ts b/src/plugins/data/public/search/types.ts index 29dc37b41c91..d34271ef7568 100644 --- a/src/plugins/data/public/search/types.ts +++ b/src/plugins/data/public/search/types.ts @@ -54,6 +54,7 @@ export interface ISearchSetup { * @internal */ __enhance: (enhancements: SearchEnhancements) => void; + getDefaultSearchInterceptor: () => ISearchInterceptor; } /**