From 8962345f9996998d9793b21dc65c498efe4ecf01 Mon Sep 17 00:00:00 2001 From: frankporras Date: Tue, 14 May 2024 16:31:22 +0200 Subject: [PATCH] Created a first method to test query to OpenSearch --- src/services/dataset.service.ts | 39 +++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/src/services/dataset.service.ts b/src/services/dataset.service.ts index 3ee9cac..f6e73bb 100644 --- a/src/services/dataset.service.ts +++ b/src/services/dataset.service.ts @@ -9,6 +9,43 @@ import { VUE_API } from "@/constants"; import { deserialize } from "class-transformer"; class DatasetService { + /* Initial test method to fetch and log data from the local OpenSearch endpoint (new backend) */ + async fetchDataFromOpenSearch(searchTerm: string): Promise { + const url = "http://192.168.21.18/tethys-records/_search"; + const headers = { + "Content-Type": "application/json", + }; + const body = { + query: { + match: { + title: searchTerm, + }, + }, + }; + + try { + const response = await fetch(url, { + method: "POST", + headers: headers, + body: JSON.stringify(body), + }); + + if (!response.ok) { + throw new Error(`Failed to fetch data from ${url}, status: ${response.status}`); + } + + const data = await response.json(); + console.log("Data from OpenSearch:", data); + } catch (error) { + 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 + terms%22%2C%20field%3A%20%22year%22%20%7D&json.facet.author=%7B%20type%3A%20%22terms%22%2C%20field%3A%20%22author_facet%22%2C%20limit%3A%20-1%20%7D + */ /* 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 @@ -18,6 +55,8 @@ class DatasetService { // For the autocomplete search. Method to perform a search based on a term public searchTerm(term: string, solrCore: string, solrHost: string): Observable { + // Calling the test method for + this.fetchDataFromOpenSearch(term); // solr endpoint const host = "https://" + solrHost; const path = "/solr/" + solrCore + "/select?";