Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/solr/3.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
lucene索引在java应用中的应用_Lucene_Solr - Fatal编程技术网

lucene索引在java应用中的应用

lucene索引在java应用中的应用,lucene,solr,Lucene,Solr,最近我开始在solr上工作。我已经在solr中创建了索引,我想通过java应用程序查询它。我不想在我的应用程序中使用solr.war。如何通过solrj api或lucene java api使用它?我的想法是在项目上下文中添加这些索引并使用它。我浏览了一些示例/教程,但没有找到任何关于如何使用已创建索引的内容。请告诉我一个合适的解决方案,或者任何指定该解决方案的链接都将不胜感激。是的,您可以将Solr创建的索引与Lucene一起使用,这没有什么特别之处,因为Solr本身使用Lucene。因此,

最近我开始在solr上工作。我已经在solr中创建了索引,我想通过java应用程序查询它。我不想在我的应用程序中使用solr.war。如何通过solrj api或lucene java api使用它?我的想法是在项目上下文中添加这些索引并使用它。我浏览了一些示例/教程,但没有找到任何关于如何使用已创建索引的内容。请告诉我一个合适的解决方案,或者任何指定该解决方案的链接都将不胜感激。

是的,您可以将Solr创建的索引与Lucene一起使用,这没有什么特别之处,因为Solr本身使用Lucene。因此,所有Lucene文档的应用都是不变的


或者,如果您不想将Solr用作服务器,您可以在Java应用程序中使用它。

您可以使用Lucene API创建/更新和搜索索引。
由于solr基于lucene,因此基础指数是lucene指数。
Lucene将类公开为IndexWriter和IndexSearcher,这将帮助您与index交互

搜索solr/lucene索引的示例-

Directory index = FSDirectory.open(new File("/path/to/index")); 
IndexSearcher searcher = new IndexSearcher(index, true);
TopScoreDocCollector collector = TopScoreDocCollector.create(10, true);
searcher.search(q, collector);
ScoreDoc[] hits = collector.topDocs().scoreDocs;
应该能够找到这方面的例子。

我是这样做的

String realPath = request.getRealPath("/");
        StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT);
        Directory index = FSDirectory.open(new File(realPath+"/index"));
        IndexSearcher indexSearcher = new IndexSearcher(index, true);
        TopScoreDocCollector collector = TopScoreDocCollector.create(2000, true);

        QueryParser query = new QueryParser(Version.LUCENE_CURRENT, "name", analyzer);
        Query q = null;
        try {
            q = query.parse("*:*");
        } catch (ParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        indexSearcher.search(q, collector);
        ScoreDoc[] scoreDoc = collector.topDocs().scoreDocs;

非常感谢。我使用了lucene java api。谢谢Jayendra先生,这真的帮助了我。如果有办法直接以JSON格式获取查询结果,请告诉我。正如我们使用&wt=json得到的那样。