0

I'm building an Android app for a college project. It searches an SQLite database for recipes according to ingredients that the user specifies. I'm still at the beginning, and I've run into this problem. I'm storing ingredients as singular in the database. Each ingredient appears only once and I'm using a junction table to connect between recipes and ingredients (many-to-many), and this table also specifies the quantity and unit of measurement.

The problem is with the search itself. What if the user types the ingredients in plural form (which is the most likely case)? For example, if I have "tomato" as an ingredient and the user types "tomatoes", how can I make this work? Another thing, how can I list ingredients in singular or plural forms as needed when displaying recipes ("1 egg", "2 potatoes"... etc)? I'm starting to think that if I store separate ingredients for each recipe it might be easier, like "2 cups of milk" for one recipe and then once again "1 cup of milk" for another instead of simply "milk" and then specifying the quantity and UOM in separate columns, though it'd be less efficient, though in this case I won't be needing the junction table.

Sorry if this question is stupid. I haven't been able to find a solution for this, and thus I'm stuck at the beginning of my project and unable to progress further.

user3501779
  • 157
  • 1
  • 10
  • Matching singular against plural seems possible, since the singular is _usually_ a substring of the plural. But the other way around could be a real headache. – Tim Biegeleisen Sep 22 '16 at 15:08
  • Why not simply storing the ingredients as `potato/es`, `egg/s`, `cup/s` and so on? – Phantômaxx Sep 22 '16 at 15:08
  • 1
    Use full-text search with the [Porter stemming tokenizer](http://www.sqlite.org/fts3.html#tokenizer). – CL. Sep 22 '16 at 17:07
  • Thanks for the suggestions guys. I found a solution. I described it in my comment to Pynnie's answer. – user3501779 Sep 23 '16 at 22:13

0 Answers0