views:

418

answers:

1

Good day

The question is: Could anyone give me an example about how to do fuzzy matching of two strings using Lucene.NET (or using Java version of Lucene, or in any other language that has port of Lucene).

+2  A: 

Could you be a bit more specific on what you mean by fuzzy matching?

Lucene offers fuzzy queries using the tilde(~) operator and the wildcards (* & ?) See here

If you want to compare string distance of 2 strings using methods such as Levenshtein, Jaro-Winkler etc. you are better off using a separate library such as SimMetrics. I use Simmetrics in my production site and it works fab.

SimMetricsMetricUtilities.Levenstein ls = new SimMetricsMetricUtilities.Levenstein(); //compare string 1, string 2 
double sim = ls.GetSimilarity(string_1, string_2); 
if(sim > [some value]) 
{ 
//do something 
} 
Mikos
Thank you for answer sir.You are right, I want to compare two strings using Levenshtein algorithm, could you give me an example how you doing fuzzy match two strings using SimMetrics?
Is actually very straight-forward:1. Add a reference to the Simmetrics dll in your project2. In the method where you want to run the similarity,SimMetricsMetricUtilities.Levenstein ls = new SimMetricsMetricUtilities.Levenstein();//compare string 1, string 2double sim = js.GetSimilarity(string_1, string_2);if(sim > [some value]){//do something}
Mikos