It takes care of unaccenting the term and looking for a full-text match against the view's document column, as well as running an alternative ILIKE search on the title for substring matches. The macro, matching_recipe_ids_and_ranks/1, builds a subquery to search the recipe_search view for matching recipes and return their recipe ids and ranks. The run/2 function normalizes the search string (which involves typical things like discarding extra white space, as well as domain-specific things like treating "gluten free" as "gluten-free"), then joins the subquery. In other words, the full-text search function takes a %Ecto.Query/, " " ) |> String. Honoring user preferences meant, in our context, performing the full-text search as a chainable Ecto query, so that other query conditions like "must be vegetarian" could also be applied. For this post, I'll assume you know the relevant PostgreSQL functions. It's a fantastic post, both as a tutorial and a reference. If you don't already understand functions like to_tsvector, you should really read Postgres full-text search is Good Enough!. But we were already using PostgreSQL as our primary data store, and its full-text search capabilities were enough for this task, which kept us from having to add another dependency. Substring matches were easy: a simple ILIKE query on recipe titles would do.Īccent-agnostic, pluralization-agnostic, multi-table search ( recipes + tags) was slightly harder, and we discussed using something like Solr. A performance hit when adding or updating recipes was OK, as this was done infrequently, and always by staff. Everybody likes speed, but it was especially important here for the "search after every keystroke" use case. For example, a vegetarian user searching for "burger" should have meaty results filtered out, leaving only matches like "Vegan Black Bean Burgers". For example, when searching for "strawberry", a recipe with "strawberry" in the title should be shown before a recipe that's merely tagged "strawberries" because that's one of its ingredients. For example, searches for "gluten-free" should return recipes tagged as gluten free, whether or not the recipe title includes those words. For example, a search for "sauté" vs "saute" should return the same results. For example, searches for "strawberries" and "strawberry" should return the same results. It would be confusing if typing "bu" filtered out everything, but continuing to type "butternut" made some recipes reappear. This was because search could be used globally, or to filter a user's saved recipes as they typed a search term. For example, "bu" should find recipes like "Vegan Butternut Squash Soup". This search feature replaced a simpler one, and needed to: I thought this was interesting enough to write up (with Mealthy's permission). You can try it out there, or check out this quick demo video. ![]() ![]() I recently built a full-text recipe search feature using Ecto and PostgreSQL for. Elixir ecto postgresql Posted on: January 8, 2018
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |