Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Lucene Highlighter令牌流异常_Java_Lucene_Lucene Highlighter - Fatal编程技术网

Java Lucene Highlighter令牌流异常

Java Lucene Highlighter令牌流异常,java,lucene,lucene-highlighter,Java,Lucene,Lucene Highlighter,我对Lucene Highlighter有问题。我在Stackoverflow和其他程序中发现了一些代码,但这些代码在我的程序中不起作用。这是一种我尝试搜索和higlight单词的方法,但当我搜索某物时,程序会给我异常 方法: private static void useIndex(String query, String field, String option) throws ParseException, CorruptIndexException, IOExce

我对Lucene Highlighter有问题。我在Stackoverflow和其他程序中发现了一些代码,但这些代码在我的程序中不起作用。这是一种我尝试搜索和higlight单词的方法,但当我搜索某物时,程序会给我异常

方法:

private static void useIndex(String query, String field, String option)
            throws ParseException, CorruptIndexException, IOException, InvalidTokenOffsetsException {
        // StandardAnalyzer analyzer = new StandardAnalyzer();
        Query q = new QueryParser(field, analyzer).parse(query);

        int hitsPerPage = 5;

        IndexReader reader = DirectoryReader.open(index);
        IndexSearcher searcher = new IndexSearcher(reader);

        TopScoreDocCollector collector = TopScoreDocCollector.create(hitsPerPage);

        searcher.search(q, collector);

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

        SimpleHTMLFormatter htmlFormatter = new SimpleHTMLFormatter();
        Highlighter highlighter = new Highlighter(htmlFormatter, new QueryScorer(q));

        // display results
        System.out.println("Found " + hits.length + " hits for " + query);
        for (int i = 0; i < hits.length; ++i) {
            int docId = hits[i].doc;
            Document d = searcher.doc(docId);
            String docURL = d.get("url");
            String docContent = d.get("content");

            TokenStream tokenStream = TokenSources.getAnyTokenStream(reader, docId, "content", analyzer);
            TextFragment[] frag = highlighter.getBestTextFragments(tokenStream, docContent, false, 4);

            String docFrag="";

            if ((frag[0] != null) && (frag[0].getScore() > 0)) {
                docFrag=frag[0].toString();
            }
            model.addRow(new Object[] { docURL, findSilimar(docId), docFrag });
        }
        reader.close();
    }
我什么都试过了,但我不知道怎么了


另外,对不起我的英语。

一个
NoClassDefFoundError
意味着类不在类路径中,所以您应该弄清楚需要添加什么jar才能获得它<代码>内存索引位于:lucene-memory-x.x.x.jar

顺便说一下,乍一看,您提供的代码中似乎不会抛出此异常

    Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/lucene/index/memory/MemoryIndex
Caused by: java.lang.ClassNotFoundException: org.apache.lucene.index.memory.MemoryIndex