使用EdgeNGram使用ElasticSearch进行精确搜索

时间:2017-03-14 13:19:36

标签: c# elasticsearch nest

我使用弹性来搜索希腊语和拉丁语。我的主要问题是我无法进行精确搜索。我在索引时使用edgeNgram过滤器,但我想在搜索时控制其最小值和最大值例如,如果我键入“titanox”,我将首先获得“ΤΙΤΑΝΙΟΥ”,其次是“TITANOX”。这是我的索引创建:

<div class="container">
        <div class="row">
            <div class="col-md-6 content">
                <h1>Meet BestApp</h1>
                <h1>The new world for chat</h1>
                <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quis deleniti cumque odit atque molestiae totam facere aliquam sed cum perspiciatis quam, at sequi, corporis distinctio. Fugit nam, nesciunt quaerat pariatur.</p>
            </div>
            <div class="col-md-6 form">
                <h2>Sign Up!</h2>
                <form action="post">
                    <input type="text" placeholder="Your Name">
                    <br>
                    <input type="text" placeholder="Email Adress*">
                    <br>
                    <input type="text" placeholder="Phone Number">
                    <br>
                    <p>
                        <input type="checkbox" id="cbox1">
                        <label for="cbox1">I agree to the terms and conditions</label>
                    </p>
                </form>
            </div>
        </div>
    </div>

在这里我的搜索

var response = client.CreateIndex(index, s => s
            .Settings(s1 => s1
.NumberOfShards(5)
.NumberOfReplicas(5)
.Analysis(a => a.TokenFilters(t => t.IcuTransform("greeklatin", it => it.Id("Greek-Latin; NFD; [:Nonspacing Mark:] Remove; NFC")//
.Direction(IcuTransformDirection.Forward)) //
.IcuTransform("latingreek", lg => lg.Id("Greek-Latin; NFD; [:Nonspacing Mark:] Remove; NFC")
.Direction(IcuTransformDirection.Reverse))
.EdgeNGram("greekedge", ed => ed.MaxGram(7)
.MinGram(1)
.Side(EdgeNGramSide.Front))
.Stop("greekstop", sw => sw.StopWords())
.Lowercase("greeklowercase", gl => gl.Language(Language.Greek.ToString()))
.KeywordMarker("greekkeywords", gk => gk.Keywords(""))
.Stemmer("greekstemmer", gs => gs.Language(Language.Greek.ToString())))
.Analyzers(a1 => a1
.Custom("greek", t => t.Tokenizer("standard")
.Filters("greekedge", "greekstop", "greeklowercase", "greekkeywords", "greekstemmer", "greeklatin")))))
.Mappings(m => m.Map(type, mt => mt.Properties(c => c.Text(c1 => c1.Name("id").Analyzer("greek"))
.Text(c2 => c2.Name("brand").Analyzer("greek"))
.Text(c3 => c3.Name("service").Analyzer("greek"))
.Text(c4 => c4.Name("servicegroupdesc").Analyzer("greek"))
.Text(c5 => c5.Name("servicecategorydesc).Analyzer("greek"))
.Text(c6 => c6.Name("partscategory").Analyzer("greek"))
.Text(c7 => c7.Name("partsid").Analyzer("greek"))
.Text(c8 => c8.Name("partsdesc").Analyzer("greek"))))));

1 个答案:

答案 0 :(得分:0)

可能有用的解决方案是在此查询中添加一个新查询,用于提升用户输入的字词。这可以实现更精确的搜索。