利用Lucene.Net进行文档递归查询
来源:互联网 发布:大数据认证有多少 编辑:程序博客网 时间:2024/05/29 18:18
如何在项目中分析建立索引
1.添加引用lucene.net dll和名字空间
using Lucene.Net.Analysis.Standard;
using Lucene.Net.Documents;
using Lucene.Net.Index;
using Lucene.Net.QueryParsers;
using Lucene.Net.Search;
using ClassLibrary1.Icons;
using ClassLibrary1.Parsing;
2.在page load事件中声明保存索引文件的路径.程序会在页面生存周期内记住文件的路径.然后调用IndexBuilt和Search函数来实现查询.
this.pathIndex = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "test");
IndexBuilt();
search();
3.以下是IndexBuilt函数的内容.他将递归的添加文件夹.然后索引目录信息
private void IndexBuilt()
{
// 以下的代码在磁盘上创建一个新的索引.
indexWriter = new IndexWriter(this.pathIndex, new StandardAnalyzer(), true);
bytesTotal = 0;
countTotal = 0;
countSkipped = 0;
DirectoryInfo di = new DirectoryInfo(@"C:/Inetpub/wwwroot/test/Resumes");
DateTime start = DateTime.Now;
addFolder(di);
string summary = String.Format("Done. Indexed {0} files ({1} bytes). Skipped {2} files.", countTotal, bytesTotal, countSkipped);
summary += String.Format(" Took {0}", (DateTime.Now - start));
indexWriter.Optimize();
indexWriter.Close();
}
4.search函数
private void search()
{
DateTime start = DateTime.Now;
try
{
searcher = new IndexSearcher(this.pathIndex);
}
catch (IOException ex)
{
MessageBox.Show("The index doesn't exist or is damaged. Please rebuild the index./r/n/r/nDetails:/r/n" + ex.Message);
return;
}
Query query = QueryParser.Parse("test", "text", new StandardAnalyzer());
Hits hits = searcher.Search(query);
for (int i = 0; i < hits.Length(); i++)
{
// 从索引获取文档
Document doc = hits.Doc(i);
// 在结果集里创建新的行
string filename = doc.Get("title");
string path = doc.Get("path");
string folder = Path.GetDirectoryName(path);
DirectoryInfo di = new DirectoryInfo(folder);
str += filename + ","
}
searcher.Close();
Response.Write(str);
string searchReport = String.Format("Search took {0}. Found {1} items.", (DateTime.Now - start), hits.Length());
}
http://www.dotlucene.net/
1.添加引用lucene.net dll和名字空间
using Lucene.Net.Analysis.Standard;
using Lucene.Net.Documents;
using Lucene.Net.Index;
using Lucene.Net.QueryParsers;
using Lucene.Net.Search;
using ClassLibrary1.Icons;
using ClassLibrary1.Parsing;
2.在page load事件中声明保存索引文件的路径.程序会在页面生存周期内记住文件的路径.然后调用IndexBuilt和Search函数来实现查询.
this.pathIndex = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "test");
IndexBuilt();
search();
3.以下是IndexBuilt函数的内容.他将递归的添加文件夹.然后索引目录信息
private void IndexBuilt()
{
// 以下的代码在磁盘上创建一个新的索引.
indexWriter = new IndexWriter(this.pathIndex, new StandardAnalyzer(), true);
bytesTotal = 0;
countTotal = 0;
countSkipped = 0;
DirectoryInfo di = new DirectoryInfo(@"C:/Inetpub/wwwroot/test/Resumes");
DateTime start = DateTime.Now;
addFolder(di);
string summary = String.Format("Done. Indexed {0} files ({1} bytes). Skipped {2} files.", countTotal, bytesTotal, countSkipped);
summary += String.Format(" Took {0}", (DateTime.Now - start));
indexWriter.Optimize();
indexWriter.Close();
}
4.search函数
private void search()
{
DateTime start = DateTime.Now;
try
{
searcher = new IndexSearcher(this.pathIndex);
}
catch (IOException ex)
{
MessageBox.Show("The index doesn't exist or is damaged. Please rebuild the index./r/n/r/nDetails:/r/n" + ex.Message);
return;
}
Query query = QueryParser.Parse("test", "text", new StandardAnalyzer());
Hits hits = searcher.Search(query);
for (int i = 0; i < hits.Length(); i++)
{
// 从索引获取文档
Document doc = hits.Doc(i);
// 在结果集里创建新的行
string filename = doc.Get("title");
string path = doc.Get("path");
string folder = Path.GetDirectoryName(path);
DirectoryInfo di = new DirectoryInfo(folder);
str += filename + ","
}
searcher.Close();
Response.Write(str);
string searchReport = String.Format("Search took {0}. Found {1} items.", (DateTime.Now - start), hits.Length());
}
http://www.dotlucene.net/
- 利用Lucene.Net进行文档递归查询
- 利用Lucene.Net进行文档递归查询
- lucene利用sort对查询结果进行排序示例
- lucene利用BooleanQuery进行多个Query组合查询
- 利用Lucene.net搜索引擎进行多条件搜索的做法
- 利用Lucene.net搜索引擎进行多条件搜索的做法
- 利用Lucene.net搜索引擎进行多条件搜索的做法
- 利用Lucene.net搜索引擎进行多条件搜索的做法
- 利用Lucene.net搜索引擎进行多条件搜索的做法
- Vb.net 利用数组进行组合查询
- lucene.net查询条件
- 利用LUCENE求相似文档
- lucene.net 如何新增文档/?
- Vb.net下,利用数组进行“组合”查询
- asp.net 利用多表联合查询进行汇总统计
- 关于lucene.net的查询
- Lucene.Net多字段查询
- Lucene使用项向量进行模糊查询
- JBoss, Tomcat等WEB服务器的优化策略
- SharpMimeTools
- 用SharpZipLib(#ZipLib)压缩MemoryStream
- 一个在.net平台上易用的开源制图组件
- 在.net中使用MagicAjax.NET
- 利用Lucene.Net进行文档递归查询
- 如何使用log4net
- dotnetopenmail使用介绍
- 最近用到的Delphi组件
- asp.net 2.0中的全球化与本地化
- 局域网内用ServerU建立ftp服务器
- 我的博客开张了!
- 在asp.net 2.0中使用主题
- 强名称的原理(strong name)