[Hippo-cms7-user] Escaping special characters in search queries

Mykhailo Kotsur miccots at gmail.com
Fri Apr 13 16:32:46 CEST 2012


This one worked for me:

        String escapeChars ="[\\\\+\\-\\!\\(\\)\\:\\^\\]\\{\\}\\~\\?]";
        String escapedQuery = query.replaceAll(escapeChars, "\\\\\\\\$0");


Mike.

On Apr 5, 2012, at 9:13 PM, Ard Schrijvers wrote:

> On Thu, Apr 5, 2012 at 4:21 PM, Mykhailo Kotsur <miccots at gmail.com> wrote:
>> Well, currently I have a trouble with parenthesis in free text search:
>> 
>>        Prognostic impact of TP53 mutations in MDS with del(5q)
>> 
>>        SearchInputParsingUtils just remores parenthesis and this document is not found.
> 
> if you want to escape them it should be possible with your own parser
> that replaces ( with \( : I did not test it but I think it should work
> 
> Regards Ard
> 
> 
> 
>> 
>> Mike.
>> 
>> 
>> On Apr 5, 2012, at 3:53 PM, Jeroen Reijn wrote:
>> 
>>> Hi,
>>> 
>>> what kind of characters would you like to escape? In the HST there is
>>> a SearchInputParsingUtils. It can help you.
>>> 
>>> Cheers,
>>> 
>>> Jeroen
>>> 
>>> On Thu, Apr 5, 2012 at 3:46 PM, Mykhailo Kotsur <miccots at gmail.com> wrote:
>>>> Is there any out-of-box way to escape special characters in search queries?
>>>> For example, searches for phrases with brackets does do work only if brackets are escaped with \\.
>>>> 
>>>> org.apache.lucene.queryParser.QueryParser seems to do the job, but it requires extra dependency in maven.
>>>> 
>>>> 
>>>> Thanks.
>>>> Mike.
>>>> _______________________________________________
>>>> Hippo-cms7-user mailing list and forums
>>>> http://www.onehippo.org/cms7/support/forums.html
>>> _______________________________________________
>>> Hippo-cms7-user mailing list and forums
>>> http://www.onehippo.org/cms7/support/forums.html
>> 
>> _______________________________________________
>> Hippo-cms7-user mailing list and forums
>> http://www.onehippo.org/cms7/support/forums.html
> 
> 
> 
> -- 
> Amsterdam - Oosteinde 11, 1017 WT Amsterdam
> Boston - 1 Broadway, Cambridge, MA 02142
> 
> US +1 877 414 4776 (toll free)
> Europe +31(0)20 522 4466
> www.onehippo.com
> _______________________________________________
> Hippo-cms7-user mailing list and forums
> http://www.onehippo.org/cms7/support/forums.html




More information about the Hippo-cms7-user mailing list