How to perform sql “LIKE” operation on firebase?

前端 未结 5 1539
别那么骄傲
别那么骄傲 2020-11-22 04:16

I am using firebase for data storage. The data structure is like this:

products:{
   product1:{
      name:\"chocolate\",
   }
   product2:{
      name:\"cho         


        
5条回答
  •  眼角桃花
    2020-11-22 04:50

    The elastic search solution basically binds to add set del and offers a get by wich you can accomplish text searches. It then saves the contents in mongodb.

    While I love and reccomand elastic search for the maturity of the project, the same can be done without another server, using only the firebase database. That's what I mean: (https://github.com/metaschema/oxyzen)

    for the indexing part basically the function:

    1. JSON stringifies a document.
    2. removes all the property names and JSON to leave only the data (regex).
    3. removes all xml tags (therefore also html) and attributes (remember old guidance, "data should not be in xml attributes") to leave only the pure text if xml or html was present.
    4. removes all special chars and substitute with space (regex)
    5. substitutes all instances of multiple spaces with one space (regex)
    6. splits to spaces and cycles:
    7. for each word adds refs to the document in some index structure in your db tha basically contains childs named with words with childs named with an escaped version of "ref/inthedatabase/dockey"
    8. then inserts the document as a normal firebase application would do

    in the oxyzen implementation, subsequent updates of the document ACTUALLY reads the index and updates it, removing the words that don't match anymore, and adding the new ones.

    subsequent searches of words can directly find documents in the words child. multiple words searches are implemented using hits

提交回复
热议问题