尝试使用Nest搜索文本时遇到代码错误 “无法将类型”string“隐式转换为”System.Collections.Generic.IEnumerable”
class Program
{
static void Main(string[] args)
{
var settings = new ConnectionSettings(new Uri("http://localhost:9200"))
.DefaultIndex("my_index");
var client = new ElasticClient(settings);
var text = "testinsg, test, my testing";
var analyzeResponse = client.Indices.Analyze(new AnalyzeRequest
{
// error occurred here when trying to pass the value of the variable text
Text = text,
Analyzer = "standard",
Tokenizer = "standard"
});
var stemmedWords = analyzeResponse.Tokens.Select(t => t.Token);
var stemCounts = stemmedWords
.GroupBy(w => new Stemmer().Stem(w))
.Select(g => new { Stem = g.Key, Count = g.Count() })
foreach (var stemCount in stemCounts)
{
Console.WriteLine($"Stem: {stemCount.Stem}, Count: {stemCount.Count}");
}
}
}
1条答案
按热度按时间oprakyz71#
看起来
Text
是IEnumerable<string>
,所以只需将字符串 Package 到集合中,例如array: