Get total record count in Lucene or SQL SERVER Full Text Search -
i have table named tags
. within table have id
, tag name
. find total record count group when user type in prefix words
in web page textbox. same stackoverflow.com.
when user type in "sql"
word ,the result below:
something work. note leading wildcard can very slow on large index.
ramdirectory dir = new ramdirectory(); indexwriter iw = new indexwriter(dir, new keywordanalyzer(), indexwriter.maxfieldlength.unlimited); document d = new document(); field f = new field("tag", "", field.store.yes, field.index.analyzed); d.add(f); f.setvalue("sql"); iw.adddocument(d); f.setvalue("mysql"); iw.adddocument(d); f.setvalue("sql-server"); iw.adddocument(d); f.setvalue("sql-server"); iw.adddocument(d); f.setvalue("sql-server"); iw.adddocument(d); f.setvalue("c#"); iw.adddocument(d); f.setvalue("java"); iw.adddocument(d); f.setvalue("java"); iw.adddocument(d); iw.commit(); indexreader reader = iw.getreader(); console.writeline("tags containing sql"); using (filteredtermenum termenum = new wildcardtermenum(reader, new term("tag", "*sql*"))) { { if (termenum.term != null) console.writeline(termenum.term.text + ":" + reader.docfreq(termenum.term)); } while (termenum.next()); } console.writeline("\ntags containing java"); using (filteredtermenum termenum = new wildcardtermenum(reader, new term("tag", "*java*"))) { { if (termenum.term != null) console.writeline(termenum.term.text + ":" + reader.docfreq(termenum.term)); } while (termenum.next()); } reader.dispose(); iw.dispose();
Comments
Post a Comment