简体   繁体   English

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

[英]How to perform Amazon Cloud Search with .net code?

I am learning Amazon Cloud Search but I couldn't find any code in either C# or Java (though I am creating in C# but if I can get code in Java then I can try converting in C#). 我正在学习亚马逊云搜索,但我找不到C#或Java中的任何代码(虽然我在C#中创建,但如果我可以用Java获取代码,那么我可以尝试使用C#进行转换)。

This is just 1 code I found in C#: https://github.com/Sitefinity-SDK/amazon-cloud-search-sample/tree/master/SitefinityWebApp . 这只是我在C#中找到的一个代码: https//github.com/Sitefinity-SDK/amazon-cloud-search-sample/tree/master/SitefinityWebApp

This is 1 method i found in this code: 这是我在此代码中找到的一种方法:

 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);
        }

I have already created domain in Amazon Cloud Search using AWS console and uploaded document using Amazon predefine configuration option that is movie Imdb json file provided by Amazon for demo. 我已经使用AWS控制台在Amazon Cloud Search中创建了域,并使用Amazon预定义配置选项上传了文档,该选项是由Amazon提供的电影Imdb json文件进行演示。

But in this method I am not getting how to use this method, like if I want to search Director name then how do I pass in this method as because this method parameter is of type ISearchQuery ? 但是在这个方法中我没有得到如何使用这个方法,比如我想搜索Director名称然后我如何传递这个方法,因为这个方法参数的类型是ISearchQuery

I'd suggest using the official AWS CloudSearch .NET SDK . 我建议使用官方的AWS CloudSearch .NET SDK The library you were looking at seems fine (although I haven't look at it any detail) but the official version is more likely to expose new CloudSearch features as soon as they're released, will be supported if you need to talk to AWS support, etc, etc. 您正在查看的库似乎很好(虽然我没有看到它的任何细节)但正式版本更有可能在它们发布后立即公开新的CloudSearch功能,如果您需要与AWS交谈将得到支持支持等等

Specifically, take a look at the SearchRequest class -- all its params are strings so I think that obviates your question about ISearchQuery. 具体来说,看一下SearchRequest类 - 它的所有参数都是字符串,所以我认为这可以避免你关于ISearchQuery的问题。

I wasn't able to find an example of a query in .NET but this shows someone uploading docs using the AWS .NET SDK. 我没能找到.NET查询的一个例子,但这种展示了使用AWS .NET SDK有人上传文档。 It's essentially the same procedure as querying: creating and configuring a Request object and passing it to the client. 它与查询的过程基本相同:创建和配置Request对象并将其传递给客户端。

EDIT : Since you're still having a hard time, here's an example. 编辑 :既然你还有困难,这是一个例子。 Bear in mind that I am unfamiliar with C# and have not attempted to run or even compile this but I think it should at least be close to working. 请记住,我不熟悉C#并且没有尝试运行甚至编译它,但我认为它至少应该接近工作。 It's based off looking at the docs at http://docs.aws.amazon.com/sdkfornet/v3/apidocs/ 它的基础是查看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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM