2012年1月16日月曜日

Google App Engine で動く全文検索ライブラリのデモをアップしました

以前の記事で紹介したGoogle App Engine で動く全文検索ライブラリのデモをアップしました。
http://beryl-demo.appspot.com/search/
できることはコメントの登録とそれに対する検索、インデックスの閲覧となります。
ちなみに、カテゴリーは指定した場合、完全一致による検索、
通常の検索条件はテキストとタイトルに対する全文検索を行います。
また、全文検索の方はAND OR NOT の演算子と括弧()による評価順の指定ができます。

デモサイトの使用は常識的な範囲で使用してもらって大丈夫です。
むしろコメントはデータ収集のためにじゃんじゃか登録して欲しいくらい。
課金はしていないので、オーバークォータになったらゴメンナサイ。

近いうちに解説の文書をアップロードする予定です。

ちなみに、転置インデックスを作成する際のソースコードは次のような感じ。
protected void commentIndexUpdate(Long id, boolean isDeleteOnly) {
    // 保存先ディレクトリとアナライザの取得
    Directory directory = DatastoreDirectory.getInstance();
    Analyzer analyzer = GomokuAnalyzer.getInstance();
    IndexReader reader = new IndexReader(directory);
    IndexWriter writer = new IndexWriter(directory, analyzer);

    // インデックスに登録する情報を取得
    Key key = Datastore.createKey(CommentModel.class, id);

    // 既存のインデックス情報を削除
    List oldDocumentKeys = reader.getDocumentIds(key);
    for (long oldDocumentKey : oldDocumentKeys) {
        writer.deleteDocument(oldDocumentKey);
    }

    // ドキュメント生成・登録
    if (!isDeleteOnly) {
        CommentModel comment = Datastore.get(CommentModel.class, key);
        DocumentModel document = new DocumentModel();
        document.setOriginalKey(comment.getKey());
        Field keyField = new Field(
                "key", id.toString(), Store.YES, Index.NO);
        Field titletField = new Field(
                "title", comment.getTitle(), 
                Store.YES, Index.TOKENIZED);
        Field readingtField = new Field(
                "category", comment.getCategory(), 
                Store.YES, Index.UN_TOKENIZED);
        Field textField = new Field(
                "text", comment.getText(), Store.NO, Index.TOKENIZED);
        document.add(keyField, titletField, readingtField, textField);
        writer.addDocument(document);
    }
}

0 件のコメント:

コメントを投稿