mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-03 04:25:24 +02:00
* feat: server side search API (#2112) * refactor repository_recipes filter building * add food filter to recipe repository page_all * fix query type annotations * working search * add tests and make sure title matches are ordered correctly * remove instruction matching again * fix formatting and small issues * fix another linting error * make search test no rely on actual words * fix failing postgres compiled query * revise incorrectly ordered migration * automatically extract latest migration version * test migration orderes * run type generators * new search function * wip: new search page * sortable field options * fix virtual scroll issue * fix search casing bug * finalize search filters/sorts * remove old composable * fix type errors --------- Co-authored-by: Sören <fleshgolem@gmx.net>
This commit is contained in:
parent
fc105dcebc
commit
71f8c1066a
36 changed files with 1057 additions and 822 deletions
|
@ -2,6 +2,5 @@ export { useFraction } from "./use-fraction";
|
|||
export { useRecipe } from "./use-recipe";
|
||||
export { useRecipes, recentRecipes, allRecipes, useLazyRecipes } from "./use-recipes";
|
||||
export { parseIngredientText } from "./use-recipe-ingredients";
|
||||
export { useRecipeSearch } from "./use-recipe-search";
|
||||
export { useTools } from "./use-recipe-tools";
|
||||
export { useRecipeMeta } from "./use-recipe-meta";
|
||||
|
|
|
@ -1,48 +0,0 @@
|
|||
import { computed, reactive, ref, Ref } from "@nuxtjs/composition-api";
|
||||
import Fuse from "fuse.js";
|
||||
import { Recipe } from "~/lib/api/types/recipe";
|
||||
|
||||
export const useRecipeSearch = (recipes: Ref<Recipe[] | null>) => {
|
||||
const localState = reactive({
|
||||
options: {
|
||||
ignoreLocation: true,
|
||||
shouldSort: true,
|
||||
threshold: 0.6,
|
||||
location: 0,
|
||||
distance: 100,
|
||||
findAllMatches: true,
|
||||
maxPatternLength: 32,
|
||||
minMatchCharLength: 2,
|
||||
ignoreFieldNorm: true,
|
||||
keys: [{ name: "name", weight: 1.3 }, { name: "description", weight: 1.2 }, "recipeIngredient.note", "recipeIngredient.food.name"],
|
||||
},
|
||||
});
|
||||
|
||||
const search = ref("");
|
||||
|
||||
const fuse = computed(() => {
|
||||
return new Fuse(recipes.value || [], localState.options);
|
||||
});
|
||||
|
||||
const fuzzyRecipes = computed(() => {
|
||||
if (search.value.trim() === "") {
|
||||
return recipes.value;
|
||||
}
|
||||
const result = fuse.value.search(search.value.trim());
|
||||
return result.map((x) => x.item);
|
||||
});
|
||||
|
||||
const results = computed(() => {
|
||||
if (!fuzzyRecipes.value) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (fuzzyRecipes.value.length > 0 && search.value.length != null && search.value.length >= 1) {
|
||||
return fuzzyRecipes.value;
|
||||
} else {
|
||||
return recipes.value;
|
||||
}
|
||||
});
|
||||
|
||||
return { results, search };
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue