mirror of
https://github.com/captbaritone/webamp.git
synced 2026-07-18 00:55:54 +00:00
Sqlite fallback search
This commit is contained in:
parent
faee5410ac
commit
eb6b28b326
2 changed files with 23 additions and 2 deletions
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue