Zend
and the art of search
Dave Dash
Spindrop LLC
Minneapolis USA
* I’m a symfony evangelist for any who’ll listen
* I write articles and how-tos on spindrop.us
* I’m the lead developer for reviewsby.us
* I’ve worked on a number of symfony sites, many which boast search powered by Zend
you at yo eat y peat ep
urs ours your
rse
don lf. do elf. d elf. s
on’ don’
’t re n’t
rep pea repe t rep t
you eat yo t y at y eat
our
rse urs our
don lf. do elf. d self. self
D RY
on’ don’ .
’t re n’t
rep
eat peat repea t rep t rep
you you t yo eat y
you
rse
lf. d rself. rself urse ou
don don . don lf. do
’t re on’t
rep
eat peat repea ’t rep ’t rep n
you you t yo eat y eat
you
rse
lf. d rself. rself urse ours
don don . don lf. do el
’t re on’t
rep pea repe ’t rep ’t re n’t r
you eat yo t y eat peat e
at y
urs ours
rse our you you
lf. d elf. elf.
don self
don don . do rself.
on’
rep ’t rep t re do
’t re ’t r n’t
eat pea
eat pea epea repe
you t yo
you t yo t yo at
rse urs
rse
lf. d elf. ursel urse
lf. d
you on’ lf
don f. d
on’
rse t re ’t re on’t
t re
lf. d pea pea pea r
on’
t re t you t you t yo
*
The core symfony framework can do quite a lot
pea rsel u
rse
*
The greatest strength of symfony is it’s ability to extend beyond the core
*
Plugins
t yo f. do lf. do
*
PEAR libraries
*
other frameworks?
urs n’t
*
In symfony (and other frameworks) we embrace the idea of DRY: Don’t Repeat Yourself
elf. rep
*
Not just in our applications, or the framework itself, but open source PHP in general
e
*
If there’s good code available, don’t re-invent the wheel.
bridge = simple
*
Even without help, Zend and ezComponents are easy to use within symfony
*
But why not build a bridge
*
The Bridge is simple, it allows us to call classes from Zend or other frameworks and autoload them
*
That’s it
lucene
*
We’re going to specifically look at Zend Search Lucene
*
Great way to quickly add a powerful search engine to your web app
*
Apache Lucene is a feature-rich, but easy to use search engine library written in Java
*
Ported to C, Ruby and of course PHP
*
The ports generally use binary compatible libraries, meaning we can write one part of the search in Java and another part in PHP if necessary
*
PHP isn’t always the best language for heavy server-side lifting, so we can pull out resource-intensive processes that are unbecoming of a PHP script and use Java to take care of
them. We’ll touch on that later
search = 3 things
*
We’ve got a bridge, we’ve got a php library, search is a snap, so let’s talk about adding it to our applications
*
There’s three or four things we do with a search engine
*
Index records
*
Delete records
*
Query records
*
We do update, but at least with Lucene that involves deleting and indexing
*
If you’ve seen the tutorials I have online they are written in a propel-specific manner, this is by no means a requirement, we can very easily use Doctrine or
any type of object we want to index
*
If we have time, which we might, I’ll show a demo with the code in action if people would like
*
Since our primary task is searching or querying records we’ll start there
*
In either our Peer or Table class for our object which we have indexed we’ll want a query method.
*
This method loads the search index and uses the Zend Search Lucene library to query
*
All these queries will be useless without a built up index
*
In our object’s class we override the save method and have it delete all the old records of the object in the index (if any) and create a new one from
scratch using the Zend API
*
We store the fields we’d want to search on in the index
*
Finally we need to override our delete method for our object and make sure it removes its records in the search index upon deletion