List Info

Thread: Zend Lucene Search - find() best Practices?




Zend Lucene Search - find() best Practices?
user name
2008-01-21 07:19:37
I have built an index on a database that users can search
on.  Everything is
very basic about what it does.  I am currently doing nothing
special with
the input from the user, before applying calling find.

ex;
$query = $_GET['query'];
$hits = $index->find($query);

This works most of the time, but throws exceptions if you
include characters
such as * or ?.  It will also throw an exception if you end
the query with a
word like "and" or "or".  

Other than looking for exceptions and alerting the user to
issues with the
query, what would be considered best practices in regards to
manipulating
the query to search for exactly what the user entered (while
still using
find and not the search API)?  What I mean by that is, could
I remove
special characters from the query (*, ?, etc.)?  Should I
remove the word
"and" or "or" if the query ends with
that word?  What about the word "to"? 
If I search for "back to back" it will throw an
exception also.


-- 
View this message in context: http://www.n
abble.com/Zend-Lucene-Search---find%28%29-best-Practices--tp
14997184s16154p14997184.html
Sent from the Zend Framework mailing list archive at
Nabble.com.


Re: Zend Lucene Search - find() best Practices?
user name
2008-01-21 07:30:32
When you use the $index->find() method with a string,
special characters
such as "*", "?" and keywords such as
"and" are parsed as part of the
Lucene query language. As such, misplacing them will cause
an exception.

What you probably want to do is to take the input and treat
it as a
literal string, and use the query API (see docs) to build a
query object
out of it.

Good luck,

Shahar.


On Mon, 2008-01-21 at 05:19 -0800, boopfm523 wrote:
> 
> $query = $_GET['query'];
> $hits = $index->find($query);

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )