user246392
user246392

Reputation: 3027

Azure Search: How to specify search fields in v11

In v10 of Azure Search SDK, I was able to specify exactly which fields to search in an index by taking advantage of SearchParameters class. In v11, I see there is SearchOptions, but the SearchFields parameter is get only. In v10, SearchFields has a setter.

How do I choose which fields to search on in v11?

Upvotes: 1

Views: 840

Answers (1)

Bruce Johnston
Bruce Johnston

Reputation: 8634

You can call .Add() on the SearchFields property:

var options = new SearchOptions();
options.SearchFields.Add("field1");
options.SearchFields.Add("field2");

Or you can use C#'s list initializer syntax:

var options = new SearchOptions() { SearchFields = { "field1", "field2" } };

Example adapted from this GitHub issue.

Upvotes: 3

Related Questions