2017-11-21 1 views
0

자동 완성 기능을 만들려고 노력 중이지만 작동하는 것 같지만 사용자 정의 분석기가 때때로 이상한 결과를 반환한다는 것을 알게됩니다. 내가NEST 사용자 정의 분석기 NGram이 올바른 결과를 반환하지 않습니다.

127.0.0.1:9200/default-index/_analyze?text=dan&analyzer=auto-complete 

그때 내가 그래서 위의 3 내 MinGram을 설정, 내가 설정을 확실히 잘못 실종되어

{ 
    "tokens": [ 
     { 
      "token": "d", 
      "start_offset": 0, 
      "end_offset": 3, 
      "type": "<ALPHANUM>", 
      "position": 0 
     }, 
     { 
      "token": "da", 
      "start_offset": 0, 
      "end_offset": 3, 
      "type": "<ALPHANUM>", 
      "position": 0 
     }, 
     { 
      "token": "a", 
      "start_offset": 0, 
      "end_offset": 3, 
      "type": "<ALPHANUM>", 
      "position": 0 
     }, 
     { 
      "token": "an", 
      "start_offset": 0, 
      "end_offset": 3, 
      "type": "<ALPHANUM>", 
      "position": 0 
     }, 
     { 
      "token": "n", 
      "start_offset": 0, 
      "end_offset": 3, 
      "type": "<ALPHANUM>", 
      "position": 0 
     } 
    ] 
} 

를 얻을 호출하는 경우

var response = this.client.CreateIndex(
        ElasticConfig.IndexName, 
        index => index 
         .Mappings(
          ms => ms.Map<EmployeeDocument>(
           m => m.Properties(
            p => p 
             .Text(t => t.Name(n => n.EmpFirstName).Analyzer("auto-complete").Fields(ff => ff.Keyword(k => k.Name("keyword")))) 
             .Text(t => t.Name(n => n.pkEmpID).Analyzer("auto-complete").Fields(ff => ff.Keyword(k => k.Name("keyword")))) 
             .Text(t => t.Name(n => n.Description).Analyzer("auto-complete").Fields(ff => ff.Keyword(k => k.Name("keyword"))))))) 
          .Settings(
          f => f.Analysis(
            analysis => analysis 
            .Tokenizers(
             tokenizers => 
             tokenizers 
              .EdgeNGram("ngram", t => t.MinGram(3).MaxGram(5))) 
            .Analyzers(
             analyzers => analyzers.Custom(
              "auto-complete", 
              a => a.Filters(new List<string> { "lowercase", "ngram" }).Tokenizer("standard")))))); 

?

답변

0

좋아, 그럼 내가 토큰을 만든 방법을 바꿨어. Tokenizers 대신 TokenFilters을 사용하는 방법에 유의하십시오.

var response = this.client.CreateIndex(
        ElasticConfig.IndexName, 
        index => index.Mappings(
         ms => ms.Map<EmployeeDocument>(
          m => m.Properties(
           p => p 
            .Text(t => t.Name(n => n.EmpFirstName).Analyzer("auto-complete").Fields(ff => ff.Keyword(k => k.Name("keyword")))) 
            .Text(t => t.Name(n => n.pkEmpID).Analyzer("auto-complete-id").Fields(ff => ff.Keyword(k => k.Name("keyword")))) 
            .Text(t => t.Name(n => n.Description).Analyzer("auto-complete").Fields(ff => ff.Keyword(k => k.Name("keyword"))))))) 
         .Settings(f => f.Analysis(
          analysis => analysis 
           .Analyzers(
            analyzers => analyzers 
             .Custom("auto-complete", a => a.Tokenizer("standard").Filters("lowercase", "auto-complete-filter")) 
             .Custom("auto-complete-id", a => a.Tokenizer("standard").Filters("lowercase", "auto-complete-id-filter"))) 
             .TokenFilters(tokenFilter => tokenFilter 
                    .EdgeNGram("auto-complete-filter", t => t.MinGram(3).MaxGram(5)) 
                    .EdgeNGram("auto-complete-id-filter", t => t.MinGram(1).MaxGram(5)))))); 
관련 문제