OpenSearch progress. Stetic changes in result list. Faceted search not started

This commit is contained in:
Porras-Bernardez 2024-06-11 14:38:50 +02:00
parent 9b8b2bd5ac
commit a70e454cbc
6 changed files with 41 additions and 179 deletions

View file

@ -16,131 +16,7 @@ class DatasetService {
*
* @param {string} searchTerm - The search term to query.
*/
// async fetchDataFromOpenSearch(searchTerm: string): Promise<void> {
// // Define the OpenSearch endpoint URL
// const url = "http://opensearch.geoinformation.dev/tethys-records/_search";
// // Set the headers for the POST request
// const headers = {
// "Content-Type": "application/json",
// };
// // Construct the body of the POST request
// const body = {
// query: {
// bool: {
// // The `should` clause specifies that at least one of these conditions must match
// should: [
// {
// // Match the search term in the title field with fuzziness enabled and a boost of 3
// match: {
// title: {
// query: searchTerm,
// fuzziness: "AUTO", // Enable fuzzy search
// boost: 3 // Boosting the relevance of title matches
// }
// }
// },
// {
// // Match the search term in the author field with fuzziness enabled and a boost of 2
// match: {
// author: {
// query: searchTerm,
// fuzziness: "AUTO", // Enable fuzzy search
// boost: 2 // Boosting the relevance of author matches
// }
// }
// },
// {
// // Match the search term in the subject field with fuzziness enabled and a boost of 1
// match: {
// subject: {
// query: searchTerm,
// fuzziness: "AUTO", // Enable fuzzy search
// boost: 1 // Boosting the relevance of subject matches
// }
// }
// },
// {
// // Match the search term in the title field with a wildcard
// wildcard: {
// title: {
// value: `${searchTerm}*`, // Wildcard search for terms starting with searchTerm
// boost: 3 // Boosting the relevance of title matches
// }
// }
// },
// {
// // Match the search term in the author field with a wildcard
// wildcard: {
// author: {
// value: `${searchTerm}*`, // Wildcard search for terms starting with searchTerm
// boost: 2 // Boosting the relevance of author matches
// }
// }
// },
// {
// // Match the search term in the subject field with a wildcard
// wildcard: {
// subject: {
// value: `${searchTerm}*`, // Wildcard search for terms starting with searchTerm
// boost: 1 // Boosting the relevance of subject matches
// }
// }
// }
// ],
// // Ensure that at least one of the `should` clauses must match
// minimum_should_match: 1
// }
// },
// // Limit the number of search results to 10
// size: 10,
// // Start from the first result (pagination)
// from: 0,
// // Sort the results by the `server_date_published` field in descending order
// sort: [
// { server_date_published: { order: "desc" } }
// ],
// // Aggregations to provide facets for the `language` and `subject` fields
// aggs: {
// language: {
// terms: {
// field: "language.keyword" // Aggregate by the exact values of the `language` field
// }
// },
// subject: {
// terms: {
// field: "subjects.keyword", // Aggregate by the exact values of the `subjects` field
// size: 10 // Limit the number of aggregation buckets to 10
// }
// }
// }
// };
// try {
// // Send the POST request to the OpenSearch endpoint
// const response = await fetch(url, {
// method: "POST",
// headers: headers,
// body: JSON.stringify(body),
// });
// // Check if the response is not successful
// if (!response.ok) {
// throw new Error(`Failed to fetch data from ${url}, status: ${response.status}`);
// }
// // Parse the response JSON
// const data = await response.json();
// // Log the data from OpenSearch
// console.log("Data from OpenSearch:", data);
// console.log("Hits:", data.hits.total.value);
// } catch (error) {
// // Log any errors that occur during the fetch process
// console.error("Error fetching data:", error);
// }
// }
/* https://tethys.at/solr/rdr_data/select?&0=fl%3Did%2Clicence%2Cserver_date_published%2Cabstract_output%2Cidentifier%2Ctitle_output%2Ctitle_additional%2Cauthor%2Csubject%2Cdoctype&q=%2A
&q.op=or&defType=edismax&qf=title%5E3%20author%5E2%20subject%5E1&indent=on&wt=json&rows=10&start=0&sort=server_date_published%20desc&facet=on&json.facet.language=%7B%20type%3A%20%22
terms%22%2C%20field%3A%20%22language%22%20%7D&json.facet.subject=%7B%20type%3A%20%22terms%22%2C%20field%3A%20%22subject%22%2C%20limit%3A%20-1%20%7D&json.facet.year=%7B%20type%3A%20%22
@ -148,10 +24,19 @@ class DatasetService {
*/
// private openSearchUrl = "http://opensearch.geoinformation.dev/tethys-records/_search";
private openSearchUrl = "http://192.168.21.18/tethys-records/_search";
// private openSearchUrl = "http://192.168.21.18/tethys-records/_search";
// public searchTerm(term: string): Observable<Dataset[]> {
public searchTerm(term: string): Observable<{ datasets: Dataset[], highlights: HitHighlight[] }> {
public searchTerm(term: string, openCore: string, openHost: string): Observable<{ datasets: Dataset[], highlights: HitHighlight[] }> {
// OpenSearch endpoint
const host = "https://" + openHost; // When using geoinformation.dev
// const host = "http://" + openHost; // When using local OpenSearch dev endpoint
const path = "/" + openCore + "/_search";
const base = host + path;
/**
* The match query used for title, author, and subjects fields is case-insensitive by default. The standard analyzer is typically used, which lowercases the terms.
* The wildcard query is case-sensitive by default. To make it case-insensitive, it is needed to use a lowercase filter */
const lowercaseTerm = term.toLowerCase(); // Lowercase the search term
const body = {
query: {
bool: {
@ -159,9 +44,9 @@ class DatasetService {
{ match: { title: { query: term, fuzziness: "AUTO", boost: 3 } } },
{ match: { author: { query: term, fuzziness: "AUTO", boost: 2 } } },
{ match: { subjects: { query: term, fuzziness: "AUTO", boost: 1 } } }, // In SOLR is "subject"!
{ wildcard: { title: { value: `${term}*`, boost: 3 } } },
{ wildcard: { author: { value: `${term}*`, boost: 2 } } },
{ wildcard: { subjects: { value: `${term}*`, boost: 1 } } } // In SOLR is "subject"!
{ wildcard: { title: { value: `${lowercaseTerm}*`, boost: 3 } } },
{ wildcard: { author: { value: `${lowercaseTerm}*`, boost: 2 } } },
{ wildcard: { subjects: { value: `${lowercaseTerm}*`, boost: 1 } } } // In SOLR is "subject"!
],
minimum_should_match: 1
}
@ -190,7 +75,7 @@ class DatasetService {
* One of the key properties of this response object is _source, which is an array of documents (datasets) that match the search criteria.
* It is used the pipe method to chain RxJS operators to the Observable returned by api.get. The map operator is used to transform the emitted items of the Observable.
*/
return api.post<OpenSearchResponse>(this.openSearchUrl, body).pipe(
return api.post<OpenSearchResponse>(base, body).pipe(
tap(response => console.log("OpenSearchResponse:", response)), // Log the complete response
// tap(response => console.log("Aggre:", response.aggregations?.subjects.buckets[0])), // log the first subject of the array of subjects returned
// tap(response => console.log("Hits:", response.hits)), // log the first subject of the array of subjects returned
@ -206,9 +91,7 @@ class DatasetService {
// For the autocomplete search. Method to perform a search based on a term
public searchTerm_SOLR(term: string, solrCore: string, solrHost: string): Observable<Dataset[]> {
// Calling the test method for
// this.fetchDataFromOpenSearch(term);
// solr endpoint
// SOLR endpoint
const host = "https://" + solrHost;
const path = "/solr/" + solrCore + "/select?";
const base = host + path;
@ -268,6 +151,12 @@ class DatasetService {
solrHost: string,
start?: string, // Starting page
): Observable<SolrResponse> {
// console.log("face:", suggestion);
// console.log(activeFilterCategories);
// console.log(solrCore);
// console.log(solrHost);
// console.log(start);
// Construct Solr query parameters
const host = "https://" + solrHost;
const path = "/solr/" + solrCore + "/select?";