On 4/20/2015 7:41 AM, Steven White wrote: > In my application, a user types "Apache Solr Notes". I take that text and > send it over to Solr like so: > > > http://localhost:8983/solr/db/select?q=title:(Apache%20Solr%20Notes)&fl=id%2Cscore%2Ctitle&wt=xml&indent=true&q.op=AND > > And I get a hit on "Apache Solr Release Notes". This is all good. > > Now if the same user types "Apache: Solr Notes" (notice the ":" after > "Apache") I will get a SyntaxError. The fix is to escape ":" before I send > it to Solr. What I want to figure out is how can I tell Solr / Lucene to > ignore ":" and escape it for me? In this example, I used ":" but my need > is for all other operators and reserved Solr / Lucene characters.
If we assume that what you did for the first query is what you will do for the second query, then this is what you would have sent: q=title:(Apache: Solr Notes) How is the parser supposed to know that only the second colon should be escaped, and not the first one? If you escape them both (or treat the entire query string as query text), then the fact that you are searching the "title" field is lost. The text "title" becomes an actual part of the query, and may not match, depending on what you have done with other parameters, such as the default operator. If you use the dismax parser (*NOT* the edismax parser, which parses field:value queries and boolean operator syntax just like the lucene parser), you may be able to achieve what you're after. https://cwiki.apache.org/confluence/display/solr/The+DisMax+Query+Parser https://wiki.apache.org/solr/DisMaxQParserPlugin With dismax, you would use the qf and possibly the pf parameter to tell it which fields to search and send this as the query: q=Apache: Solr Notes Thanks, Shawn