我不清楚:制作索引时是否必须使用雪球分析仪?
var Client = new ElasticClient(Settings);
Client.CreateIndex("pictures", i => i
.Settings(st => st
.Analysis(a => a
.Analyzers(ad => ad
.Snowball("snowball", s => s.Language(SnowballLanguage.English))
)
)
)
);
还是在搜索时?
var queryResults = Client.Search<PictureIndex>(s => s
.From(0).Size(10)
.Query(q=>q
.QueryString(qs=>qs
.Analyzer("snowball")
.Query("my test string")
)
)
);
此代码未返回预期结果。
例如,如果我有:
在我的索引中,如果我搜索西红柿,我希望能找到2个结果,但事实并非如此。
我正在尝试仅使用英文,不区分大小写,词干搜索,并增加模糊性以适应拼写错误。
(作为奖励,我希望能够提交同义词列表)
编辑: 这是我拥有的测试代码,但是我认为我误会了如何输入同义词。该代码将不返回任何匹配项。
public static class Program
{
public class IndexData
{
public int Id { get; set; }
public string Text { get; set; }
}
public static void Main()
{
var Settings = new ConnectionSettings(new Uri("http://elasticsearch:9200")).DefaultIndex("testindex");
var A = new List<IndexData>
{
new IndexData { Id = 11, Text = "I like red, green and blue. But also cookies and candies" },
new IndexData { Id = 12, Text = "There is a red cookie on the shelf" },
new IndexData { Id = 13, Text = "Blue candies are my favorite" }
};
var Client = new ElasticClient(Settings);
var D = Client.DeleteIndexAsync("testindex").Result;
var U = Client.CreateIndex("testindex", i => i
.Settings(s => s
.Analysis(a => a
.CharFilters(cf => cf
.Mapping("my_char_filter", m => m
.Mappings("Blue => blue", "Red => red", "Green => green")
)
)
.TokenFilters(tf => tf
.Synonym("my_synonym", sf => sf
.Synonyms("red, blue")
.Synonyms("green, blue")
)
)
.Analyzers(an => an
.Custom("my_analyzer", ca => ca
.Tokenizer("standard")
.CharFilters("my_char_filter")
.Filters("lowercase", "stop", "my_synonym")
)
)
)
)
);
var R = Client.IndexDocument(A[0]);
R = Client.IndexDocument(A[1]);
R = Client.IndexDocument(A[2]);
var Articles = Client.Search<IndexData>(s => s
.From(0)
.Size(1000)
.Analyzer("my_analyzer")
.Query(q => q.Fuzzy(fz => fz.Field("text").Value("blue").MaxExpansions(2)))
);
var Documents = Articles.Documents;
}
}
我要实现的是文本搜索,其中:
我必须承认,尽管浏览了文档,但我对整个系统的术语和流程感到非常困惑。另一个问题是,Web上的一半示例都无法编译,因为看起来API有时已更改。