tethys/resources/js/search/search-results/dataservice.ts
Arno Kaimbacher 4b8f2a63d8 1. Timer auf 60 Minuten und 10 Minuten vorher eine Warnung
11. Continue statt Review Dataset (im Step 3)
12. keywords auf default 'uncontrolled' einfrieren
14. Lizenzen mit Links versehen
19. Timezone: 'timezone' => 'Europe/Vienna'
20. angefangen mit RDR -> TETHYS Unbenennungen
21. translated validation ausgebessert
22. dataset als Typescript Instanz
2020-06-10 21:09:27 +02:00

108 lines
3.8 KiB
TypeScript

import axios from "axios";
var SOLR_CONFIG = {
"server": "https://arcticdata.io/metacat/d1/mn/v2/query/solr?", // Solr server
"filter": "knb-lter-bnz", // Filter results for an organization or user
"limit": 4, // Max number of results to retrieve per page
"resultsElementId": "searchResults", // Element to contain results
"urlElementId": "searchUrl", // Element to display search URL
"countElementId": "resultCount", // Element showing number of results
"pagesElementId": "pagination", // Element to display result page links
"showPages": 5 // MUST BE ODD NUMBER! Max number of page links to show
};
export default {
async search(term: string, filterItems: Object, start?: string): Promise<any> {
// solr endpoint
// const host = 'http://voyagerdemo.com/';
const host = 'https://repository.geologie.ac.at/';
const path = 'solr/rdr_data/select?';
var base = host + path;
//const fields = 'id,server_date_published,abstract_output,title_output,title_additional,author,subject'; // fields we want returned
var fields = ["id",
"server_date_published",
"abstract_output",
"title_output",
"title_additional",
"author",
"subject"].toString();
var limit = "&rows=" + SOLR_CONFIG["limit"];
// var limit = solrConfig.limit;
var qfFields = "title^3 author^2 subject^1";
var params = "fl=" + fields;
if (term == "*%3A*") {
params += "&defType=edismax&wt=json&indent=on"; //edismax
} else {
params += "&defType=dismax&qf=" + qfFields + "&wt=json&indent=on"; //dismax
}
if (start === undefined) start = "0";
start = "&start=" + start;
const facetFields = "&facet=on&facet.field=language&facet.field={!key=datatype}doctype&facet.field=subject";//&fq=year:(2019)";//&facet.query=year:2018";
var filterFields = "";
// filterItems.forEach(function (item) {
// console.log(item.value + " " + item.category);
// filterFields += "&fq=" + item.category +":("+ item.value + ")";
// });
Object.entries(filterItems).forEach(([key, valueArray]) => {
// console.log(`${key} ${valueArray}`);
valueArray.forEach(function (value) {
filterFields += "&fq=" + key + ":(" + value + ")";
});
});
var query = "&q=" + term;
// $dismax->setQueryFields('title^3 abstract^2 subject^1');
//const api = `${host}${path}?defType=dismax&q=${term}&fl=${fields}&qf=${dismaxFields}&facet=on&${facetFields}&${filterFields}&wt=json&rows=20&indent=on`;
//const api = `${host}${path}?q=${term}&fl=${fields}&facet=on&${facetFields}&${filterFields}&wt=json&rows=20&indent=on`;
var api = base + params + limit + start + query + filterFields + facetFields;
let res = await axios.get(api);
// let { data } = res.data;
return res.data;//.response;//.docs;
},
async searchTerm(term: string): Promise<any> {
// solr endpoint
// const host = 'http://voyagerdemo.com/';
const host = 'https://repository.geologie.ac.at/';
const path = 'solr/rdr_data/select?';
var base = host + path;
//const fields = 'id,server_date_published,abstract_output,title_output,title_additional,author,subject'; // fields we want returned
var fields = ["id",
"server_date_published",
"abstract_output",
"title_output",
"title_additional",
"author",
"subject"].toString();
//var dismaxFields = "title^3 abstract^2 subject^1";
var qfFields = "title^3 author^2 subject^1";
var params = "fl=" + fields;
// if (term == "*%3A*") {
// params += "&defType=edismax&wt=json&indent=on"; //edismax
// } else {
params += "&defType=edismax&qf=" + qfFields + "&wt=json&indent=on"; //dismax
// }
var query = "&q=" + term + "*";
var api = base + params + query;
let res = await axios.get(api);
return res.data;//.response;//.docs;
}
}