Zend Lucene does not search with special characters

if anyone knows a simple answer to this question, I don't have to wade through creating an extra index with escaped strings and cry with my eyes clogging up my beautiful code.

Basically, the Lucene search that we have is unable to handle any letters other than letters. Space, percent signs, periods, dashes, forward slashes, you name it. This is extremely infuriating because I cannot search for items containing these characters, no matter where I run away or not.

I have two options: Kill these characters in a separate index and split them into the names I'm looking for, or stop searching for the damned.

+2


source to share


3 answers


You can avoid special characters using '/'. Lucene treats the following characters as special characters and you will have to avoid those characters to get it to work.

+ - && || ! ( ) { } [ ] ^ " ~ * ? : \ 

      



If you want to search for "2 + 3" the query must be "2 / + 3"

+3


source


Use QueryParser.escape(String s)

to escape the query string.



+3


source


According to http://lucene.apache.org/core/old_versioned_docs/versions/2_9_1/queryparsersyntax.html#-

The escape character is backward slash, not -forward :.

And to Ankit's answer, the $ doesn't seem to need to be escaped as it is not a special character.

The way out of the dash suggested by Ralph doesn't change me (Zend Lucene). You think that when the word "abc-def" is indexed and you search for "abc-def", you will somehow find that word, whether or not the dash is ignored during indexing. The same result should have the same result. The word appears to be indexed as two separate characters "abc" and "def". However, searching for "abc-def" gives no results if "abc def" does.

+1


source







All Articles