Reputation: 14604
I have a domain where I have 2 searchable fields (a literal and a text field), basically Category and Content.
How can I specify a specific field to use in a field? From what I can tell, it will default to search all searchable fields, but that is not what I want (ie, don't want to look for category Cats and get a result from another category just because it includes the word Cat in the content.)
I am using .Net SDK, and I've been going through their documentation, but can't find that section.
Thanks!
Upvotes: 1
Views: 1859
Reputation: 11
Sample codes for Cloudsearch in C# aren't common however you can try this one i wrote
public List<AdditionalFields> Search(string query)
{
var batch = new List<AdditionalFields>();
query = query.Trim();
try
{
// Configure the Client that you'll use to make search requests
string queryUrl = @"http://search-********.cloudsearch.amazonaws.com";
var awsCredentials = new Amazon.Runtime.BasicAWSCredentials();
AmazonCloudSearchDomainClient searchClient = new AmazonCloudSearchDomainClient(queryUrl, awsCredentials);
SearchRequest searchRequest = new SearchRequest();
searchRequest.Query = query;
//searchRequest.Facet =
//searchRequest.QueryOptions.
searchRequest.Return = "_all_fields";
SearchResponse searchResponse = searchClient.SearchAsync(searchRequest).Result;
foreach (var hit in searchResponse.Hits.Hit)
{
var fields = new AdditionalFields();
var searchfields = new Fields();
searchfields.content = hit.Fields["content"][0].ToString();
searchfields.directory = hit.Fields["directory"][0].ToString();
searchfields.resourcename = hit.Fields["resourcename"][0].ToString();
searchfields.title = hit.Fields["title"][0].ToString();
fields.abridgedContent = searchfields.content.Replace(searchfields.title, string.Empty);
searchfields.version = hit.Fields["version"][0].ToString();
fields.abridgedContent = Abridged(fields.abridgedContent, query);
searchfields.description = hit.Fields["description"][0].ToString();
searchfields.resourcename = hit.Fields["resourcename"][0].ToString();
searchfields.resourcetype = hit.Fields["resourcetype"][0].ToString();
fields.url = "/bookviewer?bookValue=" + searchfields.resourcename + "&version=" + searchfields.version + "&chapterFolder=" + searchfields.directory + "&firstChapterNo=" + searchfields.description + ".htm";
fields.fields = searchfields;
batch.Add(fields);
}
// return searchResponse.Status.ToString();
}
catch (AmazonCloudSearchDomainException ex)
{
var fields = new AdditionalFields();
fields.error = "ERROR : " + ex.Message;
batch.Add(fields);
}
catch (Exception ex)
{
var fields = new AdditionalFields();
fields.error = "ERROR : " + ex.Message;
batch.Add(fields);
}
return batch;
}
Upvotes: 1
Reputation: 14604
After digging a bit more, and that the way to specify a field is using the fields
array field.
When using the .Net SDK
, it can be done this way:
new SearchRequest {
Query = query,
QueryOptions = @"{""fields"":[""field_name""]}"
};
Upvotes: 5