Hello,
Can't see anything obviously wrong with it, but I have one idea which
might make some tiny difference...
Personally in my own scripts where I do a delete, in the foreach loop, I
don't pull anything fancy out from each $hit instance, I simply
reference $hit->id for the internal document - every document in a
Lucene index will have its internal ID, which is what you really need to
be establishing in the foreach loop, so you can then apply the delete
method using that ID - try switching to $hit->id instead of referencing
getDocument and see what results you get. You should at least get an id
of some kind (bearing in mind that 0 as an id is valid)
To be honest, I'm not sure what the getDocument() method is actually
doing, as I can't find it readily documented anywhere; the core code I
had came directly from the manual.
Sorry I can't be more help,
Pete
Josh Team wrote:
Okay, so I have a Search class. And it looks really simple,
Search::addDocument( $doc )
Search::find( $query )
Search::deleteAll()
Search::deleteDocumentByField( $field, $value )
Everything works fine, I can add my custom document objects, find,
delete all.. except for ::deleteDocumentByField(). So, without getting
too detailed here is how I am trying to get it to work:
My custom document object is simply Search_Document, which takes a
Doctrine_Record and builds it's self ( fields ) based off the data
types and properties. Nothing fancy, but if it would help here is the
class: http://www.hashbin.com/5nl
It works fine, the only important thing is that their is a constant:
Search_Document::SEARCH_IDENTIFIER which holds the string of the UID
to identify documents with later. Right now it builds this off of
modelname.uniqueid. This works fine, right now it's suid and when I
add a record (foo) I get foo.1 as the suid.
I found on the mailing list a code snippet on how to find records on a
uid and delete them and that is pretty much my deleteDocumentByField:
public function deleteDocumentByField( $field, $value ) {
$query = new Zend_Search_Lucene_Search_Query_Term(new
Zend_Search_Lucene_Index_Term($value, $field));
$hits = $this->_index->find($query);
$identifier = Search_Document::SEARCH_IDENTIFIER;
foreach($hits as $hit) {
Zend_Debug::dump($hit->getDocument()->$identifier);
die();
}
}
and if I call:
$searcher->deleteDocumentByField(Search_Document::SEARCH_IDENTIFIER,
'foo.1');
It doesn't match anything. If anyone has any guidance I would be most
appreciative, I will post all 3 classes here if anyone does have the
ability to give guidance or also uses Doctrine and wants to utilize
this method. ( I have a Doctrine_Listener which on postInsert adds the
record, postUpdate deletes the record and re adds it, and postDelete
deletes the record. The postInsert is working, but postUpdate doesn't
delete currently so everything you save the object you get another
instance of the document in lucene. haha. Anyways thanks guys
1. Search.php <http://www.hashbin.com/5no>
2. Search/Document.php <http://www.hashbin.com/5np>
3. Search/Doctrine/Listener.php <http://www.hashbin.com/5nq>
Thanks,
Josh Team