gpt4 book ai didi

java - 为什么我在使用 lucene 时查询解析器总是出现错误

转载 作者:行者123 更新时间:2023-11-30 04:54:54 25 4
gpt4 key购买 nike

大家好,我目前正在解析所有 html 正文用于查找包含单词的列表的文档频率以及为什么我不断收到此错误

org.apache.lucene.queryParser.ParseException: Cannot parse '': Encountered "<EOF>" at line 1, column 0.

期待以下之一: ... “+”... “——”…… “(”... “”... ... ... ... ... “[”... “{”... ... ... “”...

at org.apache.lucene.queryParser.QueryParser.parse(QueryParser.java:211)
at CalculateWeightTable.search(CalculateWeightTable.java:221)
at CalculateWeightTable.calculate(CalculateWeightTable.java:134)
at FocusedCrawlingMain.Search(FocusedCrawlingMain.java:64)
at View.actionPerformed(View.java:219)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
at java.awt.EventQueue.access$000(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.awt.EventQueue$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.awt.EventQueue$2.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)

这是我用于查找文档频率的代码

它说错误发生在 lucene 尝试解析 queryString 时

位于我的代码的这一部分

Query query = parser.parse(queryString);

我不知道为什么它在解析查询字符串时总是给我错误

private static int search(Searcher searcher, String queryString)
throws ParseException, IOException {

// Build a Query object
StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT);
QueryParser parser = new QueryParser(Version.LUCENE_CURRENT, "content",
analyzer);
Query query = parser.parse(queryString);

// Search for the query
TopScoreDocCollector collector = TopScoreDocCollector.create(10, true);
searcher.search(query, collector);

ScoreDoc[] hit = collector.topDocs().scoreDocs;

int hitsCount = hit.length;

if (hitsCount == 0) {
//System.out.println("No matches were found for \"" + queryString+ "\"");
} else {
//System.out.println("hit count : " + collector.getTotalHits());

}

return collector.getTotalHits();
}

最佳答案

看起来 queryString 对象是空的。您可以从调用该方法的位置检查该方法的输入吗?

关于java - 为什么我在使用 lucene 时查询解析器总是出现错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8845750/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com