Ravendb如何使用Map Reducer

问题描述

我有一个3列的表格ID(标题,部分)。

  1. 我想要标题列中的唯一值。 (我通过Map Reduce索引获取)
  2. 现在用户将从下拉菜单中选择“标题”,然后要获取将按标题匹配的“唯一”部分(如何获取与“标题”匹配的唯一部分。我使用了Distinct但性能下降)
  3. 然后用户将通过匹配标题和部分来选择我要获取唯一标题的部分

我的索引

 class UniqueActIndex : AbstractIndexCreationTask<ActRuleModel,UniqueActIndex.Result> {
    public class Result {
        public string ActTitle { get; set; }
    }

    public UniqueActIndex() {
        Map = orders => from o in orders
                        select new Result {
                            ActTitle = Regex.Replace(o.ActTitle,@"[^0-9a-zA-Z]+"," ")
                        };

        Reduce = results => from r in results
                            group r by r.ActTitle into g
                            select new Result {
                                ActTitle = g.Key
                            };



    }
}

}

解决方法

Map-Reduce索引通常用于聚合数据(在建立索引时),以后可以查询该数据。
参见https://demo.ravendb.net/demos/csharp/static-indexes/map-reduce-index

您还可以定义常规Map Index并获取为索引生成的索引唯一'条款
参见https://ravendb.net/docs/article-page/5.0/Csharp/client-api/operations/maintenance/indexes/get-terms

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...