Exemple #1
0
        private static void Main(string[] args)
        {
            #region 初始化

            var paths = new List <string>
            {
                "Config/moduleConfig.json",
                "Config/commonConfig.json"
            };
            BootstrapWarpper.InitiateConfig(paths);

            #endregion 初始化

            //初始化service
            var service = BootstrapWarpper.IocManager.Resolve <IContentService>();

            //初始化预置数据
            Contents = InitData();
            //赋值
            //service.BlukIndex(Contents, "content_test");

            //复杂查询
            var request = new RequestContentDto
            {
                PageSize  = 5,
                SearchKey = "赛乐"
            };

            #region 高亮

            var highlightConfig = new HighlightConfig <Content>
            {
                Tag = "i",
                HighlightConfigExpression = new List <Expression <Func <Content, object> > >
                {
                    x => x.Title
                }
            };
            request.HighlightConfigEntity = highlightConfig;

            var data = service.Search(request.CurrentIndex, request.PageSize, request);

            //删除
            service.DeleteByQuery("123852");

            //更新
            service.UpdateByKey("123754", new Content
            {
                Key = "123"
            });

            #endregion 高亮
        }
Exemple #2
0
        private void ExecuteAddColorCommand(object obj)
        {
            var rowColorItem = new HighlightConfig
            {
                Key             = Guid.NewGuid().ToString(),
                BackgroundColor = Background,
                ForegroundColor = Foreground,
                RowQueryText    = RowQueryText
            };

            RowColorItems.Add(rowColorItem);

            SelectedRowColorItem = rowColorItem;

            OnSelectedHighlightChanged(HighlightOption.None);
        }
Exemple #3
0
        /// <summary>
        ///     初始化高亮配置
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="searchRequest"></param>
        /// <param name="config"></param>
        /// <returns></returns>
        public static ISearchRequest InitHighlight <T>(this ISearchRequest searchRequest, HighlightConfig <T> config)
        {
            if (config == null)
            {
                return(searchRequest);
            }
            var dic = new Dictionary <Field, IHighlightField>();

            foreach (var expression in config.HighlightConfigExpression)
            {
                var propertySearchName = (PropertySearchNameAttribute)
                                         LoadAttributeHelper.LoadAttributeByType <T, PropertySearchNameAttribute>(expression);

                dic.Add(propertySearchName.Name, new HighlightField());
            }
            searchRequest.Highlight = new Highlight
            {
                PreTags  = new[] { $"<{config.Tag}>" },
                PostTags = new[] { $"</{config.Tag}>" },
                Encoder  = HighlighterEncoder.Html,
                Fields   = dic
            };
            return(searchRequest);
        }