RavenDb进行全文检索实现及数据统计
2013-02-23 20:49
621 查看
实现目标:项目中使用到了ravendb进行数据的保存,而ravendb对字段的检索是经过lucene进行处理的,而默认的分词器是小写分词器,查找网上的资料看中了中科院的ictclas分词器和盘古分词。选择使用盘古分词和lucene结合,ravendb最新版2.0使用的lucene版本是3.0版本的而网上找到的分词器代码都不能很好的支持3.0,最终选择使用ravendb低版本的方式解决,另外一个问题是引用的json.net版本比较高,解决方式是删除就的高版本引用使用低版本的进行编译。另外一个问题是ravendb中无法直接使用groupby进行数据的分组统计,需要创建一个mapreduce生成统计索引
1,建立分词索引
2,创建统计索引
3,Global.asax中进行配置
1,建立分词索引
public class ByFormNameIndex : AbstractIndexCreationTask<MobileForm> { public ByFormNameIndex() { Map = mobileForms => from form in mobileForms select new { form.FormName, form.BelongTo, form.RequestType }; Analyzers.Add(x => x.FormName, "Lucene.Net.Analysis.PanGu.PanGuAnalyzer,PanGu.Lucene.Analyzer, Version=1.3.1.0, Culture=neutral, PublicKeyToken=null"); Indexes.Add(x => x.FormName, FieldIndexing.Analyzed); Indexes.Add(x => x.BelongTo, FieldIndexing.NotAnalyzed); Indexes.Add(x => x.RequestType, FieldIndexing.NotAnalyzed); } }
2,创建统计索引
public class StatisticResult { public string UserName { get; set; } public int Count { get; set; } } public class GroupUserIndex : AbstractIndexCreationTask<MobileForm, StatisticResult> { public GroupUserIndex() { Map = mobileForms => from form in mobileForms select new StatisticResult { UserName = form.BelongTo, Count = 1 }; Reduce = results => from result in results group result by result.UserName into g select new StatisticResult { UserName = g.Key, Count = g.Sum(x => x.Count) }; } }
3,Global.asax中进行配置
DataDocumentStore.Initialize(); PanGu.Segment.Init(); IndexCreation.CreateIndexes(typeof(ByFormNameIndex).Assembly, DataDocumentStore.Instance); IndexCreation.CreateIndexes(typeof(GroupUserIndex).Assembly, DataDocumentStore.Instance);
相关文章推荐
- MongoDB数据自动同步到ElasticSearch(实现中文全文检索)
- 全文检索、数据挖掘、推荐引擎系列2---异步服务实现
- DataTable数据进行排序、检索、合并、分页、统计 [转]
- asp.net中对DataTable数据进行排序、检索、合并、分页、统计
- 利用decode函数实现按不同的选择条件 对数据进行分组统计
- 全文检索、数据挖掘、推荐引擎系列2---异步服务实现
- NUI的DataGrid中想进行列的数据统计该如何实现?
- 全文检索、数据挖掘、推荐引擎系列2---异步服务实现
- DataTable数据进行排序、检索、合并、分页、统计
- java实现搜索引擎,全文检索,超大数据量查询,lucene
- 检索算法 ---利用二分查找进行数据重复次数统计
- DataTable数据进行排序、检索、合并、分页、统计
- iOS开发:一个高仿美团的团购ipad客户端的设计和实现(功能:根据拼音进行检索并展示数据,离线缓存团购数据,浏览记录与收藏记录的批量删除等)
- asp.net中对DataTable数据进行排序、检索、合并、分页、统计
- DataTable数据进行排序、检索、合并、分页、统计
- asp.net中对DataTable数据进行排序、检索、合并、分页、统计
- Spring Data MongoDB 使用group和unwind实现对数组数据进行简单统计
- 数据在千万级别上进行全文检索有哪些技术?强大的大数据全文索引解决方案-ClouderaSearch
- 全文检索、数据挖掘、推荐引擎系列2---异步服务实现
- 使用Lucene对doc、docx、pdf、txt文档进行全文检索功能的实现