Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lukavdplas committed Nov 2, 2023
1 parent 736930b commit 09b909a
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 33 deletions.
2 changes: 1 addition & 1 deletion frontend/src/app/models/page-results.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SearchResults } from './search-results';
import { Results } from './results';
import { DocumentPage } from './document-page';

const RESULTS_PER_PAGE = 20;
export const RESULTS_PER_PAGE = 20;

export interface PageResultsParameters {
from: number;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/services/elastic-search.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ describe('ElasticSearchService', () => {
it('should make a search request', async () => {
const queryModel = new QueryModel(mockCorpus);
const size = 2;
const response = service.search(queryModel, size);
const response = service.loadResults(queryModel, 0, size);

const searchUrl = `/api/es/${mockCorpus.name}/_search?size=${size}`;
httpTestingController.expectOne(searchUrl).flush(mockResponse);
Expand Down
25 changes: 6 additions & 19 deletions frontend/src/app/services/elastic-search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import {
} from '../models/index';
import * as _ from 'lodash';
import { QueryParameters } from '../models/search-requests';
import { RESULTS_PER_PAGE } from '../models/page-results';


@Injectable()
export class ElasticSearchService {

private resultsPerPage = 20;

constructor(private http: HttpClient) {
}

Expand Down Expand Up @@ -78,29 +77,17 @@ export class ElasticSearchService {
};
}



public async search(
queryModel: QueryModel,
size?: number,
): Promise<SearchResults> {
const esQuery = queryModel.toEsQuery();

// Perform the search
const response = await this.execute(queryModel.corpus, esQuery, size || this.resultsPerPage);
return this.parseResponse(queryModel.corpus, response);
}


/**
* Load results for requested page
*/
public async loadResults(
queryModel: QueryModel, from: number,
size: number): Promise<SearchResults> {
queryModel: QueryModel,
from: number,
size: number = RESULTS_PER_PAGE
): Promise<SearchResults> {
const esQuery = queryModel.toEsQuery();
// Perform the search
const response = await this.execute(queryModel.corpus, esQuery, size || this.resultsPerPage, from);
const response = await this.execute(queryModel.corpus, esQuery, size, from);
return this.parseResponse(queryModel.corpus, response);
}

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app/services/search.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe('SearchService', () => {

it('should search', inject([SearchService], async (service: SearchService) => {
const queryModel = new QueryModel(mockCorpus);
const results = await service.search(queryModel);
const results = await service.loadResults(queryModel, 0, 20);
expect(results).toBeTruthy();
expect(results.total.value).toBeGreaterThan(0);
}));
Expand Down
11 changes: 1 addition & 10 deletions frontend/src/app/services/search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,7 @@ export class SearchService {
from,
size
);
results.fields = queryModel.corpus.fields.filter((field) => field.resultsOverview);
return results;
}

public async search(queryModel: QueryModel
): Promise<SearchResults> {
const request = this.elasticSearchService.search(queryModel);
return request.then(results =>
this.filterResultsFields(results, queryModel)
);
return this.filterResultsFields(results, queryModel);
}

public async aggregateSearch(
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/mock-data/elastic-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class ElasticSearchServiceMock {
return Promise.resolve(makeDocument({content: 'Hello world!'}));
}

search(): Promise<SearchResults> {
loadResults(): Promise<SearchResults> {
return Promise.resolve({
total: {
relation: 'eq',
Expand Down

0 comments on commit 09b909a

Please sign in to comment.