Skip to content

Commit

Permalink
Sqlite fallback search
Browse files Browse the repository at this point in the history
  • Loading branch information
captbaritone committed Jan 25, 2025
1 parent faee541 commit eb6b28b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
21 changes: 21 additions & 0 deletions packages/skin-museum-client/src/algolia.js
Original file line number Diff line number Diff line change
@@ -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(
Expand Down
4 changes: 2 additions & 2 deletions packages/skin-museum-client/src/redux/epics.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit eb6b28b

Please sign in to comment.