i implemented fuzzy search lucene 4.3.1 i'm not satisfied result. specify number of results should return. example if want 10 results, should return 10 best matches, no matter how bad are. of time returns nothing if word search different in index. how can achieve more/fuzzier results?
here code have:
public string[] lucenequery(string query, int numberofhits, string path) throws parseexception, ioexception { file dir = new file(path); directory index = fsdirectory.open(dir); query = query + "~"; query q = new queryparser(version.lucene_43, "label", analyzer) .parse(query); indexreader reader = directoryreader.open(index); indexsearcher searcher = new indexsearcher(reader); query fuzzyquery = new fuzzyquery(new term("label", query), 2); scoredoc[] fuzzyhits = searcher.search(fuzzyquery, numberofhits).scoredocs; string[] fuzzyresults = new string[fuzzyhits.length]; (int = 0; < fuzzyhits.length; ++i) { int docid = fuzzyhits[i].doc; document d = searcher.doc(docid); fuzzyresults[i] = d.get("label"); } reader.close(); return fuzzyresults; }
large edit distances no longer supported fuzzyquery in lucene 4.x. current implementation of fuzzyquery huge improvement on performance lucene 3.x implementation, supports 2 edits. distances greater 2 damerau–levenshtein edits considered useful.
according fuzzyquery documentation, if must have higher edit distances:
if want this, consider using n-gram indexing technique (such spellchecker in suggest module) instead.
the strong implication should rethink trying accomplish, , find more useful approach.
Comments
Post a Comment