无法取消对java QueryParser short的引用
我有一些索引文档,我想用一个查询来搜索它们,我检查了lucene文档并编写了这段代码,但不知怎的,我在QueryParser行中得到了“short Can Dereference”,我是Java和lucene的新手,我使用lucene 5.3.1
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import static java.time.Clock.system;
import javax.management.Query;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.core.KeywordAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.Term;
import org.apache.lucene.queryparser.classic.QueryParser;
import org.apache.lucene.search.FuzzyQuery;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import static sun.rmi.transport.TransportConstants.Version;
import static sun.rmi.transport.TransportConstants.Version;
public class Searcher
{
public static void main(String args[]) throws IOException{
String query="computer science";
Analyzer analyzer = new KeywordAnalyzer();
Query q = new QueryParser(Version.LUCENE_CURRENT, "W", analyzer).parse(query); //ERROR IS HERE
Path indexPath = Paths.get("MonIndex");
Directory directory = FSDirectory.open(indexPath);
DirectoryReader reader = DirectoryReader.open(directory);
IndexSearcher iSearcher = new IndexSearcher(reader);
TopDocs topdocs = iSearcher.search(q2, 100);
ScoreDoc[] resultsList = topdocs.scoreDocs;
for(int i = 0; i<resultsList.length; i++){
Document book = iSearcher.doc(resultsList[i].doc);
System.out.println(book.getField("I").stringValue());
}
}
}
# 1 楼答案
问题是
Version.LUCENE_CURRENT
。您没有导入Lucene的Version
,但是您确实有sun.rmi.transport.TransportConstants.Version
,虽然我不熟悉这个库,但它肯定是does appear to be a short。因此,试图通过引用不存在的sun.rmi.transport.TransportConstants.Version.LUCENE_CURRENT
来取消引用,会导致抛出该错误但是,在您所说的Lucene版本中,the ^{}ctor 甚至不再接受版本参数,所以只需删除它:
您的下一个错误:queryparser返回的
Query
不是javax.management.Query