Google Firestore: Query on substring of a property value (text search)

前端 未结 16 1649
抹茶落季
抹茶落季 2020-11-22 12:08

I am looking to add a simple search field, would like to use something like

collectionRef.where(\'name\', \'contains\', \'searchTerm\')

I tried

16条回答
  •  再見小時候
    2020-11-22 12:35

    I agree with @Kuba's answer, But still, it needs to add a small change to work perfectly for search by prefix. here what worked for me

    For searching records starting with name queryText

    collectionRef.where('name', '>=', queryText).where('name', '<=', queryText+ '\uf8ff').

    The character \uf8ff used in the query is a very high code point in the Unicode range (it is a Private Usage Area [PUA] code). Because it is after most regular characters in Unicode, the query matches all values that start with queryText.

提交回复
热议问题