java - How to transfer lucene36 to lucene 40 -
here code:
public int docscontainterm(term tm) throws ioexception { termdocs termdocs = indexreader.termdocs(tm); //docsenum termdocs = indexreader. int count = 0; while (termdocs.next()) { if (indexreader.docfreq(tm) != 0) { count++; } } return count; } public int tf(term tm, string docname) throws ioexception { termdocs termdocs = indexreader.termdocs(tm); while (termdocs.next()) { document doc = indexreader.document(termdocs.doc()); if (doc.get("filename").equals(docname)) { return termdocs.freq(); } } return 0; } public static void main(string[] args) throws corruptindexexception, ioexception { string indexdir = "indexdir"; string docs = "docs"; string query = "kennedy administration pressure on ngo dinh diem stop suppressing buddhists"; directory dir = fsdirectory.open(new file(indexdir)); indexreader indexreader = indexreader.open(dir); bm25 bm25 = new bm25(indexreader, docs); system.out.println(bm25.getcontent("171")); system.out.println(bm25.htmlgetcontent("171", query.tolowercase())); }
}
i have searched it, should change termdocs docsenum,but don't know how change. here error: exception in thread "main" java.lang.error: unresolved compilation problem:
at bm25.main(bm25.java:269)
from apache lucene migration guide,
terms binary in nature (arbitrary byte[]), represented bytesref class (which provides offset + length "slice" existing byte[]).
fields separately enumerated (fields.iterator()) terms within each field (termenum).
termdocs renamed docsenum.
termpositions renamed docsandpositionsenum, , no longer extends docs enumerator (docsenum).
deleted docs no longer implicitly filtered docs/positions enums. instead, pass bits skipdocs (set bits skipped) when obtaining enums. also, can ask reader deleted docs.
the docs/positions enums cannot seek term. instead, termsenum able seek, , request docs/positions enum termsenum.
termsenum's seek method returns more information.
termsenum has ord() method, returning long numeric ordinal (ie, first term 0, next 1, , on) term it's not positioned to. there corresponding seek(long ord) method. note these methods optional; in particular multifields termsenum not implement them.
how obtain enums has changed. primary entry point fields class. likewise docsandpositionsenum.
Comments
Post a Comment