0

According to lucene documentation I'm getting proper results with the following approaches:

  1. term:foo~1 means a fuzzy search on a word foo allowing room for 1 error
  2. term:"foo bar"~1 means that foo and bar should be within 1 word of each other in order for search to produce any meaningful result (e.g. search will match foo me bar)

Question: is there a way to query lucene so that term:"foo bar"~1 means that it's a fuzzy search and token foo bar as a whole is allowed 1 error in it?

If it's of any help, I am using standard analyzer on the term field

AVK
  • 645
  • 9
  • 22
  • 1
    When you are using Lucene's classic query parser, fuzzy searches can only be applied to single word terms (single tokens). As soon as you start using a phrase ("foo bar") then you no longer have a single word term, and you can no longer use the fuzzy search syntax. Therefore you cannot combine the two approaches (fuzzy search and proximity search). You would need to use the full Lucene API to build such a query. – andrewJames Jul 05 '21 at 15:58
  • Thanks for the answer @andrewjames. Would you know if it would somehow be possible in the context of `couchdb-lucene`? – AVK Jul 06 '21 at 03:22
  • Sorry - I don't see any obvious way to use a full Lucene API query, but that is after just a quick scan of the [documentation](https://github.com/rnewson/couchdb-lucene). I have never used couchdb-lucene, so I could be missing something. Can you split the query into 2 steps? (1) Fuzzy search against all couchdb data, then (2) proximity search against the results from step 1 (with some data "normalization" needed to fix the fuzzy term)? That would be awkward, to say the least - but may be possible. – andrewJames Jul 06 '21 at 12:21
  • @andrewjames thanks! I think i'll take a different approach by doing some post processing on a looser match set (gonna allow fuzziness on each token if the search string instead) which is possible in my case. btw, i did get a reply from couchbd-lucene's creator, saying that what i need is indeed impossible and needs an additional work on the library itself. – AVK Jul 07 '21 at 05:44

0 Answers0