lucos_search_component 0.0.8 → 0.0.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +48 -8
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -50,6 +50,34 @@ class LucosSearchComponent extends HTMLSelectElement {
|
|
|
50
50
|
--lozenge-background: #044E00;
|
|
51
51
|
--lozenge-border: #033100;
|
|
52
52
|
}
|
|
53
|
+
/** Aquatic Places **/
|
|
54
|
+
.lozenge[data-type="Ocean"], .lozenge[data-type="Sea"], .lozenge[data-type="Sea Inlet"], .lozenge[data-type="River"], .lozenge[data-type="Lake"] {
|
|
55
|
+
--lozenge-background: #0085fe;
|
|
56
|
+
--lozenge-border: #0036b1;
|
|
57
|
+
}
|
|
58
|
+
/** Terrestrial Places **/
|
|
59
|
+
.lozenge[data-type="Archipelago"], .lozenge[data-type="Area Of Outstanding Natural Beauty"], .lozenge[data-type="Continent"], .lozenge[data-type="Historical Site"], .lozenge[data-type="Island"], .lozenge[data-type="Mountain"] {
|
|
60
|
+
--lozenge-background: #652c17;
|
|
61
|
+
--lozenge-border: #321200;
|
|
62
|
+
}
|
|
63
|
+
/** Cosmic Places **/
|
|
64
|
+
.lozenge[data-type="Galaxy"], .lozenge[data-type="Planetary System"], .lozenge[data-type="Star"], .lozenge[data-type="Planet"], .lozenge[data-type="Natural Satellite"] {
|
|
65
|
+
--lozenge-background: #15163a;
|
|
66
|
+
--lozenge-border: #000000;
|
|
67
|
+
--lozenge-text: #feffe8;
|
|
68
|
+
}
|
|
69
|
+
/** Human Places **/
|
|
70
|
+
.lozenge[data-type="Airport"], .lozenge[data-type="Autonomous Area"], .lozenge[data-type="City"], .lozenge[data-type="Country"], .lozenge[data-type="County"], .lozenge[data-type="Dependent Territory"], .lozenge[data-type="Historical Site"], .lozenge[data-type="Neighbourhood"], .lozenge[data-type="Province"], .lozenge[data-type="Region"], .lozenge[data-type="Road"], .lozenge[data-type="State"], .lozenge[data-type="Town"], .lozenge[data-type="Tribal Nation"], .lozenge[data-type="Village"] {
|
|
71
|
+
--lozenge-background: #aed0db;
|
|
72
|
+
--lozenge-border: #3f6674;
|
|
73
|
+
--lozenge-text: #0c1a1b;
|
|
74
|
+
}
|
|
75
|
+
/** Supernatural Places **/
|
|
76
|
+
.lozenge[data-type="Supernatural Realm"] {
|
|
77
|
+
--lozenge-background: #f1ff5f;
|
|
78
|
+
--lozenge-border: #674800;
|
|
79
|
+
--lozenge-text: #352005;
|
|
80
|
+
}
|
|
53
81
|
.lozenge.active {
|
|
54
82
|
--lozenge-border: #b00;
|
|
55
83
|
}
|
|
@@ -77,9 +105,12 @@ class LucosSearchComponent extends HTMLSelectElement {
|
|
|
77
105
|
const queryParams = new URLSearchParams({
|
|
78
106
|
q: query,
|
|
79
107
|
});
|
|
80
|
-
if (component.getAttribute("data-types"))
|
|
81
|
-
|
|
82
|
-
|
|
108
|
+
if (component.getAttribute("data-types")) {
|
|
109
|
+
queryParams.set("filter_by",`type:[${component.getAttribute("data-types")}]`);
|
|
110
|
+
} else if (component.getAttribute("data-exclude_types")) {
|
|
111
|
+
queryParams.set("filter_by",`type:![${component.getAttribute("data-exclude_types")}]`);
|
|
112
|
+
}
|
|
113
|
+
const results = await component.searchRequest(queryParams);
|
|
83
114
|
this.clearOptions();
|
|
84
115
|
callback(results);
|
|
85
116
|
},
|
|
@@ -102,9 +133,10 @@ class LucosSearchComponent extends HTMLSelectElement {
|
|
|
102
133
|
if (ids.length < 1) return;
|
|
103
134
|
const searchParams = new URLSearchParams({
|
|
104
135
|
q: '*',
|
|
105
|
-
|
|
136
|
+
filter_by: `id:[${ids.join(",")}]`,
|
|
137
|
+
per_page: ids.length,
|
|
106
138
|
});
|
|
107
|
-
const results = await component.
|
|
139
|
+
const results = await component.searchRequest(searchParams);
|
|
108
140
|
results.forEach(result => {
|
|
109
141
|
this.updateOption(result.id, result);
|
|
110
142
|
});
|
|
@@ -119,14 +151,22 @@ class LucosSearchComponent extends HTMLSelectElement {
|
|
|
119
151
|
},
|
|
120
152
|
});
|
|
121
153
|
}
|
|
122
|
-
async
|
|
154
|
+
async searchRequest(searchParams) {
|
|
123
155
|
const key = this.getAttribute("data-api-key");
|
|
124
156
|
if (!key) throw new Error("No `data-api-key` attribute set on `lucos-search` component");
|
|
125
|
-
|
|
126
|
-
|
|
157
|
+
searchParams.set('query_by', "pref_label,labels,description,lyrics");
|
|
158
|
+
searchParams.set('query_by_weights', "10,8,3,1");
|
|
159
|
+
searchParams.set('sort_by', "_text_match:desc,pref_label:asc");
|
|
160
|
+
searchParams.set('prioritize_num_matching_fields', false);
|
|
161
|
+
searchParams.set('include_fields', "id,pref_label,type");
|
|
162
|
+
const response = await fetch("https://arachne.l42.eu/search?"+searchParams.toString(), {
|
|
163
|
+
headers: { 'X-TYPESENSE-API-KEY': key },
|
|
127
164
|
signal: AbortSignal.timeout(900),
|
|
128
165
|
});
|
|
129
166
|
const data = await response.json();
|
|
167
|
+
if (!response.ok) {
|
|
168
|
+
throw new Error(`Recieved ${response.status} error from search endpoint: ${data["message"]}`);
|
|
169
|
+
}
|
|
130
170
|
const results = data.hits.map(result => {
|
|
131
171
|
return {...result, ...result.document}
|
|
132
172
|
});
|