Mantas
Mantas

Reputation: 3239

escaping quotes in grails gsp for es

Hi guys I'm trying to escape double quotation marks in my gsp search query which is being passed into elasticsearch so far I have:

<input id="q" name="q" type="text" class="large" value="${params?.q?.encodeAsHTML()}" ..

But when I go to my webapps search field and use a query something like "abc" i get massive exceptions in my logfile, mainly:

 org.apache.lucene.queryParser.ParseException: Cannot parse '("abc) AND recstatus:"public"': Lexical error at line 1, column 30.  Encountered: <EOF> after : ""

and

2013-03-01 11:35:06,874 [New I/O  worker #3] DEBUG search.type  - [Helleyes] [some_index][3], node[BZH5bHO8RX2va-HVpTDEng], [P], s[STARTED]: Failed to execute 
[org.elasticsearch.action.search.SearchRequest@2f6a3595]
org.elasticsearch.transport.RemoteTransportException: [Lasher][inet[/xxx.xxx.x.xxx:9300]][search/phase/query]
Caused by: org.elasticsearch.search.SearchParseException: [some_index][3]: from[0],size[20]: Parse Failure [Failed to parse source [:)
^E򃦲om@0<83>sizeA20<84>query򋱵ery_string򂜨"abc) AND recstatus:"public"<8f>analyze_wildcard#󻅦ields䴩tle񻀁]]

etc.. any suggestions?

Upvotes: 0

Views: 2109

Answers (2)

denis111
denis111

Reputation: 71

Or better use raw() method from Grails 2.3+ http://mrhaki.blogspot.com.es/2013/11/grails-goodness-generating-raw-output.html ;)

<li${raw(' class="active"')}/>

Upvotes: 1

Mantas
Mantas

Reputation: 3239

Found the problem...

in config.groovy there's a flag set:

grails.views.default.codec = "none"

and this overrides any code in the gsp pages.

you can either set this flag to:

grails.views.default.codec = "html"

or override individual gsp files.

Upvotes: 4

Related Questions