Firebase database strucutre

前端 未结 2 1276
面向向阳花
面向向阳花 2021-01-26 23:37

I\'m currently creating an e-commerce app for iOS and I\'m having trouble deciding on how to structure my database for the scenario of a user searching for an item by \"keywords

2条回答
  •  我在风中等你
    2021-01-27 00:09

    How about:

     items
          item0
            color: black
            type: t-shirt
            option: design
            keywords: black_t-shirt_design
          item1
            color: black
            type: hat
            option: design
            keywords: black_hat_design
    

    then a simple query using startingAt and endingAt.

    So for example, say the user is using a filter to narrow the results and wants to know about all of the black hats and doesn't care what the option parameter is:

    itemsRef.queryOrdered(byChild: "keywords")
            .queryStarting(atValue: "black_hat")
            .queryEnding(atValue: "black_hat")
    

    likewise if the user wanted to know about all of the clothing that's just black, you could query on the 'color' child for black.

    But if they wanted all of the black hats with the design option

    itemsRef.queryOrdered(byChild: "keywords")
            .queryStarting(atValue: "black_hat_design")
            .queryEnding(atValue: "black_hat_design")
    

提交回复
热议问题