1

I have about 300 records stored in FireBase.

The structure of each record looks something like:

unique ID/key (e.g. -K1vsg7F4V_5usvPejZV)
 - city
 - firstName
 - lastName
 - image (encoded as base64)

With the images especially, a current export is 15Mb.

So everytime I want to do search for, say a first name, I need to download 15Mb and then do a search on that data in the browser. It's incredibly bandwidth heavy and slow to use this way.

I've been reading up online that content searches is coming? But I don't see it yet?

Thoughts? Or have I missed something obvious?

shareef
  • 9,255
  • 13
  • 58
  • 89
magician11
  • 4,234
  • 6
  • 24
  • 39

1 Answers1

2

Why download data and do another search? Just query for the firstName you are interested in.

ref.orderByChild("firstName").equalTo("Kato")

Another super simple option is to store your images in another node using the same key.

images
  unique ID/key
      image:
  unique ID/key
      image:

Then you only load in the image you need when it's needed and won't affect your other data.

Jay
  • 34,438
  • 18
  • 52
  • 81
  • Thanks Jay. A couple of questions: 1) if I call orderByChild and then equalTo will that only download the records that message that firstName value? 2) What I'll be needing though is partial matching e.g. searching for "Kat" should also return "Kato". I don't think we can do that with Firebase? – magician11 Nov 20 '15 at 00:59
  • Storing images in a different place seems like a good idea. I have a directory of people to display.. so will probably need to implement some sort of lazy loading solution that grabs the images as people scroll. – magician11 Nov 20 '15 at 01:01
  • 1
    To answer the questions 1) Yes. 2) Check .startAt and .endAt in the docs. Look down in the Range Queries section on this page [Retrieving Data](https://www.firebase.com/docs/web/guide/retrieving-data.html) – Jay Nov 20 '15 at 14:02
  • the combination of `.startAt(searchVal).endAt(searchVal + "\uf8ff").on("value", function(snapshot) {` worked. – magician11 Nov 23 '15 at 04:49
  • any idea how I would modify this to do a case insensitive search? – magician11 Dec 12 '15 at 12:02
  • That's going to take some extra work; how much depends on how case-insensitive you need it. A simple way is to store two versions of your data within the node; one all lower case (firstNameForQueries: "kato") and then another firstNameForDisplay: "Kato". Another would be using a delimiter to separate the search and display (firstName: "kato_Kato") and use startAt() and endAt() to grab "kato". – Jay Dec 12 '15 at 13:44