- add search components: vs-result.vue, vs-input.vue, facet-category.vue
- add search models - add opensans font - add bulma css framework - add axios, rxjs, vue-property-decorator - npm updates
This commit is contained in:
parent
8e0bc7c18d
commit
156bf0ae26
30 changed files with 4937 additions and 2044 deletions
140
src/services/dataset.service.ts
Normal file
140
src/services/dataset.service.ts
Normal file
|
@ -0,0 +1,140 @@
|
|||
// import http from "@/http-common";
|
||||
import api from "../api/api";
|
||||
import { Observable } from "rxjs";
|
||||
import { map } from "rxjs/operators";
|
||||
import { Dataset, Suggestion } from "@/models/dataset";
|
||||
import { SolrResponse } from "@/models/headers";
|
||||
import { ActiveFilterCategories } from "@/models/solr";
|
||||
|
||||
export class DatasetService {
|
||||
// for the autocomplete search
|
||||
public searchTerm(term: string, solrCore: string, solrHost: string): Observable<Dataset[]> {
|
||||
// solr endpoint
|
||||
// const host = 'http://voyagerdemo.com/';
|
||||
// const host = 'https://www.tethys.at/';''
|
||||
const host = "https://" + solrHost;
|
||||
const path = "/solr/" + solrCore + "/select?";
|
||||
const base = host + path;
|
||||
|
||||
//const fields = 'id,server_date_published,abstract_output,title_output,title_additional,author,subject'; // fields we want returned
|
||||
const fields = ["id", "licence", "server_date_published", "abstract_output", "title_output", "title_additional", "author", "subject", "doctype"].toString();
|
||||
|
||||
//var dismaxFields = "title^3 abstract^2 subject^1";
|
||||
const qfFields = "title^3 author^2 subject^1";
|
||||
let 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
|
||||
// }
|
||||
|
||||
const query = "&q=" + term + "*";
|
||||
// const apiU = base + params + query;
|
||||
|
||||
const q_params = {
|
||||
"0": "fl=" + fields,
|
||||
q: term + "*",
|
||||
defType: "edismax",
|
||||
qf: qfFields,
|
||||
indent: "on",
|
||||
wt: "json",
|
||||
};
|
||||
|
||||
const stations = api.get<SolrResponse>(base, q_params).pipe(map((res: SolrResponse) => res.response.docs));
|
||||
|
||||
return stations;
|
||||
}
|
||||
|
||||
public facetedSearch(
|
||||
suggestion: Suggestion | string,
|
||||
activeFilterCategories: ActiveFilterCategories,
|
||||
solrCore: string,
|
||||
solrHost: string,
|
||||
start?: string,
|
||||
): Observable<SolrResponse> {
|
||||
// solr endpoint
|
||||
// const host = 'http://voyagerdemo.com/';
|
||||
//const host = 'https://www.tethys.at/';
|
||||
//const host = 'https://' + solrHost;
|
||||
const host = "https://" + solrHost;
|
||||
const path = "/solr/" + solrCore + "/select?";
|
||||
const base = host + path;
|
||||
|
||||
//const fields = 'id,server_date_published,abstract_output,title_output,title_additional,author,subject'; // fields we want returned
|
||||
const fields = ["id", "licence", "server_date_published", "abstract_output", "identifier", "title_output", "title_additional", "author", "subject", "doctype"].toString();
|
||||
|
||||
// const qfFields = "title^3 author^2 subject^1";
|
||||
// let 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
|
||||
// }
|
||||
|
||||
let term, queryOperator, qfFields;
|
||||
if (typeof suggestion === "string") {
|
||||
term = suggestion + "*";
|
||||
queryOperator = "or";
|
||||
qfFields = "title^3 author^2 subject^1";
|
||||
} else if (suggestion instanceof Suggestion) {
|
||||
term = suggestion.type + ':"' + suggestion.value + '"';
|
||||
queryOperator = "and";
|
||||
qfFields = undefined;
|
||||
}
|
||||
|
||||
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";
|
||||
|
||||
const filterFields = new Array<string>();
|
||||
if (Object.keys(activeFilterCategories).length > 0) {
|
||||
// filterFields = '["';
|
||||
// const filterFields: string[] = [];
|
||||
// const facet_fields: FacetFields = res.facets;
|
||||
let prop: keyof typeof activeFilterCategories;
|
||||
for (prop in activeFilterCategories) {
|
||||
const filterItems = activeFilterCategories[prop];
|
||||
// const filterItems = facetCategory.values;
|
||||
// filterItems.forEach((filterItem) => {
|
||||
// console.log(`${key} ${valueArray}`);
|
||||
filterItems.forEach(function (value: string) {
|
||||
// filterFields += "&fq=" + key + ':("' + value + '")';
|
||||
filterFields.push(prop + ':("' + value + '")');
|
||||
// filterFields += prop + ":" + value;
|
||||
});
|
||||
}
|
||||
// filterFields += '"]';
|
||||
}
|
||||
const query = "&sort=server_date_published desc" + "&q=" + term;
|
||||
|
||||
// const api =
|
||||
// base + params + limit + start + query + filterFields + facetFields;
|
||||
|
||||
// https://solr.apache.org/guide/8_4/json-request-api.html
|
||||
const q_params = {
|
||||
"0": "fl=" + fields,
|
||||
q: term,
|
||||
"q.op": queryOperator,
|
||||
defType: "edismax",
|
||||
qf: qfFields,
|
||||
// df: "title",
|
||||
indent: "on",
|
||||
wt: "json",
|
||||
rows: 10,
|
||||
// fq: ["subject:Steiermark", "language:de"],
|
||||
fq: filterFields,
|
||||
start: start,
|
||||
facet: "on",
|
||||
// "facet.field": "language",
|
||||
"json.facet.language": '{ type: "terms", field: "language" }',
|
||||
"json.facet.subject": '{ type: "terms", field: "subject" }',
|
||||
};
|
||||
|
||||
const stations = api.get<SolrResponse>(base, q_params);
|
||||
// .pipe(map((res) => res.response.docs));
|
||||
|
||||
return stations;
|
||||
}
|
||||
}
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue