Giter Site home page Giter Site logo

Comments (5)

Mpdreamz avatar Mpdreamz commented on May 17, 2024

Here is an example how you can do this:

  var result = this._elasticClient.Search<MyDTO>(s =>  s
     .From(page * searchDescriptor.PageSize)
     .Take(searchDescriptor.PageSize)
     .Highlight(h => h
       .PreTags("<mark>")
       .PostTags("</mark>")
       .OnFields(
         f => f.OnField(a => a.Title).NumberOfFragments(0),
         f => f.OnField(a => a.Description).FragmentSize(450).BoundaryMaxSize(40)
       )
       .Encoder("html")
     )
     .Query(... Fuzzy here ...)
  );

Elasticsearch wont return the highlights in place so we have to get to them differently.

Because i cannot guess which highlight maps where in your DTO (if you even want this that is), you have to loop over result.DocumentsWithMetaData. Which gives you a Hit<MyDto> object which has a Value property which is the mapped MyDto object and a Highlight property which has all the highlights for that hit.

from elasticsearch-net.

aqbjteddy avatar aqbjteddy commented on May 17, 2024

Hi, I encountered a simple problem

public class Post{
    public string Title{get;set;}
    pulibc string Keywords{get;set;}
}
                    s.Query(q => q
                        .QueryString(qs => qs
                            .Query("is")
                            .OnField(f => f.Keywords)
                        )
                    );

I can't find the record titled "This" ?

and how to let the title to be "This"?

please note that the search is based on another field(Keywords)

Thanks

from elasticsearch-net.

Mpdreamz avatar Mpdreamz commented on May 17, 2024

Hi this is more of a general elasticsearch question, your general best bet to get those answered is the elasticsearch mailing list. The reason it wont find it is because "this" is not broken in to "th" and "is" by default so the terms index dont match "is". Also in general lucene only supports leading wildcards so "th_" will work but "_is" won't.

from elasticsearch-net.

aqbjteddy avatar aqbjteddy commented on May 17, 2024

Hi, this is my post class below

    public class ProductPost
    {
        public int Id { get; set; }

        [ElasticProperty(OmitNorms = true, Index = FieldIndexOption.not_analyzed)]
        public string Title { get; set; }

        [ElasticProperty(Index = FieldIndexOption.analyzed, Analyzer = "smartcn")]
        public string Keyword
        {
            get;
            private set;
        }
    }

and here is index code

this.Client.IndexManyAsync(productList);

search

                  s.Query(q => q
                        .QueryString(qs => qs
                            .Query(query)
                            .OnField(f => f.Keyword)
                            .Analyzer("smartcn")
                        )
                    );

but i still can not find the real products.

from elasticsearch-net.

aqbjteddy avatar aqbjteddy commented on May 17, 2024

This is a question of how to cut words in elasticsearch, thank you @Mpdreamz

from elasticsearch-net.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.