forked from geolba/tethys.frontend
CTS link opens in new window. New comments on search related classes and functions
This commit is contained in:
parent
d50bf55fb3
commit
d50e93a658
3 changed files with 70 additions and 11 deletions
|
@ -16,7 +16,7 @@ class DatasetService {
|
|||
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
|
||||
*/
|
||||
|
||||
// for the autocomplete search
|
||||
// For the autocomplete search. Method to perform a search based on a term
|
||||
public searchTerm(term: string, solrCore: string, solrHost: string): Observable<Dataset[]> {
|
||||
// solr endpoint
|
||||
const host = "https://" + solrHost;
|
||||
|
@ -48,13 +48,14 @@ class DatasetService {
|
|||
wt: "json",
|
||||
};
|
||||
|
||||
// Make API call to Solr and return the result
|
||||
const stations = api.get<SolrResponse>(base, q_params).pipe(map((res: SolrResponse) => res.response.docs));
|
||||
|
||||
return stations;
|
||||
}
|
||||
|
||||
|
||||
/* Only one facet => Author: Coric, Stjepan (16)
|
||||
/* E.g. Only one facet => Author: Coric, Stjepan (16)
|
||||
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&fq=author%3A%28%22Coric%2C%20Stjepan%22%29&start=0&sort=server_date_published%20desc&facet=on
|
||||
&json.facet.language=%7B%20type%3A%20%22terms%22%2C%20field%3A%20%22language%22%20%7D
|
||||
|
@ -62,6 +63,7 @@ class DatasetService {
|
|||
&json.facet.year=%7B%20type%3A%20%22terms%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 */
|
||||
|
||||
// Method to perform a faceted search
|
||||
public facetedSearch(
|
||||
suggestion: Suggestion | string,
|
||||
activeFilterCategories: ActiveFilterCategories,
|
||||
|
@ -69,6 +71,7 @@ class DatasetService {
|
|||
solrHost: string,
|
||||
start?: string, // Starting page
|
||||
): Observable<SolrResponse> {
|
||||
// Construct Solr query parameters
|
||||
const host = "https://" + solrHost;
|
||||
const path = "/solr/" + solrCore + "/select?";
|
||||
const base = host + path;
|
||||
|
@ -86,6 +89,7 @@ class DatasetService {
|
|||
"doctype",
|
||||
].toString();
|
||||
|
||||
// Determine search term, query operator, and query fields based on the suggestion type
|
||||
let term, queryOperator, qfFields;
|
||||
if (typeof suggestion === "string") {
|
||||
term = suggestion + "*";
|
||||
|
@ -97,10 +101,11 @@ class DatasetService {
|
|||
qfFields = undefined;
|
||||
}
|
||||
|
||||
// Set default value for start if not provided
|
||||
if (start === undefined) start = "0";
|
||||
|
||||
// Construct filter fields based on active filter categories
|
||||
const filterFields = new Array<string>();
|
||||
|
||||
if (Object.keys(activeFilterCategories).length > 0) {
|
||||
/* Declare variable prop with a type that is a key of the activeFilterCategories. The 'keyof typeof' activeFilterCategories type represents all possible keys
|
||||
that can exist on the activeFilterCategories --> prop can only be assigned a value that is a key of the activeFilterCategories object */
|
||||
|
@ -109,11 +114,13 @@ class DatasetService {
|
|||
const filterItems = activeFilterCategories[prop];
|
||||
filterItems.forEach(function (value: string) {
|
||||
filterFields.push(prop + ':("' + value + '")');
|
||||
// e.g. Array [ 'subject:("Vektordaten")', 'author:("GeoSphere Austria, ")' ]
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// https://solr.apache.org/guide/8_4/json-request-api.html
|
||||
// Construct Solr query parameters
|
||||
const q_params = {
|
||||
"0": "fl=" + fields,
|
||||
q: term,
|
||||
|
@ -135,12 +142,26 @@ class DatasetService {
|
|||
"json.facet.year": '{ type: "terms", field: "year" }',
|
||||
"json.facet.author": '{ type: "terms", field: "author_facet", limit: -1 }',
|
||||
};
|
||||
|
||||
/* E.g.
|
||||
{"0":"fl=id,licence,server_date_published,abstract_output,identifier,title_output,title_additional,author,subject,doctype","q":"*","q.op":"or","defType":"edismax",
|
||||
"qf":"title^3 author^2 subject^1",
|
||||
"indent":"on","wt":"json","rows":10,
|
||||
"fq":["subject:(\"Vektordaten\")","author:(\"GeoSphere Austria, \")"],
|
||||
"start":"0","sort":"server_date_published desc","facet":"on",
|
||||
"json.facet.language":"{ type: \"terms\", field: \"language\" }",
|
||||
"json.facet.subject":"{ type: \"terms\", field: \"subject\", limit: -1 }",
|
||||
"json.facet.year":"{ type: \"terms\", field: \"year\" }",
|
||||
"json.facet.author":"{ type: \"terms\", field: \"author_facet\", limit: -1 }"}
|
||||
*/
|
||||
// console.log(JSON.stringify(q_params));
|
||||
|
||||
// Make API call to Solr and return the result
|
||||
const stations = api.get<SolrResponse>(base, q_params);
|
||||
|
||||
return stations;
|
||||
}
|
||||
|
||||
// Method to fetch years
|
||||
public getYears(): Observable<string[]> {
|
||||
const host = VUE_API;
|
||||
const path = "/api/years";
|
||||
|
@ -150,6 +171,7 @@ class DatasetService {
|
|||
return years;
|
||||
}
|
||||
|
||||
// Method to fetch documents for a specific year
|
||||
public getDocuments(year: string): Observable<Array<DbDataset>> {
|
||||
const host = VUE_API;
|
||||
const path = "/api/sitelinks/" + year;
|
||||
|
@ -159,6 +181,7 @@ class DatasetService {
|
|||
return documents;
|
||||
}
|
||||
|
||||
// Method to fetch a dataset by its ID
|
||||
public getDataset(id: number): Observable<DbDataset> {
|
||||
const host = VUE_API;
|
||||
const path = "/api/dataset/" + id;
|
||||
|
@ -168,6 +191,7 @@ class DatasetService {
|
|||
return dataset;
|
||||
}
|
||||
|
||||
// Method to fetch a dataset by its DOI
|
||||
public getDatasetByDoi(doi: string): Observable<DbDataset> {
|
||||
const host = VUE_API;
|
||||
const path = "/api/dataset/10.24341/tethys." + doi;
|
||||
|
@ -177,6 +201,7 @@ class DatasetService {
|
|||
return dataset;
|
||||
}
|
||||
|
||||
// Method to prepare dataset object
|
||||
private prepareDataset(datasetObj: DbDataset): DbDataset {
|
||||
const dataset = deserialize<DbDataset>(DbDataset, JSON.stringify(datasetObj));
|
||||
dataset.url = document.documentURI;
|
||||
|
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue