Class QueryBuilder
Utility builder class to construct a correct search query for the Contentful API.
Inheritance
Inherited Members
Namespace:Contentful.Core.Search
Assembly:cs.temp.dll.dll
Syntax
public class QueryBuilder
Methods
Build()
Builds the query and returns the formatted querystring.
Declaration
public string Build()
Returns
| Type | Description |
|---|---|
| System.String | The formatted querystring. |
ContentTypeIs(String)
Adds a search parameter to restrict the result by content type.
Declaration
public QueryBuilder ContentTypeIs(string contentTypeId)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | contentTypeId | The ID of the content type to restrict by. |
Returns
| Type | Description |
|---|---|
| QueryBuilder | The QueryBuilder instance. |
FieldDoesNotEqual(String, String)
Adds a restriction that a certain field must not exactly match the specified value.
Declaration
public QueryBuilder FieldDoesNotEqual(string field, string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | field | The field that must not match the value. |
| System.String | value | The value that the field must not match. |
Returns
| Type | Description |
|---|---|
| QueryBuilder | The QueryBuilder instance. |
FieldEquals(String, String)
Adds a restriction that a certain field must exactly match the specified value.
Declaration
public QueryBuilder FieldEquals(string field, string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | field | The field that must match the value. |
| System.String | value | The value that the field must exactly match. |
Returns
| Type | Description |
|---|---|
| QueryBuilder | The QueryBuilder instance. |
FieldEqualsAll(String, IEnumerable<String>)
Adds a restriction that a certain field must exactly match all the specified values. Only applicable for array fields.
Declaration
public QueryBuilder FieldEqualsAll(string field, IEnumerable<string> values)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | field | The field that must exactly match all the values. |
| System.Collections.Generic.IEnumerable<System.String> | values |
Returns
| Type | Description |
|---|---|
| QueryBuilder | The QueryBuilder instance. |
FieldExcludes(String, IEnumerable<String>)
Adds a restriction that a certain field must not include any of the specified values.
Declaration
public QueryBuilder FieldExcludes(string field, IEnumerable<string> values)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | field | The field that must not contain any of the specified values. |
| System.Collections.Generic.IEnumerable<System.String> | values |
Returns
| Type | Description |
|---|---|
| QueryBuilder | The QueryBuilder instance. |
FieldExists(String)
Adds a restriction that a certain field must exist and not be null.
Declaration
public QueryBuilder FieldExists(string field)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | field | The field that must exist and also not be null. |
Returns
| Type | Description |
|---|---|
| QueryBuilder | The QueryBuilder instance. |
FieldGreaterThan(String, String)
Adds a restriction that a certain field must be greater than the specified value.
Declaration
public QueryBuilder FieldGreaterThan(string field, string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | field | The field to compare against. |
| System.String | value | The value the field must be greater than. |
Returns
| Type | Description |
|---|---|
| QueryBuilder | The QueryBuilder instance. |
FieldGreaterThanOrEqualTo(String, String)
Adds a restriction that a certain field must be greater than or equal to the specified value.
Declaration
public QueryBuilder FieldGreaterThanOrEqualTo(string field, string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | field | The field to compare against. |
| System.String | value | The value the field must be greater than or equal to. |
Returns
| Type | Description |
|---|---|
| QueryBuilder | The QueryBuilder instance. |
FieldIncludes(String, IEnumerable<String>)
Adds a restriction that a certain field must include at least one of the specified values.
Declaration
public QueryBuilder FieldIncludes(string field, IEnumerable<string> values)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | field | The field that must exactly match at least one of the specified values. |
| System.Collections.Generic.IEnumerable<System.String> | values |
Returns
| Type | Description |
|---|---|
| QueryBuilder | The QueryBuilder instance. |
FieldLessThan(String, String)
Adds a restriction that a certain field must be less than the specified value.
Declaration
public QueryBuilder FieldLessThan(string field, string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | field | The field to compare against. |
| System.String | value | The value the field must be less than. |
Returns
| Type | Description |
|---|---|
| QueryBuilder | The QueryBuilder instance. |
FieldLessThanOrEqualTo(String, String)
Adds a restriction that a certain field must be less than or equal to the specified value.
Declaration
public QueryBuilder FieldLessThanOrEqualTo(string field, string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | field | The field to compare against. |
| System.String | value | The value the field must be less than or equal to. |
Returns
| Type | Description |
|---|---|
| QueryBuilder | The QueryBuilder instance. |
FieldMatches(String, String)
Adds a search parameter to search in a specific field for a match for a value. Not to be confused with the FullTextSearch(String) method that searches across all fields.
Declaration
public QueryBuilder FieldMatches(string field, string value)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | field | The field to search for matches. |
| System.String | value | The value the field must match. |
Returns
| Type | Description |
|---|---|
| QueryBuilder | The QueryBuilder instance. |
FullTextSearch(String)
Adds a search parameter to search across all text and symbol fields.
Declaration
public QueryBuilder FullTextSearch(string query)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | query | The case insensitive query to search for. Has to be at least 2 characters long to be applied. |
Returns
| Type | Description |
|---|---|
| QueryBuilder | The QueryBuilder instance. |
Include(Int32)
Select the number of levels of referenced content that should be included in the response. The default is 1 if this querystring parameter is omitted.
Declaration
public QueryBuilder Include(int levels)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | levels | The number of levels of referenced content to include. |
Returns
| Type | Description |
|---|---|
| QueryBuilder | The QueryBuilder instance. |
InProximityOf(String, String)
Adds a search parameter on proximity of a coordinate of a location field.
Declaration
public QueryBuilder InProximityOf(string field, string coordinate)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | field | The location field to check proximity for. |
| System.String | coordinate | The coordinate. |
Returns
| Type | Description |
|---|---|
| QueryBuilder | The QueryBuilder instance. |
Limit(Int32)
Adds a limit to the number of results returned for the query.
Declaration
public QueryBuilder Limit(int limit)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | limit | The maximum number of hits returned. |
Returns
| Type | Description |
|---|---|
| QueryBuilder | The QueryBuilder instance. |
LocaleIs(String)
Filters the returned resources by the specified locale.
Declaration
public QueryBuilder LocaleIs(string locale)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | locale | The locale to filter by. |
Returns
| Type | Description |
|---|---|
| QueryBuilder | The QueryBuilder instance. |
MimeTypeIs(MimeTypeRestriction)
Adds a restriction parameter for what mimetypes should be returned by the query.
Declaration
public QueryBuilder MimeTypeIs(MimeTypeRestriction mimetype)
Parameters
| Type | Name | Description |
|---|---|---|
| MimeTypeRestriction | mimetype | The mimetype to filter by. |
Returns
| Type | Description |
|---|---|
| QueryBuilder | The QueryBuilder instance. |
New()
Creates a new instance of a querybuilder.
Declaration
public static QueryBuilder New()
Returns
| Type | Description |
|---|---|
| QueryBuilder | The created QueryBuilder. |
OrderBy(String)
Adds an order expression to the query. An order expression is most simply created using the SortOrderBuilder class.
Declaration
public QueryBuilder OrderBy(string order)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | order | The order expression. |
Returns
| Type | Description |
|---|---|
| QueryBuilder | The QueryBuilder instance. |
Skip(Int32)
Adds a skip to the results returned for the query. Use in conjunction with OrderBy(String) and Limit(Int32) to effectively page through content.
Declaration
public QueryBuilder Skip(int skip)
Parameters
| Type | Name | Description |
|---|---|---|
| System.Int32 | skip | The number of items skipped. |
Returns
| Type | Description |
|---|---|
| QueryBuilder | The QueryBuilder instance. |
WithinArea(String, String, String, String, String)
Adds a restriction parameter to only return resources with a location field within the specified area.
Declaration
public QueryBuilder WithinArea(string field, string latitude1, string longitude1, string latitude2, string longitude2)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | field | The location field to check if it is within the bounding box. |
| System.String | latitude1 | The latitude of the bottom left corner of the rectangle. |
| System.String | longitude1 | The longitude of the bottom left corner of the rectangle. |
| System.String | latitude2 | The latitude of the top right corner of the rectangle. |
| System.String | longitude2 | The longitude of the top right corner of the rectangle. |
Returns
| Type | Description |
|---|---|
| QueryBuilder | The QueryBuilder instance. |
WithinRadius(String, String, String, Single)
Adds a restriction parameter to only return resources with a location field within a certain radius of a coordinate.
Declaration
public QueryBuilder WithinRadius(string field, string latitude, string longitude, float radius)
Parameters
| Type | Name | Description |
|---|---|---|
| System.String | field | The location field to check if it is within the raidus. |
| System.String | latitude | The latitude of the centre of the bounding circle. |
| System.String | longitude | The longitude of the centre of the bounding circle. |
| System.Single | radius | The radius in kilometers of the bounding circle. |
Returns
| Type | Description |
|---|---|
| QueryBuilder | The QueryBuilder instance. |