This repository was archived by the owner on Jan 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathValuesApi.js
114 lines (105 loc) · 3.44 KB
/
ValuesApi.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { polyfill } from 'es6-promise';
import 'isomorphic-fetch';
polyfill();
export default {
name: 'ValuesApi',
getValues(name, params, options, searchState, qtext, facetObject) {
//get options
return fetch('/v1/config/query/all?format=json', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json'
},
credentials: 'same-origin'
}).then(
response => {
return response.json().then(function(json) {
let options = json.options || {};
let path = '';
let collation = '';
for (let i=0; i < options.constraint.length; i++) {
if (options.constraint[i].name === name){
path = options.constraint[i].range['path-index'].text;
collation = options.constraint[i].range.collation;
}
}
options.values = {
name: name,
range: {
collation: collation,
type: 'xs:string',
'path-index': {
text: path,
ns: ''
}
},
'values-option' : ['frequency-order']
};
//combine with search
let searchType = 'all';
// let searchType = searchType !== undefined ? searchType : 'all';
let start = facetObject.facetValues.length +1 || 1;
// let start = 1;
let pageLength = 10;
// var limit = 100;
var limit = start + pageLength - 1;
let facets = Object.keys(searchState.activeFacets || {}).map(function(facetName) {
let constraintType = searchState.activeFacets[facetName].type;
if (constraintType && constraintType.substring(0, 3) === 'xs:') {
constraintType = 'range';
}
let temp = {
'range-constraint-query' :{
'constraint-name': facetName,
constraintType: constraintType
}
};
searchState.activeFacets[facetName].values.map(function(facetValue) {
temp.value = [facetValue.value];
if (facetValue.negated) {
temp['range-operator'] = 'NE';
}
});
return temp;
});
let valuesParams = new URLSearchParams();
valuesParams.append('q', qtext);
valuesParams.append('start', start);
valuesParams.append('pageLength', pageLength);
valuesParams.append('limit', limit);
valuesParams.append('direction', 'descending');
let valuesParamsString = valuesParams.toString();
return fetch('/v1/values/' + name + '?'+valuesParamsString, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json'
},
body: JSON.stringify({
search: {
query: {
queries: {
and: [].concat(facets)
}},
options: options
}}),
credentials: 'same-origin'
}).then(
response => {
return response.json().then(function(json) {
return { response: json };
});
},
error => {
return error;
}
);
});
},
error => {
return error;
}
);
}
};