views:

156

answers:

1

I'm currently indexing a database with lucene. I was thinking of storing the table id in the index, but I can't find a way to retrieve the documents by that field. I guess some pseudo-code will further clarify the question:

document.add("_id", 7, Field.Index.UN_TOKENIZED, Field.Store.YES);
// How can I query the document with _id=7
// without getting the document with _id=17 or _id=71?
+1  A: 

EDIT for Zend Lucene: You will need a Keyword type field in order for it to be searched. For indexing, use something like:

$doc->addField(Zend_Search_Lucene_Field::Keyword('_id', '7'));

For search, use:

$idTerm  = new Zend_Search_Lucene_Index_Term('_id', '7');
$idQuery = new Zend_Search_Lucene_Search_Query_Term($idTerm);
Yuval F