1

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!

RichieMN
  • 905
  • 1
  • 12
  • 33
  • 1
    What is the query like in Lucene logs ? How is parsed `'+length:(24")'` and `'+length:(24\\")'` ? It could be that the backslash is also used to escape special characters from the code (the query is first parsed as a string client side before becoming the request that will be parsed by Lucene query parser), so I'd try to escape the backslash himself to see how this query is parsed on the client and on the server side. – EricLavault Jun 06 '19 at 07:17
  • Thanks for your help! Your suggestion made me try a few additional things and a found a helper method to escape keywords. See my solution below. – RichieMN Jun 11 '19 at 13:55

1 Answers1

1

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

RichieMN
  • 905
  • 1
  • 12
  • 33