Search code examples
lucene.netkenticoquery-parser

How to allow leading wild cards in custom smart search web part (Kentico 10)


I have a custom index for my products and I am using the Subset Analyzer. This Analyzer works great, but if you do field searches, it does not work.

For example, I have a document with the following fields:

  • "documentname", "My-Document-Name"
  • "tags", "1234,5678,9101"
  • "documentdescription", "This is a great Document, My-Document-Name."

When I just search "name AND tags:(1234)", I get this document in my results because it searches +_content:name.

-- However:

When I search "documentname:(name)^3.0 AND tags:(1234)", I do not get this document in my results.

Of course, when I do "documentname:(*name*)^3.0" I get a parse error saying: '*' or '?' not allowed as first character in WildcardQuery.

How can I either enable wildcard query in my custom CMS.Search webpart?


Solution

  • First of all you have to make sure that a field you checking is in the index with proper name. documentname might not be in the index it can be called _title, depends how you index is set up. Get lukeall and check your index (it should be in \CMS\App_Data\CMSModules\SmartSearch\YourIndexName). You can use luke to test your searches as well.

    For examples there is no tags but there is documenttags field.

    P.S. Wildcards are working and you are right you can't use them as a first character by default (lucene documentation says: You cannot use a * or ? symbol as the first character of a search), but there is a way to set it up in lucene.net, although i dont know if there are setting for that in Kentico. But i dont think you need wildcards, so your query should be (assuming you have documentname and documenttags in the index):

    +(documentname:"My-Name" AND documenttags:"tag1")