2

First of all excuse me for my very bad English...

I'm a very very new developer and I'm confusing so much with search operation. Actually I want to make a food and cooking app (with a lot of recipes and so on), and I want to add a search action to it, so the user could put multiple things (such as Ingredients) and the app show him the foods that have these things in their Ingredients.

Now I have two question.

First, how can I add tags to my "recipe activities" so when the ingredient typed app knows which recipes should showes? (My recipes are not in textview, they are all in imageviews).

Second, how can I completely separate the search keywords with ","? for finding the right recipes. (example: type "tomato", "chicken", "egg" and the app shows him/her the recipes that have these things in their Ingredients.)

I know you that now you are laughing so much for my gramer :), so after you laughted enough please answer my questions. Thank You SOOOOOOOOO MUUUUUUUUUCH.

SaDeGH_F
  • 471
  • 1
  • 3
  • 14

1 Answers1

1
  1. You can use something like a map for every Recipe's ingredients a-la:

    class Recipe
    -name:String
    -ingredients:Map < String, Quantity > or Set < String >

where Quantity represents all that nasty features used in culinary like spoons, cups, pinches. Then you can search through keys of every recipe's ingredients. Name would be a tag you've mentioned.

  1. You can read search string, parse it (e.g. into array with regular expression) and put into Set to avoid duplicates.
Margarita Litkevych
  • 2,086
  • 20
  • 28
  • thanks for your answer. can you explain the "map" thing more? or if you could just give me the right resource it would be great. – SaDeGH_F Nov 01 '13 at 10:33
  • http://docs.oracle.com/javase/tutorial/collections/interfaces/map.html map is just a pair. keys are not duplicated, values can be duplicated, one null-key is allowed that's sometimes used for default values (e.g. http://stackoverflow.com/questions/2945309/hashmap-null-key) – Margarita Litkevych Nov 01 '13 at 10:54
  • as for Map: e.g. we have a recipe of a salad YouNameIt with 2 tomatos, 100g cheese and bunch of arugula leaves. quantity is here described as pieces (vegetables) and weight. Then your Quantity can be an abstract class with realization for each type of measurement (see sth about patterns. maybe factory?) but easier (and more reasonable :) ) would be to use just a string especially if your recipes are images. So in this case it would be sth like this: ingredients:["tomato"="2", "cheese"="100g", "arugula leaves"="bunch"]. – Margarita Litkevych Nov 01 '13 at 11:08
  • Although something is not very clear with bunches and pinches (e.g. salt) so it may be even easier to use Set. that would be: ingredients:["tomato", "cheese", "arugula"]. Using Set will prevent your of duplicates in the recipe. If you want to keep them (for example in some cakes amount of sugar and eggs are given separately for dough and cream), try to use simple List :) http://docs.oracle.com/javase/tutorial/collections/interfaces/set.html – Margarita Litkevych Nov 01 '13 at 11:09