Skip to content

Commit

Permalink
feat(nl-to-mquery): try use sift first
Browse files Browse the repository at this point in the history
  • Loading branch information
XuHaoJun committed Oct 4, 2024
1 parent 93ec759 commit 8fecaba
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
3 changes: 1 addition & 2 deletions src/app/[lang]/pokedex/OpenAISearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
import * as React from "react"
import { QueryKeys, useFetchPokemonMquery } from "@/api/query"
import { formatResponseError } from "@/utils/formatResponseError"
import { mysift as sift } from "@/utils/mysift"
import { msg, Trans } from "@lingui/macro"
import { useLingui } from "@lingui/react"
import { useQueryClient } from "@tanstack/react-query"
import { Edit, Search } from "lucide-react"
import * as R from "remeda"
// import sift from "sift"
import { filter as sift } from "uqry/full"

import { Button } from "@/components/ui/button"
import {
Expand Down
3 changes: 1 addition & 2 deletions src/app/[lang]/pokedex/PokedexPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { flexsearchAtom, flexsearchIsIndexingAtom } from "@/atoms"
import type { Pokemon2, PokemonType } from "@/domain/pokemon"
import { binaraySearch } from "@/utils/binarySearch"
import { getPokemonImageSrc } from "@/utils/getPokemonImageSrc"
import { mysift as sift } from "@/utils/mysift"
import { toPokemon2 } from "@/utils/toPokemon2"
import { Trans } from "@lingui/macro"
import { useLingui } from "@lingui/react"
Expand All @@ -15,8 +16,6 @@ import { ScopeProvider } from "jotai-scope"
import { ArrowDown, ArrowUp } from "lucide-react"
import { create } from "mutative"
import { LazyLoadImage } from "react-lazy-load-image-component"
// import sift from "sift"
import { filter as sift } from "uqry/full"

import { useDownloadJSON } from "@/hooks/useDownloadJSON"
import { useLoadPokemonLingui } from "@/hooks/useLoadPokemonLingui"
Expand Down
18 changes: 18 additions & 0 deletions src/utils/mysift.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import sift from "sift"
import { filter as uqry } from "uqry/full"

export function mysift(mongodbQuery: any) {
const hasExpr = (obj: any): boolean => {
if (obj?.hasOwnProperty("$expr")) return true
if (typeof obj !== "object") return false
for (const key of Object.keys(obj)) {
if (hasExpr(obj[key])) return true
}
return false
}
if (hasExpr(mongodbQuery)) {
return uqry(mongodbQuery)
} else {
return sift(mongodbQuery)
}
}

0 comments on commit 8fecaba

Please sign in to comment.