Using the wrong escape character for Lucene lexica

2019-07-25 08:34发布

I have a similar issue as the following question: Lucene error while parsing Query: Cannot parse '': Encountered “” at line 1, column 0, and I had already tried all the escaping. What else could it be?

I'm using Kentico 12 hotfix 14, with their Lucene.NET 3.0.3 implementation. My Smart Search Index uses the Standard analyzer, see below:

enter image description here

I get the expected rows back when I use the following lucene syntax to pull back an en-US culture result. This syntax is automatically created by Kentico and is needed to retrieve the correct culture. This was directly copied from the property value.

"+_culture:([en-us TO en-us] [invariantifieldivaluei TO invariantifieldivaluei])"

When I add (or use alone) the following value (in many different forms - without parenthesis, etc):

 "+length:(24\")"

I always get the Lexical error:

"Cannot parse '+_culture:([en-us TO en-us] [invariantifieldivaluei TO invariantifieldivaluei])  +length:(24\")': Lexical error at line 1, column 95.  Encountered: <EOF> after : \"\\\")\""

As you can see, I believe that I have escaped the value for the length correctly. What am I missing here?

Other values, that don't require escaping work just fine, such as:

+material:(nitrile)

Any thoughts on what I'm doing wrong with the 24" value? Wrong analyzer? Needed Kentico hotfix? Wrong order of filters? Thanks for your time!

1条回答
一夜七次
2楼-- · 2019-07-25 08:56

Seems I'm not the first to deal with this within Kentico, and found the following helper method: CMS.Search.SearchSyntaxHelper.EscapeKeyWords(string). I applied this method to my specific search filter values and it's working as expected! Lots of good methods within the parent class too, check them out.

Escaped value in code

Escaped value in text visualizer

查看更多
登录 后发表回答