Lucene 5.3 Highlighter getBestFragments()无效

时间:2015-09-03 15:39:25

标签: java apache tomcat lucene lucene-highlighter

我使用以下代码取出检索结果的片段。下面显示的错误来自使用getBestFragment()函数的行。我正在使用Apache Tomcat 7.0。请帮忙。

public JSONArray search(String indexDir,String scoring,boolean stemming) throws IOException, ParseException{
    searcher = new Searcher(indexDir,scoring,stemming);
    long startTime = System.currentTimeMillis();
    TopDocs hits = searcher.search(query);
    long endTime = System.currentTimeMillis();
    JSONArray searchResultArray = new JSONArray();
    StandardAnalyzer analyzer = new StandardAnalyzer();

    int maxNumFragmentsRequired = 1;
    QueryParser queryParser=new QueryParser(LuceneConstants.CONTENTS,analyzer);
    QueryScorer scorer = new QueryScorer(queryParser.parse(query));
    org.apache.lucene.search.highlight.Highlighter highlighter = new org.apache.lucene.search.highlight.Highlighter(scorer);

    for(ScoreDoc scoreDoc : hits.scoreDocs) {
      JSONObject searchResultObject = new JSONObject();
      Document doc = searcher.getDocument(scoreDoc);

      StandardAnalyzer analyzer2 = new StandardAnalyzer();
      String text = doc.get(LuceneConstants.CONTENTS);
      System.out.println("dfsdfsdfsdferer "+ text);
      TokenStream tokenStream = analyzer2.tokenStream(LuceneConstants.CONTENTS,new StringReader(text));
      highlighter.setTextFragmenter(new SimpleFragmenter(40));
      String result = "";
    try {
        //result = highlighter.getBestFragments(tokenStream, text, maxNumFragmentsRequired,"...");
        result = highlighter.getBestFragment(analyzer2, LuceneConstants.CONTENTS, text);
    } 
    catch(Exception e)
    {
        e.printStackTrace();
        result = "Oh Snap!!";
    }
}

错误是

    Sep 03, 2015 8:53:55 PM org.apache.catalina.core.StandardWrapperValve invoke
    SEVERE: Servlet.service() for servlet [com.eniac.searchEngine.Search] in context with path [/Assignment1] threw exception [Servlet execution threw an exception] with root cause
    java.lang.ClassNotFoundException: org.apache.lucene.index.memory.MemoryIndex
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702)
        at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547)
        at org.apache.lucene.search.highlight.WeightedSpanTermExtractor.getLeafContext(WeightedSpanTermExtractor.java:391)
        at org.apache.lucene.search.highlight.WeightedSpanTermExtractor.extractWeightedTerms(WeightedSpanTermExtractor.java:355)
        at org.apache.lucene.search.highlight.WeightedSpanTermExtractor.extract(WeightedSpanTermExtractor.java:150)
        at org.apache.lucene.search.highlight.WeightedSpanTermExtractor.getWeightedSpanTerms(WeightedSpanTermExtractor.java:518)
        at org.apache.lucene.search.highlight.QueryScorer.initExtractor(QueryScorer.java:219)
        at org.apache.lucene.search.highlight.QueryScorer.init(QueryScorer.java:187)
        at org.apache.lucene.search.highlight.Highlighter.getBestTextFragments(Highlighter.java:196)
        at org.apache.lucene.search.highlight.Highlighter.getBestFragments(Highlighter.java:156)
        at org.apache.lucene.search.highlight.Highlighter.getBestFragment(Highlighter.java:102)
        at org.apache.lucene.search.highlight.Highlighter.getBestFragment(Highlighter.java:80)
        at com.eniac.sen.LuceneTester.search(LuceneTester.java:139)
        at com.eniac.searchEngine.Search.doGet(Search.java:103)
        at com.eniac.searchEngine.Search.doPost(Search.java:125)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
        at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
        at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
        at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
        at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
        at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
        at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
        at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:953)
        at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
        at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
        at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1041)
        at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:603)
        at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
        at java.lang.Thread.run(Thread.java:745)

0 个答案:

没有答案