如何使用 .net 代码执行 Amazon Cloud Search?
How to perform Amazon Cloud Search with .net code?
我正在学习 Amazon Cloud Search,但我在 C# 或 Java 中找不到任何代码(虽然我是在 C# 中创建的,但如果我可以在 Java 中获取代码,那么我可以尝试在 C# 中转换)。
这只是我在 C# 中找到的 1 个代码:https://github.com/Sitefinity-SDK/amazon-cloud-search-sample/tree/master/SitefinityWebApp。
这是我在此代码中找到的 1 种方法:
public IResultSet Search(ISearchQuery query)
{
AmazonCloudSearchDomainConfig config = new AmazonCloudSearchDomainConfig();
config.ServiceURL = "http://search-index2-cdduimbipgk3rpnfgny6posyzy.eu-west-1.cloudsearch.amazonaws.com/";
AmazonCloudSearchDomainClient domainClient = new AmazonCloudSearchDomainClient("AKIAJ6MPIX37TLIXW7HQ", "DnrFrw9ZEr7g4Svh0rh6z+s3PxMaypl607eEUehQ", config);
SearchRequest searchRequest = new SearchRequest();
List<string> suggestions = new List<string>();
StringBuilder highlights = new StringBuilder();
highlights.Append("{\'");
if (query == null)
throw new ArgumentNullException("query");
foreach (var field in query.HighlightedFields)
{
if (highlights.Length > 2)
{
highlights.Append(", \'");
}
highlights.Append(field.ToUpperInvariant());
highlights.Append("\':{} ");
SuggestRequest suggestRequest = new SuggestRequest();
Suggester suggester = new Suggester();
suggester.SuggesterName = field.ToUpperInvariant() + "_suggester";
suggestRequest.Suggester = suggester.SuggesterName;
suggestRequest.Size = query.Take;
suggestRequest.Query = query.Text;
SuggestResponse suggestion = domainClient.Suggest(suggestRequest);
foreach (var suggest in suggestion.Suggest.Suggestions)
{
suggestions.Add(suggest.Suggestion);
}
}
highlights.Append("}");
if (query.Filter != null)
{
searchRequest.FilterQuery = this.BuildQueryFilter(query.Filter);
}
if (query.OrderBy != null)
{
searchRequest.Sort = string.Join(",", query.OrderBy);
}
if (query.Take > 0)
{
searchRequest.Size = query.Take;
}
if (query.Skip > 0)
{
searchRequest.Start = query.Skip;
}
searchRequest.Highlight = highlights.ToString();
searchRequest.Query = query.Text;
searchRequest.QueryParser = QueryParser.Simple;
var result = domainClient.Search(searchRequest).SearchResult;
//var result = domainClient.Search(searchRequest).SearchResult;
return new AmazonResultSet(result, suggestions);
}
我已经使用 AWS 控制台在 Amazon Cloud Search 中创建了域,并使用 Amazon 预定义配置选项上传了文档,该选项是 Amazon 提供的用于演示的 movie Imdb json 文件.
但是在这个方法中我不知道如何使用这个方法,比如如果我想搜索 Director 名字那么我该如何传入这个方法因为这个方法参数类型为 ISearchQuery?
我建议使用官方 AWS CloudSearch .NET SDK。您正在查看的库看起来不错(虽然我没有查看任何细节)但正式版本更有可能在发布后立即公开新的 CloudSearch 功能,如果您需要与 AWS 交谈,将得到支持支持等等等等
具体来说,看一下 SearchRequest class -- 它的所有参数都是字符串,所以我认为这避免了你关于 ISearchQuery 的问题。
我无法在 .NET 中找到查询示例,但 this 显示有人使用 AWS .NET SDK 上传文档。它本质上与查询过程相同:创建和配置 Request 对象并将其传递给客户端。
编辑:
由于您仍然很难过,这里有一个例子。请记住,我不熟悉 C# 并且没有尝试 运行 甚至编译它,但我认为它至少应该接近工作。它基于查看 http://docs.aws.amazon.com/sdkfornet/v3/apidocs/
上的文档
// Configure the Client that you'll use to make search requests
string queryUrl = @"http://search-<domainname>-xxxxxxxxxxxxxxxxxxxxxxxxxx.us-east-1.cloudsearch.amazonaws.com";
AmazonCloudSearchDomainClient searchClient = new AmazonCloudSearchDomainClient(queryUrl);
// Configure a search request with your query
SearchRequest searchRequest = new SearchRequest();
searchRequest.Query = "potato";
// TODO Set your other params like parser, suggester, etc
// Submit your request via the client and get back a response containing search results
SearchResponse searchResponse = searchClient.Search(searchRequest);
我正在学习 Amazon Cloud Search,但我在 C# 或 Java 中找不到任何代码(虽然我是在 C# 中创建的,但如果我可以在 Java 中获取代码,那么我可以尝试在 C# 中转换)。
这只是我在 C# 中找到的 1 个代码:https://github.com/Sitefinity-SDK/amazon-cloud-search-sample/tree/master/SitefinityWebApp。
这是我在此代码中找到的 1 种方法:
public IResultSet Search(ISearchQuery query)
{
AmazonCloudSearchDomainConfig config = new AmazonCloudSearchDomainConfig();
config.ServiceURL = "http://search-index2-cdduimbipgk3rpnfgny6posyzy.eu-west-1.cloudsearch.amazonaws.com/";
AmazonCloudSearchDomainClient domainClient = new AmazonCloudSearchDomainClient("AKIAJ6MPIX37TLIXW7HQ", "DnrFrw9ZEr7g4Svh0rh6z+s3PxMaypl607eEUehQ", config);
SearchRequest searchRequest = new SearchRequest();
List<string> suggestions = new List<string>();
StringBuilder highlights = new StringBuilder();
highlights.Append("{\'");
if (query == null)
throw new ArgumentNullException("query");
foreach (var field in query.HighlightedFields)
{
if (highlights.Length > 2)
{
highlights.Append(", \'");
}
highlights.Append(field.ToUpperInvariant());
highlights.Append("\':{} ");
SuggestRequest suggestRequest = new SuggestRequest();
Suggester suggester = new Suggester();
suggester.SuggesterName = field.ToUpperInvariant() + "_suggester";
suggestRequest.Suggester = suggester.SuggesterName;
suggestRequest.Size = query.Take;
suggestRequest.Query = query.Text;
SuggestResponse suggestion = domainClient.Suggest(suggestRequest);
foreach (var suggest in suggestion.Suggest.Suggestions)
{
suggestions.Add(suggest.Suggestion);
}
}
highlights.Append("}");
if (query.Filter != null)
{
searchRequest.FilterQuery = this.BuildQueryFilter(query.Filter);
}
if (query.OrderBy != null)
{
searchRequest.Sort = string.Join(",", query.OrderBy);
}
if (query.Take > 0)
{
searchRequest.Size = query.Take;
}
if (query.Skip > 0)
{
searchRequest.Start = query.Skip;
}
searchRequest.Highlight = highlights.ToString();
searchRequest.Query = query.Text;
searchRequest.QueryParser = QueryParser.Simple;
var result = domainClient.Search(searchRequest).SearchResult;
//var result = domainClient.Search(searchRequest).SearchResult;
return new AmazonResultSet(result, suggestions);
}
我已经使用 AWS 控制台在 Amazon Cloud Search 中创建了域,并使用 Amazon 预定义配置选项上传了文档,该选项是 Amazon 提供的用于演示的 movie Imdb json 文件.
但是在这个方法中我不知道如何使用这个方法,比如如果我想搜索 Director 名字那么我该如何传入这个方法因为这个方法参数类型为 ISearchQuery?
我建议使用官方 AWS CloudSearch .NET SDK。您正在查看的库看起来不错(虽然我没有查看任何细节)但正式版本更有可能在发布后立即公开新的 CloudSearch 功能,如果您需要与 AWS 交谈,将得到支持支持等等等等
具体来说,看一下 SearchRequest class -- 它的所有参数都是字符串,所以我认为这避免了你关于 ISearchQuery 的问题。
我无法在 .NET 中找到查询示例,但 this 显示有人使用 AWS .NET SDK 上传文档。它本质上与查询过程相同:创建和配置 Request 对象并将其传递给客户端。
编辑: 由于您仍然很难过,这里有一个例子。请记住,我不熟悉 C# 并且没有尝试 运行 甚至编译它,但我认为它至少应该接近工作。它基于查看 http://docs.aws.amazon.com/sdkfornet/v3/apidocs/
上的文档// Configure the Client that you'll use to make search requests
string queryUrl = @"http://search-<domainname>-xxxxxxxxxxxxxxxxxxxxxxxxxx.us-east-1.cloudsearch.amazonaws.com";
AmazonCloudSearchDomainClient searchClient = new AmazonCloudSearchDomainClient(queryUrl);
// Configure a search request with your query
SearchRequest searchRequest = new SearchRequest();
searchRequest.Query = "potato";
// TODO Set your other params like parser, suggester, etc
// Submit your request via the client and get back a response containing search results
SearchResponse searchResponse = searchClient.Search(searchRequest);