Commit
·
b8692a1
1
Parent(s):
204fb4f
Refactor search functionality with new switchSearchType method and reduced API query limit
Browse files- index.html +10 -4
index.html
CHANGED
|
@@ -145,6 +145,12 @@
|
|
| 145 |
this.themes = data.themes;
|
| 146 |
this.totalPages = data.totalPages;
|
| 147 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
async getThemes(page, sort, useTestData) {
|
| 149 |
let data;
|
| 150 |
if (useTestData) {
|
|
@@ -159,10 +165,10 @@
|
|
| 159 |
if (this.searchType === 'semantic') {
|
| 160 |
searchUrl = `https://huggingface.co/api/spaces/semantic-search?q=${encodeURIComponent(this.searchQuery)}`;
|
| 161 |
} else {
|
| 162 |
-
searchUrl = `https://huggingface.co/api/spaces?limit=
|
| 163 |
}
|
| 164 |
} else {
|
| 165 |
-
searchUrl = `https://huggingface.co/api/spaces?limit=
|
| 166 |
}
|
| 167 |
const res = await fetch(searchUrl);
|
| 168 |
data = await res.json();
|
|
@@ -227,14 +233,14 @@
|
|
| 227 |
>
|
| 228 |
<div class="flex border border-l-0 rounded-r-lg overflow-hidden">
|
| 229 |
<button
|
| 230 |
-
@click="
|
| 231 |
:class="searchType === 'semantic' ? 'bg-orange-300 text-white' : 'bg-white text-gray-800'"
|
| 232 |
class="px-3 py-1"
|
| 233 |
>
|
| 234 |
Semantic
|
| 235 |
</button>
|
| 236 |
<button
|
| 237 |
-
@click="
|
| 238 |
:class="searchType === 'keyword' ? 'bg-orange-300 text-white' : 'bg-white text-gray-800'"
|
| 239 |
class="px-3 py-1 border-l"
|
| 240 |
>
|
|
|
|
| 145 |
this.themes = data.themes;
|
| 146 |
this.totalPages = data.totalPages;
|
| 147 |
},
|
| 148 |
+
async switchSearchType(type) {
|
| 149 |
+
this.searchType = type;
|
| 150 |
+
if (this.searchQuery) {
|
| 151 |
+
await this.searchThemes();
|
| 152 |
+
}
|
| 153 |
+
},
|
| 154 |
async getThemes(page, sort, useTestData) {
|
| 155 |
let data;
|
| 156 |
if (useTestData) {
|
|
|
|
| 165 |
if (this.searchType === 'semantic') {
|
| 166 |
searchUrl = `https://huggingface.co/api/spaces/semantic-search?q=${encodeURIComponent(this.searchQuery)}`;
|
| 167 |
} else {
|
| 168 |
+
searchUrl = `https://huggingface.co/api/spaces?limit=100&filter=${searchFilters}&search=${encodeURIComponent(this.searchQuery)}&expand[]=subdomain&expand[]=lastModified&expand[]=likes&expand[]=runtime`;
|
| 169 |
}
|
| 170 |
} else {
|
| 171 |
+
searchUrl = `https://huggingface.co/api/spaces?limit=100&filter=${encodeURIComponent(searchFilters)}&expand[]=subdomain&expand[]=lastModified&expand[]=likes&expand[]=runtime`;
|
| 172 |
}
|
| 173 |
const res = await fetch(searchUrl);
|
| 174 |
data = await res.json();
|
|
|
|
| 233 |
>
|
| 234 |
<div class="flex border border-l-0 rounded-r-lg overflow-hidden">
|
| 235 |
<button
|
| 236 |
+
@click="switchSearchType('semantic')"
|
| 237 |
:class="searchType === 'semantic' ? 'bg-orange-300 text-white' : 'bg-white text-gray-800'"
|
| 238 |
class="px-3 py-1"
|
| 239 |
>
|
| 240 |
Semantic
|
| 241 |
</button>
|
| 242 |
<button
|
| 243 |
+
@click="switchSearchType('keyword')"
|
| 244 |
:class="searchType === 'keyword' ? 'bg-orange-300 text-white' : 'bg-white text-gray-800'"
|
| 245 |
class="px-3 py-1 border-l"
|
| 246 |
>
|