0

I have 14 attributes in facedetails I want to query on and find the closest match for each, and only if the 14 attributes match person face My code will return the person object. Here is a sample on the database:

"faceDetails":{
    "mCalculateFaceSizeHeight" : 121,
    "mCalculateFaceSizeWidth" : 107,
    "mCalculateLeftEyeBrowSizeHeight" : 31,
    "mCalculateLeftEyeBrowSizeWidth" : 43,
    "mCalculateLeftEyeSizeHeight" : 64,
    "mCalculateLeftEyeSizeWidth" : 10,
    "mCalculateMouthSizeHeight" : 24,
    "mCalculateMouthSizeWidth" : 30,
    "mCalculateNoseSizeHeight" : 43,
    "mCalculateNoseSizeWidth" : 71,
    "mCalculateRightEyeBrowSizeHeight" : 43,
    "mCalculateRightEyeBrowSizeWidth" : 52,
    "mCalculateRightEyeSizeWidth" : 14,
    "mCalculatedRightEyeSizeHeight" : 36
            }

Currently in the Android device I have something like this.

Query personLeftEyeSizeWidthQueryendAt = myRef.orderByChild("mCalculateLeftEyeSizeWidth")
                .endAt(mCalculateLeftEyeSizeWidth())
                .limitToLast(1);
        personLeftEyeSizeWidthQuery.addChildEventListener(new ChildEventListener() {....

Query personLeftEyeSizeWidthQueryStartAt = myRef.orderByChild("mCalculateLeftEyeSizeWidth")
                    .startAt(mCalculateLeftEyeSizeWidth())
                    .limitToFirst(1);
            personLeftEyeSizeWidthQuery.addChildEventListener(new ChildEventListener() {....


My index is like this:
".indexOn": [
        "mCalculateLeftEyeSizeWidth",
        "mCalculateLeftEyeSizeHeight",
        "mCalculateRightEyeSizeWidth",
        "mCalculatedRightEyeSizeHeight",
        "mCalculateNoseSizeWidth",
        "mCalculateNoseSizeHeight",
        "mCalculateMouthSizeWidth",
        "mCalculateMouthSizeHeight",
        "mCalculateLeftEyeBrowSizeWidth",
        "mCalculateLeftEyeBrowSizeHeight",
        "mCalculateRightEyeBrowSizeWidth",
        "mCalculateRightEyeBrowSizeHeight",
        "mCalculateFaceSizeWidth",
        "mCalculateFaceSizeHeight"

      ]

My question is do I move forward with 28 single queries each one single query or there is better way to combine all 28. I do not want to give up on some of them as face recognition accuracy is very important for finding a match. Let me know if should I continue with 28 single query then check the key of each one to see that they are all matching the same person or maybe another method.

Thanks Eran Gross

  • Check my answer on this question https://stackoverflow.com/questions/46156902/make-firebaserecycleradapter-get-data-under-conditions-and-not-all-of-them/46384299#46384299 – gtzinos Sep 23 '17 at 21:21

1 Answers1

2

Current Firebase Database API does not provide exact way for combining queries.
However, in the video person from Firebase tells how to structure your database to relieve the burden.
I suggest, instead of seperating leftEyeHeight and leftEyeWidth you can merge them up by simply leftEyeSize whose value could be written as (leftEyeHeight, leftEyeWidth) This will halve your problem even if you write each query manualy

Ziya ERKOC
  • 839
  • 7
  • 18
  • Not sure it will work merge two values. The DB understand number int string that is why I divided it to begin with so .startAt(mCalculateLeftEyeSizeWidth()) return int and search that value. if you combine the values to point(widht,height) so for example mCalculateLeftEyeSize() = (14,20) then the DB will not be able to search on. .startAt(mCalculateLeftEyeSize()) = > this will not work. I did not try that on Firebase but already tested few DB, they do not understand point values ... –  Jul 13 '17 at 08:52
  • Did you look at this discussion https://stackoverflow.com/questions/26700924/query-based-on-multiple-where-clauses-in-firebase?rq=1 – Ziya ERKOC Jul 13 '17 at 08:56
  • I am looking at the source code. Query.class = > .startAt and .endAt boolean String Double –  Jul 13 '17 at 08:59
  • Yes I saw that already, in the example they are combining multiple string. then search on root string... The Firebase recommended flat Database as possible . Eventually I need the number value to run the query . I do not want to combine the actual value like like eyeSize = width * height return eyeSize –  Jul 13 '17 at 09:04
  • I hope they will release an update which they provide a better Query class – Ziya ERKOC Jul 13 '17 at 09:11