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(newZend_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

Reply via email to