Skip to content

Commit eb6b28b

Browse files
committed
Sqlite fallback search
1 parent faee541 commit eb6b28b

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

packages/skin-museum-client/src/algolia.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,29 @@
1+
import * as Utils from "./utils";
12
import algoliasearch from "algoliasearch";
23
var client = algoliasearch("HQ9I5Z6IM5", "6466695ec3f624a5fccf46ec49680e51");
34

45
var index = client.initIndex("Skins");
56

7+
export async function graphqlSearch(query, options = {}) {
8+
const queryText = Utils.gql`
9+
query SearchQuery($query: String!) {
10+
search_classic_skins(query: $query) {
11+
filename
12+
md5
13+
nsfw
14+
}
15+
}`;
16+
const data = await Utils.fetchGraphql(queryText, { query });
17+
const hits = data.search_classic_skins.map((skin) => {
18+
return {
19+
objectID: skin.md5,
20+
fileName: skin.filename,
21+
nsfw: skin.nsfw,
22+
};
23+
});
24+
return { hits };
25+
}
26+
627
export function search(query, options = {}) {
728
return new Promise((resolve, reject) => {
829
index.search(

packages/skin-museum-client/src/redux/epics.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
takeWhile,
2020
mergeAll,
2121
} from "rxjs/operators";
22-
import { search } from "../algolia";
22+
import { search, graphqlSearch } from "../algolia";
2323
import queryParser from "../queryParser";
2424
import { CHUNK_SIZE } from "../constants";
2525
import * as UploadUtils from "../upload/uploadUtils";
@@ -148,7 +148,7 @@ const searchEpic = (actions) =>
148148

149149
const [newQuery, options] = queryParser(query);
150150

151-
return from(search(newQuery, options)).pipe(
151+
return from(graphqlSearch(newQuery, options)).pipe(
152152
map((content) => {
153153
const matchingSkins = content.hits.map((hit) => ({
154154
hash: hit.objectID,

0 commit comments

Comments
 (0)