How can i search in firebase by different fields?

OK, two things going on.

  1. The positioning of the rules
  • You should not need to write a rule for every key in the node recambois. Just as I have shown.
  1. The double quotes around the values
  • If you use the experiemental firebase component to add records to your database, this will add a set of double quotes. Use the web component to add records.
  • or if using the experiemental firebase component, add double quotes as another set to the textbox.text ?

Thanks for the explanation,

if I use firebase component in App inventor, knowing that it uses double quotes, there is no problem .

For my part, I close the query by thanking you again for your help.

after getting it to search by " compatible " thanks to your indications, now I find a new problem, when there are two or more words it is not able to search, not even if you put both words... is there a solution or is it not possible to do that in firebase?

thanks in advanced

It is not really possible to carry out wildcard / partial string searches in firebase. There are some hacks, but I do not believe any of the ones I have seen will handle your requirement. To do it, you will need to restructure your data, I have a couple of ideas, but will have to carry out some testing....

many thanks Timai2

I still think that if the amount of data you are going to handle is not very large, it would be better to recover it all and do the searches then. Everything would be much simpler

It is possible, but you would need to structure your data differently. You would need another "node" that listed each compatible item and its PN item as a sub-node e.g

    Compatible: ["ABC123","ABD123","ABE123"]
    Description: "3TB HDD"
    PN: "123ABC"

   Description: "3TB HDD"
   Description: "3TB HDD"
   Description: "3TB HDD"

In this way you can query the recambios table for descriptions, and compatibles for...compatibles

It does appear heavy handed and a duplication. Firebase call this de-normalising, and generally recommend this approach to make it possible to access and query subsets of data.

It would not take much to create this second structure when new records are added.

The fun would start when you have more than one part number that is compatible with a compatible!!

1 Like

I have thought of the following, which might be easier to do, I have created two compatible ones
compatible and compatible1 creating a new structure, but I do not know how to make it search and find me in compatible or compatible1.
with the blocks that I have that you made me, I can only do it with & and I have to have the two search fields filled, I do not know how to do the search "or".



Could you help me ?

sorry ,

block diagram

You cannot do OR queries in firebase (realtime database)

You would have to do a query for compatible, then another for compatible1....


Do I need 2 search buttons or 2 web components or do I have to do some conditional in the blocks?

Thanks in advanced

Before we go there, what will you do if you have 4, or 5, or more compatibles ?

I have reduced it to 2, it already works for me with that amount,

When I have more time, I'll try to modify the firebase structure as I see fit.

To answer this, it depends on what you want to happen. If you run the first compatible check, if you get a result, do you then run the second anyway? How many results do you want returned, just the one ?

I need you to show me what is in compatible and compatible1 in case you have data, starting to search for compatible
For example, if I put 22222 it also shows me compatible1 and if I put 3333 it also shows me compatible

Probably something like this?



A little logical data modelling here...

If A is compatible with B, and
B is compatible with C,
is A always compatible with C?

If that were the case, having B and C point back to A for compatibility would change the data structure to eliminate lists at the part level.

If you need a replacement for B, check what B is compatible with (A),
then search for all parts that are compatible with A (A,B,C)

Forgive me if I missed problems with this approach earlier in this long thread.

I believe I handled this, in Firebase (the Firebase way) here:

but the OP has not chosen that route

perfect, it works as I wanted it to, thank you very much for your help.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.