Ejemplo n.º 1
0
 private static HighlightDescriptor <Person> GetHLDescriptor(HighlightDescriptor <Person> hl, SearchParam p)
 {
     return(hl.PreTags("<b>")
            .PostTags("</b>")
            .Fields(f => f.Field("company.std"),
                    f => f.Field("company.max"),
                    f => f.Field(fld => fld.company)));
 }
Ejemplo n.º 2
0
 private IHighlight highlightSelector(HighlightDescriptor <post> arg)
 {
     return(arg
            .PreTags(Highlight_Token)
            .PostTags(Highlight_Token)
            .Encoder(HighlighterEncoder.Default)
            .Fields(
                fs => fs.Field(p => p.body),
                fs => fs.Field(p => p.title)
                ));
 }
 protected override HighlightDescriptor <BookIndexItem> Highlight(
     HighlightDescriptor <BookIndexItem> highlight)
 => highlight
 .PreTags(PreHighlightTag)
 .PostTags(PostHighlightTag)
 .Fields(
     fs => fs.Field(f => f.Title),
     fs => fs.Field(f => f.Description),
     fs => fs.Field(f => f.Authors),
     fs => fs.Field(f => f.Tags),
     fs => fs.Field(f => f.DatePublication),
     fs => fs.Field(f => f.Issue),
     fs => fs.Field(f => f.Publisher),
     fs => fs.Field(f => f.Language));
Ejemplo n.º 4
0
        public virtual async Task <ISearchResponse <T> > SearchAsync <T, TKey>(string indexName, SearchDescriptor <T> query, int skip, int size, string[] includeFields = null,
                                                                               string preTags   = "<strong style=\"color: red;\">", string productTags = "</strong>",
                                                                               bool disableHigh = false, params string[] highField) where T : ElasticEntity <TKey>
        {
            query.Index(indexName);
            var highdes = new HighlightDescriptor <T>();

            if (disableHigh)
            {
                preTags     = "";
                productTags = "";
            }
            highdes.PreTags(preTags).PostTags(productTags);

            var ishigh = highField != null && highField.Length > 0;

            var hfs = new List <Func <HighlightFieldDescriptor <T>, IHighlightField> >();

            //Pagination
            query.Skip(skip).Take(size);
            //Keyword highlighting
            if (ishigh)
            {
                foreach (var s in highField)
                {
                    hfs.Add(f => f.Field(s));
                }
            }

            highdes.Fields(hfs.ToArray());
            query.Highlight(h => highdes);
            if (includeFields != null)
            {
                query.Source(ss => ss.Includes(ff => ff.Fields(includeFields.ToArray())));
            }


            var data     = JsonConvert.SerializeObject(query);
            var response = await ElasticSearchClient.SearchAsync <T>(query);


            return(response);
        }
        /// <summary>
        /// search
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <typeparam name="TKey"></typeparam>
        /// <param name="indexName"></param>
        /// <param name="query"></param>
        /// <param name="skip">skip num</param>
        /// <param name="size">return document size</param>
        /// <param name="includeFields">return fields</param>
        /// <param name="preTags">Highlight tags</param>
        /// <param name="postTags">Highlight tags</param>
        /// <param name="disableHigh"></param>
        /// <param name="highField">Highlight fields</param>
        /// <returns></returns>
        public virtual async Task <ISearchResponse <T> > SearchAsync <T, TKey>(string indexName, SearchDescriptor <T> query,
                                                                               int skip, int size, string[] includeFields = null,
                                                                               string preTags = "<strong style=\"color: red;\">", string postTags = "</strong>", bool disableHigh = false,
                                                                               params string[] highField) where T : class
        {
            query.Index(indexName);
            var highlight = new HighlightDescriptor <T>();

            if (disableHigh)
            {
                preTags  = "";
                postTags = "";
            }

            highlight.PreTags(preTags).PostTags(postTags);

            var isHigh = highField != null && highField.Length > 0;

            var hfs = new List <Func <HighlightFieldDescriptor <T>, IHighlightField> >();

            //分页
            query.Skip(skip).Take(size);
            //关键词高亮
            if (isHigh)
            {
                foreach (var s in highField)
                {
                    hfs.Add(f => f.Field(s));
                }
            }

            highlight.Fields(hfs.ToArray());
            query.Highlight(h => highlight);
            if (includeFields != null)
            {
                query.Source(ss => ss.Includes(ff => ff.Fields(includeFields.ToArray())));
            }
            var response = await _esClient.SearchAsync <T>(query);

            return(response);
        }
Ejemplo n.º 6
0
 private HighlightDescriptor <T> Get_HL(HighlightDescriptor <T> hl, QueryDes qd) => hl
 .PreTags(qd.HLPreTag)
 .PostTags(qd.HLPostTag)
 .Fields(
     f => f.Field("oc_code"),
     f => f.Field("oc_number")
     );
Ejemplo n.º 7
0
 private static HighlightDescriptor <T> HL_Create <T>(HighlightDescriptor <T> hl, IEnumerable <string> names) where T : class => hl
 .PreTags("<font color=\"red\">")
 .PostTags("</font>")
 .Fields(names.Select <string, Func <HighlightFieldDescriptor <T>, IHighlightField> >(n => f => f.Field(n)).ToArray());