From 5a2c708d055d63dd7e07456b9b03d320224363c3 Mon Sep 17 00:00:00 2001 From: Jacob Corn Date: Sun, 14 May 2023 06:02:56 +0200 Subject: [PATCH] address comments --- docs/docs/documentation/getting-started/faq.md | 7 +++++++ mealie/db/models/recipe/ingredient.py | 3 ++- mealie/repos/repository_recipes.py | 5 ++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/docs/docs/documentation/getting-started/faq.md b/docs/docs/documentation/getting-started/faq.md index 0a34463251f..ab3fb348894 100644 --- a/docs/docs/documentation/getting-started/faq.md +++ b/docs/docs/documentation/getting-started/faq.md @@ -41,6 +41,13 @@ Yes, you can install Mealie on your local machine. HOWEVER, it is recommended th - [Advanced Installation](./installation/advanced/) +## What is fuzzy search and how do I use it? +Mealie can use fuzzy search, which is robust to minor typos. For example, searching for "brocolli" will still find your recipe for "broccoli soup". But fuzzy search is only functional on a Postgres database backend. To enable fuzzy search you will need to migrate to Postgres: + +1. Backup your database and download the .zip file (same as when [migrating](./migrating-to-mealie-v1.md)) +2. Set up a [Postgres](./installation/postgres.md) instance of Mealie +3. Upload the backup .zip and click to apply it (as as migration) + ## How i can attach an image or video to a Recipe? Yes. Mealie's Recipe Steps and other fields support the markdown syntax and therefor supports images and videos. To attach an image to the recipe, you can upload it as an asset and use the provided copy button to generate the html image tag required to render the image. For videos, Mealie provides no way to host videos. You'll need to host your videos with another provider and embed them in your recipe. Generally, the video provider will provide a link to the video and the html tag required to render the video. For example, youtube provides the following link that works inside a step. You can adjust the width and height attributes as necessary to ensure a fit. diff --git a/mealie/db/models/recipe/ingredient.py b/mealie/db/models/recipe/ingredient.py index 6fc89754b78..8813603b2d4 100644 --- a/mealie/db/models/recipe/ingredient.py +++ b/mealie/db/models/recipe/ingredient.py @@ -3,6 +3,7 @@ import sqlalchemy as sa from sqlalchemy import Boolean, Float, ForeignKey, Integer, String, event, orm from sqlalchemy.orm import Mapped, mapped_column +from sqlalchemy.orm.session import Session from text_unidecode import unidecode from mealie.db.models._model_base import BaseMixins, SqlAlchemyBase @@ -88,7 +89,7 @@ class RecipeIngredientModel(SqlAlchemyBase, BaseMixins): original_text_normalized: Mapped[str | None] = mapped_column(String, index=True) @auto_init() - def __init__(self, session, note: str | None = None, orginal_text: str | None = None, **_) -> None: + def __init__(self, session: Session, note: str | None = None, orginal_text: str | None = None, **_) -> None: # SQLAlchemy events do not seem to register things that are set during auto_init if note is not None: self.note_normalized = unidecode(note).lower().strip() diff --git a/mealie/repos/repository_recipes.py b/mealie/repos/repository_recipes.py index deb6bf9d003..a782daf4713 100644 --- a/mealie/repos/repository_recipes.py +++ b/mealie/repos/repository_recipes.py @@ -168,13 +168,12 @@ def _add_search_to_query(self, query: Select, search: str) -> Select: # keep quoted phrases together as literal portions of the search string literal = False quoted_regex = re.compile(r"""(["'])(?:(?=(\\?))\2.)*?\1""") # thank you stack exchange! + removequotes_regex = re.compile(r"""['"](.*)['"]""") if quoted_regex.search(normalized_search): literal = True temp = normalized_search quoted_search_list = [match.group() for match in quoted_regex.finditer(temp)] # all quoted strings - quoted_search_list = [ - re.sub(r"""['"](.*)['"]""", "\\1", x) for x in quoted_search_list - ] # remove outer quotes + quoted_search_list = [removequotes_regex.sub("\\1", x) for x in quoted_search_list] # remove outer quotes temp = quoted_regex.sub("", temp) # remove all quoted strings, leaving just non-quoted temp = temp.translate( str.maketrans(punctuation, " " * len(punctuation))