static String QueryParser.escape(String) should do the trick: <http://lucene.apache.org/java/docs/api/org/apache/lucene/queryParser/QueryParser.html#escape(java.lang.String)>
Look at the bottom of the below-linked page for the list of characters that the above method will escape: <http://lucene.apache.org/java/docs/queryparsersyntax.html> Steve Mark Miller wrote: > if you scan the query and escape all colons (ie \:) then you should be > good (I have not verified). Of course you will not be able to do a field > search, but that seems to be what your after. > > Antony Bowesman wrote: >> Hi, >> >> I have a search UI that allows search criteria to be input against >> specific fields, e.g. Subject. >> >> In order to create a suitable Lucene Query, I must analyze that String >> so that it becomes a set of Tokens which I can then turn into Terms. >> QueryParser seems to fit the bill for that, however, it is too clever >> as it assumes that anything suffixes with a : is a field reference. >> >> If someone enters >> >> important:conference agenda >> >> in the subject field, I don't want QP to translate this to >> >> +important:conference +defaultfield:agenda >> >> I want to end up with >> >> +subject:important +subject:conference +subject:agenda >> >> I've written something to do this, but I know it is not as clever as >> QP as currently it can only create BooleanQueries with TermQueries and >> cannot handle PhraseQuery, so would not handle >> >> important:"conference agenda" >> >> correctly. Does anyone have any pointers on how to limit QueryParser >> so that I can force it to treat what it thinks as fields as terms. >> >> Thanks >> Antony --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]