インデックスの構築 | Lucene PHP

http://framework.zend.com/manual/ja/zend.search.lucene.overview.html

Zend_Search_Lucene_Field の型
フィールド型	保存	インデックス化	トークン化	バイナリ
Keyword	Yes	Yes	No	No
UnIndexed	Yes	No	No	No
Binary	Yes	No	No	Yes
Text	Yes	Yes	Yes	No
UnStored	No	Yes	Yes	No

使い方によって保存方法を選べますね。自分の場合は、検索だけでデータは、別に保存するので検索して独自のIDだけ取得出来れば大丈夫なので。

$indexFile = '/tmp/myIndex';
$index = null;
if( !is_dir($indexFile) ){
  $index = Zend_Search_Lucene::create($indexFile);
}else{
  $index = Zend_Search_Lucene::open($indexFile);
}

// add to index
$doc = new Zend_Search_Lucene_Document();
// for datastore key
$doc->addField(Zend_Search_Lucene_Field::UnIndexed('myid','abcd1235467890'));
// search index
$doc->addField(Zend_Search_Lucene_Field::UnStored('contents','逆境無頼カイジ 破戒録篇','utf-8'));
// add index
$index->addDocument($doc);

$doc2 = new Zend_Search_Lucene_Document();
$doc2->addField(Zend_Search_Lucene_Field::UnIndexed('myid','xyzd1235467890'));
$doc2->addField(Zend_Search_Lucene_Field::UnStored('contents','Nayutawave Recordsよりリリースする少女時代の公式ペ>ージ。リリース情報やニュース、視聴・試聴コンテンツをご覧いただけます。','utf-8'));
$index->addDocument($doc2);

// たまに最適化
$index->optimize();

これを実行すると以下のようなファイルが生成されます。

$ tree -L 3 /tmp/myIndex
/tmp/myIndex/
|-- _1.cfs
|-- _1.sti
|-- optimization.lock.file
|-- read-lock-processing.lock.file
|-- read.lock.file
|-- segments.gen
|-- segments_d
`-- write.lock.file

This entry was posted on 水曜日, 5月 11th, 2011 at 6:15 PM and is filed under Lucene, php. You can follow any responses to this entry through the RSS 2.0 feed. Both comments and pings are currently closed.

Unityによるゲームを公開しております iOS/Android
https://itunes.apple.com/jp/app/lost-knight-3d-action/id900917032
https://play.google.com/store/apps/details?id=com.groundroad.runknight

各種開発支援・機能開発等小さいお仕事などもお請けしております。
unity開発支援, PHPシステム開発, javascript/html5 フロント開発, titanium mobileアプリ開発
お気軽にお問い合わせください
大崎・五反田近郊での対面でのお打ち合わせはいつでも可能です。