Prev | Current Page 217 | Next

Rob Allen, Nick Lo, and Steven Brown

"Zend Framework in Action"

3.
Listing 8.3: Adding to the index
$index = Zend_Search_Lucene::open($path); A
$doc = new Places_Search_Lucene_Document( B
$class, $key, $title, $contents, B
$summary, $createdBy, $dateCreated); B
$index->addDocument($doc); C
A Open the index
B Create the document in one line of code
C Add to the index
That??™s all there is to it! We now need to write this code within each model class that is to be searched over.
and we immediately hit a design brick wall. The model clearly knows all about the data to be searched,
however it should not be know about how to add that data to the search index. If it did, it would be tightly
coupled to the search system which would make our lives much harder if we ever want to change the search
engine to another one. Fortunately, programmers before us have had the same basic problem that we have and
it turns out that it??™s so common that there??™s a design pattern named after the solution: the Observer pattern.
Licensed to Menshu You
Please post comments or corrections to the Author Online forum at
http://www.manning-sandbox.com/forum.jspa?forumID=329
Using the Observer Pattern to decouple indexing from the model
The Observer pattern describes a solution that uses the concept of notifications.


Pages:
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229
FIAT BRAVO Diety uwodzenie poker online alufelgi