core icon indicating copy to clipboard operation
core copied to clipboard

Fuzzy Query not working on 3.3

Open maurizo opened this issue 10 years ago • 10 comments

Referenced from: https://my.dotcms.com/tickets/detail.dot?id=4c35c6e9-f656-44a0-8b21-dc424ba5dc0b

Fuzzy queries using "~" worked on dotCMS 2.5.7 with Lucene 3.6.1 but not on dotCMS 3.3. Possible problem on the repackaged version for 3.3 upgrading from Lucene 3.6.1 to 4.10.2. No error logs present.

maurizo avatar Mar 14 '16 21:03 maurizo

I can confirm this is also an issue in 3.5:

I tried:

Working with regular query: +contentType:Blog +Blog.body:*pass* -> Returns 4 results
NOT working with Fuzzy search: +contentType:Blog +Blog.body:pass~ -> NO results

And according to: http://dotcms.com/docs/latest/content-search-syntax the code above using ~ should give us results:

Fuzzy Search dotCMS search queries support fuzzy searches based on the Levenshtein Distance. To do a fuzzy search use the tilde, "~", symbol at the end of a Single word Term. An additional (optional) parameter can specify the required similarity. The value is between 0 and 1, with a value closer to 1 only terms with a higher similarity will be matched. The default is 0.5 if no parameter is passed. The first example below (without the parameter), returns blogs with "passes, passing, compassion, passenger, impasse, passed" etc. The second example, however returns only the blogs where "pass" specifically appears in the body.

+contentType:Blog +Blog.body:pass~ +contentType:Blog +Blog.body:pass~0.8 (optional)

jgambarios avatar Apr 08 '16 20:04 jgambarios

This is a an issue with the findAndReplaceQueryDates() method in the ESContentFactoryImpl. It translates the fuzzy query to:

+contenttype:blog +blog.body:pass\~ if you prevent that from happening, then the query works successfully.

wezell avatar Apr 14 '16 16:04 wezell

You can replace these queries with the more powerful ES query language

{
    "query" : {
    "fuzzy" : { "blog.body" : "pass" }
    },
    "size":  10,
    "from": 0
}

wezell avatar Apr 14 '16 16:04 wezell

Jose, while we are in this method, can we confirm that the examples on our hint text work as well? They are pretty much the qa acceptance criteria.

screen shot 2016-04-26 at 12 25 02 pm

wezell avatar Apr 27 '16 13:04 wezell

Hi @wezell,

I tested with the following examples after applying my fix, and the results are correct:

Lucene Query Results Status
+contentType:News +News.sysPublishDate:[01/25/2016 TO 01/28/2016] 5 Correct
+contentType:News +News.sysPublishDate:[01/25/2016 10:00:00PM TO 01/28/2016 10:00:00PM] 3 Correct
+contentType:News +News.sysPublishDate:20160125* 2 Correct
+contentType:News +News.sysPublishDate:2016012514* 1 Correct
+contentType:News +News.sysPublishDate:20160127230000 1 Correct

jcastro-dotcms avatar Apr 27 '16 14:04 jcastro-dotcms

@jcastro-dotcms awesome! @john-thomas-dotcms lets doc.

wezell avatar Apr 27 '16 14:04 wezell

PR: https://github.com/dotCMS/core/pull/8964

Incorrect code was added to escape the tilde (~) character. Escaping is necessary when filtering data from the Content Search portlet, which is already being done in this line: https://github.com/dotCMS/core/blob/master-3.5/src/com/dotmarketing/portlets/contentlet/ajax/ContentletAjax.java#L516

Users that run Lucene queries from the Query Tool portlet must know that the tilde needs to be escaped when looking for content that has such a character, as explained in our doc: http://dotcms.com/docs/latest/content-search-syntax , in the Escape Special Characters section.

jcastro-dotcms avatar Apr 27 '16 15:04 jcastro-dotcms

master-3.6 PR: https://github.com/dotCMS/core/pull/9006

jgambarios avatar May 04 '16 18:05 jgambarios

Fixed, tested on master-3.6 // H2 // FF

bryanboza avatar Jun 06 '16 20:06 bryanboza

Is there anything new that needs to be doc'ed here? We have doc on the fuzzy search already here: http://auth.dotcms.com/docs/latest/content-search-syntax#FuzzySearch, and we document that characters need to be escaped here: http://auth.dotcms.com/docs/latest/content-search-syntax#EscapingCharacters

I'm not seeing anything else that needs to be doc'ed - please let me know if I'm missing something.

john-thomas-dotcms avatar Jun 10 '16 21:06 john-thomas-dotcms