Sqlite fallback search

This commit is contained in:
Jordan Eldredge 2025-01-25 14:31:05 -08:00
parent faee5410ac
commit eb6b28b326
2 changed files with 23 additions and 2 deletions

View file

@ -1,8 +1,29 @@
import * as Utils from "./utils";
import algoliasearch from "algoliasearch";
var client = algoliasearch("HQ9I5Z6IM5", "6466695ec3f624a5fccf46ec49680e51");
var index = client.initIndex("Skins");
export async function graphqlSearch(query, options = {}) {
const queryText = Utils.gql`
query SearchQuery($query: String!) {
search_classic_skins(query: $query) {
filename
md5
nsfw
}
}`;
const data = await Utils.fetchGraphql(queryText, { query });
const hits = data.search_classic_skins.map((skin) => {
return {
objectID: skin.md5,
fileName: skin.filename,
nsfw: skin.nsfw,
};
});
return { hits };
}
export function search(query, options = {}) {
return new Promise((resolve, reject) => {
index.search(

View file

@ -19,7 +19,7 @@ import {
takeWhile,
mergeAll,
} from "rxjs/operators";
import { search } from "../algolia";
import { search, graphqlSearch } from "../algolia";
import queryParser from "../queryParser";
import { CHUNK_SIZE } from "../constants";
import * as UploadUtils from "../upload/uploadUtils";
@ -148,7 +148,7 @@ const searchEpic = (actions) =>
const [newQuery, options] = queryParser(query);
return from(search(newQuery, options)).pipe(
return from(graphqlSearch(newQuery, options)).pipe(
map((content) => {
const matchingSkins = content.hits.map((hit) => ({
hash: hit.objectID,