gpt4 book ai didi

java - 如何使用 .net 代码执行 Amazon Cloud Search?

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:18:13 26 4
gpt4 key购买 nike

我正在学习 Amazon Cloud Search,但我找不到任何 C# 或 Java 代码(尽管我是用 C# 创建的,但如果我能获得 Java 代码,那么我可以尝试在 C# 中转换)。

这只是我在 C# 中找到的 1 个代码:https://github.com/Sitefinity-SDK/amazon-cloud-search-sample/tree/master/SitefinityWebApp .

这是我在这段代码中找到的一种方法:

 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 预定义配置选项上传了文档,该选项是亚马逊为演示提供的 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);

关于java - 如何使用 .net 代码执行 Amazon Cloud Search?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32219777/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com