0
我想在不使用第三方的情況下實現搜索。我目前的想法是將不同的字符串長度存儲爲鍵,以便快速索引。我會實現至少3個字符串長度,並確保搜索的字符串是小寫字母。例如在火力數據會是這個樣子:索引字符串以方便搜索
{
users: {
matUserId: {
name: 'Mathew'
}
},
search: {
mat: {
users: { matUserId: true }
},
ath: {
users: { matUserId: true }
},
the: {
users: { matUserId: true }
},
hew: {
users: { matUserId: true }
},
math: {
users: { matUserId: true }
},
athe: {
users: { matUserId: true }
},
thew: {
users: { matUserId: true }
},
mathe: {
users: { matUserId: true }
},
athew: {
users: { matUserId: true }
},
mathew: {
users: { matUserId: true }
},
}
}
我將它擴展的,所以如果有可以搜索他們將共享相同的搜索關鍵字其他的事情。我相信這會起作用並且速度很快(我有一個基本的實現來檢查它),但是想知道這是否是正確的搜索方式或者是否完全離開了基礎。舉例來說,如果我要搜索「hew」這個詞,它只會降低「hew」的子節點,然後我可以獲取用戶並顯示它們。
正確的搜索方式取決於您的用例。但是,之前已經回答過:Firebase實時數據庫不是全文搜索引擎。雖然可以模擬一些FTS技術,但它很少是一個完美的選擇。如果您想搜索文本,最好使用專用搜索引擎,例如通過我們的手電筒集成。 –
一如既往地感謝弗蘭克的迴應。有沒有可用的工具,不需要我運行一個單獨的服務器?在我上面的建議中是否還有任何問題(除了有大量數據)?我不介意它處理非常特定類型的基本字符串搜索。 –
這樣的推薦是堆棧溢出的話題,但我在Algolia看到了很好的結果。 –