如何解决 Azure 搜索中的性能问题
How to fix performance issue in azure search
我正在我的应用程序中实施 azure 搜索以提供 google、big 和 amazon 等自动建议功能。我已经使用下面 URL.All 实现了相同的可用 github 代码,工作正常但每个句子的结果在超过 1.5 秒的时间内得到结果。
https://github.com/Azure-Samples/search-dotnet-getting-started/tree/master/DotNetHowToAutocomplete
目前我正在使用两个索引进行搜索并在基本层中创建。下面是代码
public ActionResult Suggest(bool highlights, bool fuzzy, string term)
{
InitSearch();
// Call suggest API and return results
SuggestParameters sp = new SuggestParameters()
{
UseFuzzyMatching = fuzzy,
Top = 5,
Filter="name eq 'testid'",
OrderBy=new List<string>() { "Date desc"}
};
if (highlights)
{
sp.HighlightPreTag = "<b>";
sp.HighlightPostTag = "</b>";
}
DocumentSuggestResult suggestResult = _indexClient1.Documents.Suggest(term, "index1",sp);
if (suggestResult.Results.Count<5)
{
SuggestParameters sp2 = new SuggestParameters()
{
UseFuzzyMatching = fuzzy,
Top = 5- suggestResult.Results.Count,
Filter = "Product eq 'PAAS'",
OrderBy = new List<string>() { "Count desc" }
};
if (highlights)
{
sp2.HighlightPreTag = "<b>";
sp2.HighlightPostTag = "</b>";
}
DocumentSuggestResult suggestResult2= _indexClient2.Documents.Suggest(term, "index2", sp2);
suggestResult.Results = suggestResult.Results.Union(suggestResult2.Results).Distinct().ToList();
// final = suggestResult.Results.GroupBy(s => s.Text, StringComparer.CurrentCultureIgnoreCase).ToList();
}
// Convert the suggest query results to a list that can be displayed in the client.
List<string> suggestions = suggestResult.Results.Select(x => x.Text).Distinct().ToList();
return new JsonResult
{
JsonRequestBehavior = JsonRequestBehavior.AllowGet,
Data = suggestions
};
}
测试它 - 当我输入任何单词时,它会花费太多时间来填充结果,大约需要 1.5 到 1.8 秒,它的工作方式与其他网络应用程序搜索框一样。
时间我正在使用 chrome 浏览器的检查元素进行检查。附上截图。see screenshot
求推荐。
我在另一个 post 上回答了类似的问题:
最主要的是,您不应该使用 Chrome 计时器来衡量 azure 搜索的性能。使用您收到的 HTTP 响应的 "elapsed-time" 字段(取多次调用的平均值),因为它准确地告诉您从 Azure 搜索获取结果所花费的时间。 chrome 计时器可能会受到您的 network/machine 配置的影响。如果这没有帮助,您可以按照我在上面链接的 post 中建议的其他提示进行操作。
我正在我的应用程序中实施 azure 搜索以提供 google、big 和 amazon 等自动建议功能。我已经使用下面 URL.All 实现了相同的可用 github 代码,工作正常但每个句子的结果在超过 1.5 秒的时间内得到结果。 https://github.com/Azure-Samples/search-dotnet-getting-started/tree/master/DotNetHowToAutocomplete
目前我正在使用两个索引进行搜索并在基本层中创建。下面是代码
public ActionResult Suggest(bool highlights, bool fuzzy, string term)
{
InitSearch();
// Call suggest API and return results
SuggestParameters sp = new SuggestParameters()
{
UseFuzzyMatching = fuzzy,
Top = 5,
Filter="name eq 'testid'",
OrderBy=new List<string>() { "Date desc"}
};
if (highlights)
{
sp.HighlightPreTag = "<b>";
sp.HighlightPostTag = "</b>";
}
DocumentSuggestResult suggestResult = _indexClient1.Documents.Suggest(term, "index1",sp);
if (suggestResult.Results.Count<5)
{
SuggestParameters sp2 = new SuggestParameters()
{
UseFuzzyMatching = fuzzy,
Top = 5- suggestResult.Results.Count,
Filter = "Product eq 'PAAS'",
OrderBy = new List<string>() { "Count desc" }
};
if (highlights)
{
sp2.HighlightPreTag = "<b>";
sp2.HighlightPostTag = "</b>";
}
DocumentSuggestResult suggestResult2= _indexClient2.Documents.Suggest(term, "index2", sp2);
suggestResult.Results = suggestResult.Results.Union(suggestResult2.Results).Distinct().ToList();
// final = suggestResult.Results.GroupBy(s => s.Text, StringComparer.CurrentCultureIgnoreCase).ToList();
}
// Convert the suggest query results to a list that can be displayed in the client.
List<string> suggestions = suggestResult.Results.Select(x => x.Text).Distinct().ToList();
return new JsonResult
{
JsonRequestBehavior = JsonRequestBehavior.AllowGet,
Data = suggestions
};
}
测试它 - 当我输入任何单词时,它会花费太多时间来填充结果,大约需要 1.5 到 1.8 秒,它的工作方式与其他网络应用程序搜索框一样。
时间我正在使用 chrome 浏览器的检查元素进行检查。附上截图。see screenshot
求推荐。
我在另一个 post 上回答了类似的问题:
最主要的是,您不应该使用 Chrome 计时器来衡量 azure 搜索的性能。使用您收到的 HTTP 响应的 "elapsed-time" 字段(取多次调用的平均值),因为它准确地告诉您从 Azure 搜索获取结果所花费的时间。 chrome 计时器可能会受到您的 network/machine 配置的影响。如果这没有帮助,您可以按照我在上面链接的 post 中建议的其他提示进行操作。