我从Lucene 3.6升级到5.3.0,但搜索不想在使用5.3.0时使用我的参数。Lucene查询对象和搜索
这个工作在3.6:
IndexSearcher searcher = new IndexSearcher(IndexReader.open(directory));
SimpleAnalyzer analyzer = new SimpleAnalyzer(Version.LUCENE_36);
QueryParser parser = new QueryParser(Version.LUCENE_36, "contents",
analyzer);
TopDocs topDocs = null;
Query query = parser.parse(queryString);
topDocs = searcher.search(query, 1000);
但在5.3中,编译器要求我使用SrndQuery,但我还是坐上searcher.search方法的错误:
IndexSearcher searcher = new IndexSearcher(DirectoryReader.open(directory));
Analyzer analyzer = new SimpleAnalyzer();
QueryParser parser = new QueryParser();
TopDocs topDocs = null;
SrndQuery query = QueryParser.parse(queryString);
topDocs = searcher.search(query, 1000);//**The method search(Query, int) in the type IndexSearcher is not applicable for the arguments (SrndQuery, int)**
不确定我在这里做错了什么。有任何想法吗?
P.S.我正在升级,因为我无法从最近索引的某些PDF中获取突出显示的文本。
+ femtoRgon此代码是基于Web的搜索的一部分,所以我没有打算重复使用,因为它一次只有一个请求。我现在会尝试你的建议。 –
+ femtoRgon工作,谢谢。感谢您的解释。 –