Class QueryBuilder<T>
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<T>
Type Parameters
Name | Description |
---|---|
T |
Fields
_querystringValues
The querystring values.
Declaration
protected readonly List<KeyValuePair<string, string>> _querystringValues
Field Value
Type | Description |
---|---|
System.Collections.Generic.List<System.Collections.Generic.KeyValuePair<System.String, System.String>> |
Properties
New
Creates a new instance of a querybuilder.
Declaration
public static QueryBuilder<T> New { get; }
Property Value
Type | Description |
---|---|
QueryBuilder<T> | The created QueryBuilder<T>. |
Methods
AddFieldRestriction(String, String, String)
Adds the restriction for a specific field, value and operator.
Declaration
protected QueryBuilder<T> AddFieldRestriction(string field, string value, string operator)
Parameters
Type | Name | Description |
---|---|---|
System.String | field | The field to restrict. |
System.String | value | The value to restrict by. |
System.String | operator | The operator to apply restriction with. |
Returns
Type | Description |
---|---|
QueryBuilder<T> | The QueryBuilder<T> instance. |
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<T> ContentTypeIs(string contentTypeId)
Parameters
Type | Name | Description |
---|---|---|
System.String | contentTypeId | The ID of the content type to restrict by. |
Returns
Type | Description |
---|---|
QueryBuilder<T> | The QueryBuilder<T> instance. |
FieldDoesNotEqual(String, String)
Adds a restriction that a certain field must not exactly match the specified value.
Declaration
public QueryBuilder<T> 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<T> | The QueryBuilder<T> instance. |
FieldDoesNotEqual<U>(Expression<Func<T, U>>, String)
Adds a restriction that a certain field must not exactly match the specified value.
Declaration
public QueryBuilder<T> FieldDoesNotEqual<U>(Expression<Func<T, U>> selector, string value)
Parameters
Type | Name | Description |
---|---|---|
Expression<System.Func<T, U>> | selector | The expression of the field that must not match the value. |
System.String | value | The value that the field must not match. |
Returns
Type | Description |
---|---|
QueryBuilder<T> | The QueryBuilder<T> instance. |
Type Parameters
Name | Description |
---|---|
U |
FieldEquals(String, String)
Adds a restriction that a certain field must exactly match the specified value.
Declaration
public QueryBuilder<T> 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<T> | The QueryBuilder<T> instance. |
FieldEquals<U>(Expression<Func<T, U>>, String)
Adds a restriction that a certain field must exactly match the specified value.
Declaration
public QueryBuilder<T> FieldEquals<U>(Expression<Func<T, U>> selector, string value)
Parameters
Type | Name | Description |
---|---|---|
Expression<System.Func<T, U>> | selector | The expression of the field that must match the value. |
System.String | value | The value that the field must exactly match. |
Returns
Type | Description |
---|---|
QueryBuilder<T> | The QueryBuilder<T> instance. |
Type Parameters
Name | Description |
---|---|
U |
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<T> 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 | The values that the field must inlcude all of. |
Returns
Type | Description |
---|---|
QueryBuilder<T> | The QueryBuilder<T> instance. |
FieldEqualsAll<U>(Expression<Func<T, U>>, IEnumerable<String>)
Adds a restriction that a certain field must exactly match all the specified values. Only applicable for array fields.
Declaration
public QueryBuilder<T> FieldEqualsAll<U>(Expression<Func<T, U>> selector, IEnumerable<string> values)
Parameters
Type | Name | Description |
---|---|---|
Expression<System.Func<T, U>> | selector | The expression of the field that must exactly match all the values. |
System.Collections.Generic.IEnumerable<System.String> | values | The values that the field must inlcude all of. |
Returns
Type | Description |
---|---|
QueryBuilder<T> | The QueryBuilder<T> instance. |
Type Parameters
Name | Description |
---|---|
U |
FieldExcludes(String, IEnumerable<String>)
Adds a restriction that a certain field must not include any of the specified values.
Declaration
public QueryBuilder<T> 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 | The values that the field must not include any of. |
Returns
Type | Description |
---|---|
QueryBuilder<T> | The QueryBuilder<T> instance. |
FieldExcludes<U>(Expression<Func<T, U>>, IEnumerable<String>)
Adds a restriction that a certain field must not include any of the specified values.
Declaration
public QueryBuilder<T> FieldExcludes<U>(Expression<Func<T, U>> selector, IEnumerable<string> values)
Parameters
Type | Name | Description |
---|---|---|
Expression<System.Func<T, U>> | selector | The expression of the field that must not contain any of the specified values. |
System.Collections.Generic.IEnumerable<System.String> | values | The values that the field must not include any of. |
Returns
Type | Description |
---|---|
QueryBuilder<T> | The QueryBuilder<T> instance. |
Type Parameters
Name | Description |
---|---|
U |
FieldExists(String, Boolean)
Adds a restriction that a certain field must exist and not be null.
Declaration
public QueryBuilder<T> FieldExists(string field, bool mustExist = true)
Parameters
Type | Name | Description |
---|---|---|
System.String | field | The field that must exist and also not be null. |
System.Boolean | mustExist | Whether or not the field must exist or not exist. A value of false means only include entries where the particular field does NOT exist. |
Returns
Type | Description |
---|---|
QueryBuilder<T> | The QueryBuilder<T> instance. |
FieldExists<U>(Expression<Func<T, U>>, Boolean)
Adds a restriction that a certain field must exist and not be null.
Declaration
public QueryBuilder<T> FieldExists<U>(Expression<Func<T, U>> selector, bool mustExist = true)
Parameters
Type | Name | Description |
---|---|---|
Expression<System.Func<T, U>> | selector | The expression of the field that must exist and also not be null. |
System.Boolean | mustExist | Whether or not the field must exist or not exist. A value of false means only include entries where the particular field does NOT exist. |
Returns
Type | Description |
---|---|
QueryBuilder<T> | The QueryBuilder<T> instance. |
Type Parameters
Name | Description |
---|---|
U |
FieldGreaterThan(String, String)
Adds a restriction that a certain field must be greater than the specified value.
Declaration
public QueryBuilder<T> 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<T> | The QueryBuilder<T> instance. |
FieldGreaterThan<U>(Expression<Func<T, U>>, String)
Adds a restriction that a certain field must be greater than the specified value.
Declaration
public QueryBuilder<T> FieldGreaterThan<U>(Expression<Func<T, U>> selector, string value)
Parameters
Type | Name | Description |
---|---|---|
Expression<System.Func<T, U>> | selector | The expression of the field to compare against. |
System.String | value | The value the field must be greater than. |
Returns
Type | Description |
---|---|
QueryBuilder<T> | The QueryBuilder<T> instance. |
Type Parameters
Name | Description |
---|---|
U |
FieldGreaterThanOrEqualTo(String, String)
Adds a restriction that a certain field must be greater than or equal to the specified value.
Declaration
public QueryBuilder<T> 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<T> | The QueryBuilder<T> instance. |
FieldGreaterThanOrEqualTo<U>(Expression<Func<T, U>>, String)
Adds a restriction that a certain field must be greater than the specified value.
Declaration
public QueryBuilder<T> FieldGreaterThanOrEqualTo<U>(Expression<Func<T, U>> selector, string value)
Parameters
Type | Name | Description |
---|---|---|
Expression<System.Func<T, U>> | selector | The expression of the field to compare against. |
System.String | value | The value the field must be greater than. |
Returns
Type | Description |
---|---|
QueryBuilder<T> | The QueryBuilder<T> instance. |
Type Parameters
Name | Description |
---|---|
U |
FieldIncludes(String, IEnumerable<String>)
Adds a restriction that a certain field must include at least one of the specified values.
Declaration
public QueryBuilder<T> 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 | The values that the field must include at least one of. |
Returns
Type | Description |
---|---|
QueryBuilder<T> | The QueryBuilder<T> instance. |
FieldIncludes<U>(Expression<Func<T, U>>, IEnumerable<String>)
Adds a restriction that a certain field must include at least one of the specified values.
Declaration
public QueryBuilder<T> FieldIncludes<U>(Expression<Func<T, U>> selector, IEnumerable<string> values)
Parameters
Type | Name | Description |
---|---|---|
Expression<System.Func<T, U>> | selector | The expression of the field that must exactly match at least one of the specified values. |
System.Collections.Generic.IEnumerable<System.String> | values | The values that the field must include at least one of. |
Returns
Type | Description |
---|---|
QueryBuilder<T> | The QueryBuilder<T> instance. |
Type Parameters
Name | Description |
---|---|
U |
FieldLessThan(String, String)
Adds a restriction that a certain field must be less than the specified value.
Declaration
public QueryBuilder<T> 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<T> | The QueryBuilder<T> instance. |
FieldLessThan<U>(Expression<Func<T, U>>, String)
Adds a restriction that a certain field must be less than the specified value.
Declaration
public QueryBuilder<T> FieldLessThan<U>(Expression<Func<T, U>> selector, string value)
Parameters
Type | Name | Description |
---|---|---|
Expression<System.Func<T, U>> | selector | The expression of the field to compare against. |
System.String | value | The value the field must be less than. |
Returns
Type | Description |
---|---|
QueryBuilder<T> | The QueryBuilder<T> instance. |
Type Parameters
Name | Description |
---|---|
U |
FieldLessThanOrEqualTo(String, String)
Adds a restriction that a certain field must be less than or equal to the specified value.
Declaration
public QueryBuilder<T> 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<T> | The QueryBuilder<T> instance. |
FieldLessThanOrEqualTo<U>(Expression<Func<T, U>>, String)
Adds a restriction that a certain field must be less than or equal to the specified value.
Declaration
public QueryBuilder<T> FieldLessThanOrEqualTo<U>(Expression<Func<T, U>> selector, string value)
Parameters
Type | Name | Description |
---|---|---|
Expression<System.Func<T, U>> | selector | The expression of the field to compare against. |
System.String | value | The value the field must be less than. |
Returns
Type | Description |
---|---|
QueryBuilder<T> | The QueryBuilder<T> instance. |
Type Parameters
Name | Description |
---|---|
U |
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<T> 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<T> | The QueryBuilder<T> instance. |
FieldMatches<U>(Expression<Func<T, U>>, 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<T> FieldMatches<U>(Expression<Func<T, U>> selector, string value)
Parameters
Type | Name | Description |
---|---|---|
Expression<System.Func<T, U>> | selector | The expression of the field to search for matches. |
System.String | value | The value the field must match. |
Returns
Type | Description |
---|---|
QueryBuilder<T> | The QueryBuilder<T> instance. |
Type Parameters
Name | Description |
---|---|
U |
FullTextSearch(String)
Adds a search parameter to search across all text and symbol fields.
Declaration
public QueryBuilder<T> 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<T> | The QueryBuilder<T> 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<T> Include(int levels)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | levels | The number of levels of referenced content to include. |
Returns
Type | Description |
---|---|
QueryBuilder<T> | The QueryBuilder<T> instance. |
InProximityOf(String, String)
Adds a search parameter on proximity of a coordinate of a location field.
Declaration
public QueryBuilder<T> 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<T> | The QueryBuilder<T> instance. |
InProximityOf<U>(Expression<Func<T, U>>, String)
Adds a search parameter on proximity of a coordinate of a location field.
Declaration
public QueryBuilder<T> InProximityOf<U>(Expression<Func<T, U>> selector, string coordinate)
Parameters
Type | Name | Description |
---|---|---|
Expression<System.Func<T, U>> | selector | The expression of a location field to check proximity for. |
System.String | coordinate | The coordinate. |
Returns
Type | Description |
---|---|
QueryBuilder<T> | The QueryBuilder<T> instance. |
Type Parameters
Name | Description |
---|---|
U |
Limit(Int32)
Adds a limit to the number of results returned for the query.
Declaration
public QueryBuilder<T> Limit(int limit)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | limit | The maximum number of hits returned. |
Returns
Type | Description |
---|---|
QueryBuilder<T> | The QueryBuilder<T> instance. |
LinksToAsset(String)
Adds a search parameter to only fetch entries which links to the specified asset.
Declaration
public QueryBuilder<T> LinksToAsset(string id)
Parameters
Type | Name | Description |
---|---|---|
System.String | id | The id of the asset to get all incoming links for. |
Returns
Type | Description |
---|---|
QueryBuilder<T> | The QueryBuilder<T> instance. |
LinksToEntry(String)
Adds a search parameter to only fetch entries which links to the specified entry.
Declaration
public QueryBuilder<T> LinksToEntry(string id)
Parameters
Type | Name | Description |
---|---|---|
System.String | id | The id of the entry to get all incoming links for. |
Returns
Type | Description |
---|---|
QueryBuilder<T> | The QueryBuilder<T> instance. |
LocaleIs(String)
Filters the returned resources by the specified locale.
Declaration
public QueryBuilder<T> LocaleIs(string locale)
Parameters
Type | Name | Description |
---|---|---|
System.String | locale | The locale to filter by. |
Returns
Type | Description |
---|---|
QueryBuilder<T> | The QueryBuilder<T> instance. |
MimeTypeIs(MimeTypeRestriction)
Adds a restriction parameter for what mimetypes should be returned by the query.
Declaration
public QueryBuilder<T> MimeTypeIs(MimeTypeRestriction mimetype)
Parameters
Type | Name | Description |
---|---|---|
MimeTypeRestriction | mimetype | The mimetype to filter by. |
Returns
Type | Description |
---|---|
QueryBuilder<T> | The QueryBuilder<T> instance. |
OrderBy(String)
Adds an order expression to the query. An order expression is most simply created using the SortOrderBuilder<T> class.
Declaration
public QueryBuilder<T> OrderBy(string order)
Parameters
Type | Name | Description |
---|---|---|
System.String | order | The order expression. |
Returns
Type | Description |
---|---|
QueryBuilder<T> | The QueryBuilder<T> 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<T> Skip(int skip)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | skip | The number of items skipped. |
Returns
Type | Description |
---|---|
QueryBuilder<T> | The QueryBuilder<T> 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<T> 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<T> | The QueryBuilder<T> instance. |
WithinArea<U>(Expression<Func<T, U>>, String, String, String, String)
Adds a restriction parameter to only return resources with a location field within the specified area.
Declaration
public QueryBuilder<T> WithinArea<U>(Expression<Func<T, U>> selector, string latitude1, string longitude1, string latitude2, string longitude2)
Parameters
Type | Name | Description |
---|---|---|
Expression<System.Func<T, U>> | selector | 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<T> | The QueryBuilder<T> instance. |
Type Parameters
Name | Description |
---|---|
U |
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<T> 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 radius. |
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<T> | The QueryBuilder<T> instance. |
WithinRadius<U>(Expression<Func<T, U>>, 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<T> WithinRadius<U>(Expression<Func<T, U>> selector, string latitude1, string longitude1, float radius)
Parameters
Type | Name | Description |
---|---|---|
Expression<System.Func<T, U>> | selector | The expression of the location field to check if it is within the radius. |
System.String | latitude1 | The latitude of the centre of the bounding circle. |
System.String | longitude1 | The longitude of the centre of the bounding circle. |
System.Single | radius | The radius in kilometers of the bounding circle. |
Returns
Type | Description |
---|---|
QueryBuilder<T> | The QueryBuilder<T> instance. |
Type Parameters
Name | Description |
---|---|
U |