firestore内で全文検索を実装するためのモジュール
- ネストしているフィールドのテキストを検索対象としては取ってこれない
- 現時点のバージョンではOR検索ができない
- スペースを挟んだキーワードを検索する場合はAND検索となる
const firestore = getFirestore(app);
import {
functionFactoryForWriteHook,
functionFactoryForSearchRequest,
} from "@codelic/searchforfirestorebyngram";
// onWriteでデータの追加されたタイミングで検索用のDBへ検索用のドキュメントを追加
export const createBinaryGrumDoc = functionFactoryForWriteHook(
firestore,
"users"
);
// 検索リクエストを投げる先のAPI
export const getSearchRequest = functionFactoryForSearchRequest(firestore);
検索をかけたい場合のリクエストの中身のタイプ情報
type query ={
collectionName: string; // 対象のコレクション名 例)User
targetFieldName: string; // 検索をかけたいフィールド名 例)name
searchWord: string; // 検索キーワード 例)山田
}
- firestoreドキュメントの最大情報量が1MBなので検索用のドキュメントが1MB超えるようであれば検索自体難しい