在Eclipse中创建Lucene项目

1、下载Lucene代码。
GithHub地址:ttps://github.com/apache/lucene-solr
这个地址下载到的是Lucene + solr的源码。Lucene主页下载的单独的Lucene_src.zip是不可以导入的。

2、必须软件安装
Lucene5.5 需要JDK8、ANT1.8.1以上、ivy。
如果网络需要代理的,需要执行
set ANT_OPTS=-Dhttp.proxyHost=myproxyhost -Dhttp.proxyPort=8080 -Dhttp.proxyUser=myproxyusername -Dhttp.proxyPassword=myproxypassword -Dhttps.proxyHost=myproxyhost -Dhttps.proxyPort=8080


3、进入lucene-solr目录下(Lucene和solr文件夹上一级),执行ant eclipse。(也可以执行'ant idea','ant netbeans')

如果网络状况差,下载依赖出现报错的情况。手动访问报错消息中的红色URL,将下载好的jar包拷贝到绿色本地仓库下
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

[ivy:retrieve]  ==== shared: tried
[ivy:retrieve]    C:\Users\zhaotiantian.G08\.ivy2\shared\org.carrot2\morfologik-polish\2.0.1\jars\morfologik-polish.jar
[ivy:retrieve]  ==== public: tried
[ivy:retrieve]    https://repo1.maven.org/maven2/org/carrot2/morfologik-polish/2.0.1/morfologik-polish-2.0.1.jar
[ivy:retrieve]          ::::::::::::::::::::::::::::::::::::::::::::::
[ivy:retrieve]          ::              FAILED DOWNLOADS            ::
[ivy:retrieve]          :: ^ see resolution messages for details  ^ ::
[ivy:retrieve]          ::::::::::::::::::::::::::::::::::::::::::::::
[ivy:retrieve]          :: org.carrot2#morfologik-polish;2.0.1!morfologik-polish
.jar
[ivy:retrieve]          ::::::::::::::::::::::::::::::::::::::::::::::
[ivy:retrieve]
[ivy:retrieve]
[ivy:retrieve] :: USE VERBOSE OR DEBUG MESSAGE LEVEL FOR MORE DETAILS

BUILD FAILED
D:\OpenSource\lucene-5.5.0-src\build.xml:230: The following error occurred while
 executing this line:
D:\OpenSource\lucene-5.5.0-src\lucene\build.xml:126: The following error occurre
d while executing this line:
D:\OpenSource\lucene-5.5.0-src\lucene\common-build.xml:2273: The following error
 occurred while executing this line:
D:\OpenSource\lucene-5.5.0-src\lucene\analysis\build.xml:91: The following error
 occurred while executing this line:
D:\OpenSource\lucene-5.5.0-src\lucene\analysis\build.xml:38: The following error
 occurred while executing this line:
D:\OpenSource\lucene-5.5.0-src\lucene\common-build.xml:454: impossible to resolv
e dependencies:
        resolve failed - see output for details

------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


4、进入Eclipse 导入Java Project,路径为lucene-solr/Lucene和lucene-solr/solr
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
以下是使用C# Lucene.Net创建索引的步骤: 1.添加Lucene.Net库的引用 在Visual Studio,右键单击项目并选择“管理NuGet程序包”。在搜索框搜索“Lucene.Net”,然后安装Lucene.Net库。 2.创建索引 ```csharp using Lucene.Net.Analysis.Standard; using Lucene.Net.Documents; using Lucene.Net.Index; using Lucene.Net.Store; using System.IO; // 创建索引 public void CreateIndex(string indexPath, string dataPath) { // 创建分析器 var analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30); // 创建索引存储目录 var directory = FSDirectory.Open(new DirectoryInfo(indexPath)); // 创建索引写入器 var writer = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED); // 读取数据文件 var lines = File.ReadAllLines(dataPath); // 遍历数据文件的每一行 foreach (var line in lines) { // 创建文档 var doc = new Document(); // 添加字段 doc.Add(new Field("content", line, Field.Store.YES, Field.Index.ANALYZED)); // 将文档写入索引 writer.AddDocument(doc); } // 关闭索引写入器 writer.Dispose(); } ``` 3.使用索引 ```csharp using Lucene.Net.Analysis.Standard; using Lucene.Net.QueryParsers; using Lucene.Net.Search; using Lucene.Net.Store; using System.IO; // 使用索引 public void SearchIndex(string indexPath, string queryStr) { // 创建分析器 var analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30); // 创建索引存储目录 var directory = FSDirectory.Open(new DirectoryInfo(indexPath)); // 创建索引搜索器 var searcher = new IndexSearcher(directory, true); // 创建查询解析器 var parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "content", analyzer); // 解析查询字符串 var query = parser.Parse(queryStr); // 执行查询 var hits = searcher.Search(query, null, 10, Sort.RELEVANCE).ScoreDocs; // 遍历查询结果 foreach (var hit in hits) { // 获取文档 var doc = searcher.Doc(hit.Doc); // 输出文档内容 Console.WriteLine(doc.Get("content")); } // 关闭索引搜索器 searcher.Dispose(); } ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值