From 32f743c04e967bf40a4a7d11d795c921669e44f1 Mon Sep 17 00:00:00 2001 From: frankporras Date: Wed, 19 Jun 2024 16:21:31 +0200 Subject: [PATCH] Tests. TODO solving failure with the faceted search with 2 subjects --- src/components/vs-input/vs-input.ts | 2 +- src/services/dataset.service.ts | 38 ++++++++++++++----- .../search-view/search-view-component.ts | 6 +-- 3 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/components/vs-input/vs-input.ts b/src/components/vs-input/vs-input.ts index 76c3ea6..468d55b 100644 --- a/src/components/vs-input/vs-input.ts +++ b/src/components/vs-input/vs-input.ts @@ -88,7 +88,7 @@ export default class VsInput extends Vue { const suggestions = new Array(); - console.log("getSuggestions > Display:", this.display); + // console.log("getSuggestions > Display:", this.display); // console.log("results:", this.results ); // console.log("highlights:", this.highlights); diff --git a/src/services/dataset.service.ts b/src/services/dataset.service.ts index a6ddc12..a976cce 100644 --- a/src/services/dataset.service.ts +++ b/src/services/dataset.service.ts @@ -70,8 +70,6 @@ class DatasetService { } }; - - // Make API call to OpenSearch and return the result /** * When a POST request is made to the OpenSearch server using the api.post method, the response received from OpenSearch is an object that includes various details about the search results. @@ -148,7 +146,7 @@ class DatasetService { const path = "/" + openCore + "/_search"; const base = host + path; - const lowercaseTerm = typeof suggestion === 'string' ? suggestion.toLowerCase() : suggestion.value.toLowerCase(); + const lowercaseTerm = typeof suggestion === 'string' ? suggestion.toLowerCase() : suggestion.value; // console.log("facetedsearchOPEN > suggestion entered:"); // console.log(suggestion); @@ -158,7 +156,7 @@ class DatasetService { /** * The query construction depends on whether the suggestion is a string or a Suggestion object. */ // When suggestion is a string: - const query = typeof suggestion === 'string' + const mainQuery = typeof suggestion === 'string' ? { bool: { should: [ @@ -182,11 +180,12 @@ class DatasetService { } }; - // Constructing Filters Based on Active Filter Categories + // // Constructing Filters Based on Active Filter Categories // const filters = Object.entries(activeFilterCategories).map(([category, values]) => ({ - // terms: { [`${category}.keyword`]: values } - // // terms: { [category]: values } + // // terms: { [`${category}.keyword`]: values } + // terms: { [category]: values } // })); + const filters = Object.entries(activeFilterCategories).map(([category, values]) => { if (category === "language" || category === "year") { return { terms: { [category]: values } }; @@ -194,12 +193,28 @@ class DatasetService { return { terms: { [`${category}.keyword`]: values } }; } }); - + + // console.log(activeFilterCategories); + console.log("mainQuery:", mainQuery); + console.log("filters:", filters); + const body = { + // query: { + // bool: { + // must: query, // Contains the main query constructed earlier. + // filter: filters // Contains the filters constructed from activeFilterCategories. + // // filter: [ + // // { "terms": { "subjects.keyword": ["Lower Austria", "counting data"] } }, + // // { "term": { "language": "en" } } + // // ] // Contains the filters constructed from activeFilterCategories. + // } + // }, query: { bool: { - must: query, // Contains the main query constructed earlier. - filter: filters // Contains the filters constructed from activeFilterCategories. + must: [ + mainQuery, // Ensure the main query must be satisfied + ...filters // Ensure all filters must be satisfied + ] } }, size: 10, @@ -224,6 +239,9 @@ class DatasetService { } }; +console.log("body:", body); + + const stations = api.post(base, body); return stations; diff --git a/src/views/search-view/search-view-component.ts b/src/views/search-view/search-view-component.ts index 5ce94b6..cf5c3ee 100644 --- a/src/views/search-view/search-view-component.ts +++ b/src/views/search-view/search-view-component.ts @@ -131,7 +131,7 @@ export default class SearchViewComponent extends Vue { this.activeFilterCategories = new ActiveFilterCategories(); this.facets = new FacetResults(); this.searchTerm = suggestion; - console.log("ONSEARCH > suggestion: ", suggestion); + // console.log("ONSEARCH > suggestion: ", suggestion); // /* Perform faceted search. The method returns an Observable, and the code subscribes to this Observable to handle the response. If the response is successful, it calls the dataHandler method // with the Solr response as a parameter. If there is an error, it calls the errorHandler method with the error message as a parameter */ @@ -157,10 +157,10 @@ export default class SearchViewComponent extends Vue { // console.log(this.results); // console.log(this.numFound); // console.log(res.hits.hits); - // console.log(res.hits.total.value); + // console.log(res.hits.total.value); console.log(res); + // console.log("results:"); console.log(res); - // for (const key in this.results) { // if (Object.prototype.hasOwnProperty.call(this.results, key)) { // const element = this.results[key];