已经在我的网站上实现了Bing Web Search,但我想限制随机结果并使搜索更加精确。
这里是可接受的搜索方案。
www.stackoverflow.com
www.stackoverflow.com/language/foo/bar
的搜索,然后显示相同域下的其他站点的搜索这里是代码
public static async Task<SearchResultModel> WebResultsWithCountAndOffset(WebSearchClient client, string searchQuery,int pageNumber)
{
SearchResultModel model = new SearchResultModel();
List<SearchResult> searchResults = new List<SearchResult>();
try
{
var offset = (pageNumber-1) * 20;
var webData = await client.Web.SearchAsync(query: searchQuery.Replace(' ', '+') + " domain:stackoverflow.com OR site:www.stackoverflow.com/language/foo/bar", offset: offset, count: 20, textFormat: "HTML", textDecorations: true, countryCode: "US");
if (webData?.WebPages?.Value?.Count > 0)
{
model.totalCount = webData.WebPages.TotalEstimatedMatches;
var WebPagesResult = webData.WebPages.Value.ToList();
var ds = webData.SpellSuggestions;
foreach(var d in WebPagesResult)
{
SearchResult result = new SearchResult();
result.PageURL = d.Url;
result.Snippet = d.Snippet;
result.Title = d.Name;
searchResults.Add(result);
}
model.list = searchResults;
}
else
{
Console.WriteLine("Didn't see any Web data..");
}
}
catch (Exception ex)
{
Console.WriteLine("Encountered exception. " + ex.Message);
}
return model;
}
我可以看到输入的数据,但对我来说似乎无关紧要。域限制效果很好,但是结果的顺序和精度仍然无关紧要。请注意,我所指的域可以索引成千上万的页面,但是精度看起来完全偏离了轨道。