Skip to content

Commit

Permalink
dql and lucene working again
Browse files Browse the repository at this point in the history
Signed-off-by: Kawika Avilla <[email protected]>
  • Loading branch information
kavilla committed Aug 25, 2024
1 parent 8fce6b1 commit 89e238c
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 28 deletions.
11 changes: 6 additions & 5 deletions src/plugins/data/public/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
Expand Down
8 changes: 6 additions & 2 deletions src/plugins/data/public/query/query_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ export class QueryService {

state$!: ReturnType<typeof createQueryStateObservable>;

public setup({ storage, uiSettings }: QueryServiceSetupDependencies): IQuerySetup {
public setup({
storage,
uiSettings,
defaultSearchInterceptor,
}: QueryServiceSetupDependencies): IQuerySetup {
this.filterManager = new FilterManager(uiSettings);

const timefilterService = new TimefilterService();
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,28 +3,23 @@
* 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<string, LanguageConfig> = new Map();

constructor(private readonly uiSettings: CoreStart['uiSettings']) {}

public async init(): Promise<void> {
if (!this.uiSettings.get(UI_SETTINGS.QUERY_ENHANCEMENTS_ENABLED)) return;
constructor(private readonly defaultSearchInterceptor: ISearchInterceptor) {
this.registerDefaultLanguages();
}

/**
* 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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Query>;
Expand All @@ -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<Query>(this.getDefaultQuery());
this.queryHistory = createHistory({ storage });
this.datasetService = new DatasetService(uiSettings);
this.languageService = new LanguageService(uiSettings);
this.languageService = new LanguageService(this.defaultSearchInterceptor);
}

private getDefaultQueryString() {
Expand All @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/data/public/query/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -35,6 +36,7 @@ export interface IQueryStart {
export interface QueryServiceSetupDependencies {
storage: DataStorage;
uiSettings: IUiSettingsClient;
defaultSearchInterceptor: ISearchInterceptor;
}

/** @internal */
Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/public/search/search_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ export class SearchService implements Plugin<ISearchSetup, ISearchStart> {
__enhance: (enhancements: SearchEnhancements) => {
this.searchInterceptor = enhancements.searchInterceptor;
},
getDefaultSearchInterceptor: () => this.defaultSearchInterceptor,
};
}

Expand Down
1 change: 1 addition & 0 deletions src/plugins/data/public/search/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export interface ISearchSetup {
* @internal
*/
__enhance: (enhancements: SearchEnhancements) => void;
getDefaultSearchInterceptor: () => ISearchInterceptor;
}

/**
Expand Down

0 comments on commit 89e238c

Please sign in to comment.