Class PagedSearch<T, TProjection>
Represents an aggregation query that retrieves results with easy paging support.
public class PagedSearch<T, TProjection> where T : IEntity
Type Parameters
TAny class that implements IEntity
TProjectionThe type you'd like to project the results to.
- Inheritance
-
PagedSearch<T, TProjection>
- Derived
- Inherited Members
Methods
ExecuteAsync(CancellationToken)
Run the aggregation search command in MongoDB server and get a page of results and total + page count
public Task<(IReadOnlyList<TProjection> Results, long TotalCount, int PageCount)> ExecuteAsync(CancellationToken cancellation = default)
Parameters
cancellationCancellationTokenAn optional cancellation token
Returns
- Task<(IReadOnlyList<TProjection> Results, long TotalCount, int PageCount)>
IgnoreGlobalFilters()
Specify that this operation should ignore any global filters
public PagedSearch<T, TProjection> IgnoreGlobalFilters()
Returns
- PagedSearch<T, TProjection>
Match(FilterDefinition<T>)
Specify the matching criteria with a filter definition
public PagedSearch<T, TProjection> Match(FilterDefinition<T> filterDefinition)
Parameters
filterDefinitionFilterDefinition<T>A filter definition
Returns
- PagedSearch<T, TProjection>
Match(Search, string, bool, bool, string?)
Specify a search term to find results from the text index of this particular collection.
TIP: Make sure to define a text index with DB.Index<T>() before searching
public PagedSearch<T, TProjection> Match(Search searchType, string searchTerm, bool caseSensitive = false, bool diacriticSensitive = false, string? language = null)
Parameters
searchTypeSearchThe type of text matching to do
searchTermstringThe search term
caseSensitiveboolCase sensitivity of the search (optional)
diacriticSensitiveboolDiacritic sensitivity of the search (optional)
languagestringThe language for the search (optional)
Returns
- PagedSearch<T, TProjection>
Match(Template)
Specify the matching criteria with a template
public PagedSearch<T, TProjection> Match(Template template)
Parameters
templateTemplateA Template with a find query
Returns
- PagedSearch<T, TProjection>
Match(Func<FilterDefinitionBuilder<T>, FilterDefinition<T>>)
Specify the matching criteria with a filter expression
public PagedSearch<T, TProjection> Match(Func<FilterDefinitionBuilder<T>, FilterDefinition<T>> filter)
Parameters
filterFunc<FilterDefinitionBuilder<T>, FilterDefinition<T>>f => f.Eq(x => x.Prop, Value) & f.Gt(x => x.Prop, Value)
Returns
- PagedSearch<T, TProjection>
Match(Expression<Func<T, bool>>)
Specify the matching criteria with a lambda expression
public PagedSearch<T, TProjection> Match(Expression<Func<T, bool>> expression)
Parameters
expressionExpression<Func<T, bool>>x => x.Property == Value
Returns
- PagedSearch<T, TProjection>
Match(Expression<Func<T, object?>>, Coordinates2D, double?, double?)
Specify criteria for matching entities based on GeoSpatial data (longitude & latitude)
TIP: Make sure to define a Geo2DSphere index with DB.Index<T>() before searching
Note: DB.FluentGeoNear() supports more advanced options
public PagedSearch<T, TProjection> Match(Expression<Func<T, object?>> coordinatesProperty, Coordinates2D nearCoordinates, double? maxDistance = null, double? minDistance = null)
Parameters
coordinatesPropertyExpression<Func<T, object>>The property where 2DCoordinates are stored
nearCoordinatesCoordinates2DThe search point
maxDistancedouble?Maximum distance in meters from the search point
minDistancedouble?Minimum distance in meters from the search point
Returns
- PagedSearch<T, TProjection>
MatchExpression(Template)
Specify the matching criteria with a Template
public PagedSearch<T, TProjection> MatchExpression(Template template)
Parameters
templateTemplateA Template object
Returns
- PagedSearch<T, TProjection>
MatchExpression(string)
Specify the matching criteria with an aggregation expression (i.e. $expr)
public PagedSearch<T, TProjection> MatchExpression(string expression)
Parameters
expressionstring{ $gt: ['$Property1', '$Property2'] }
Returns
- PagedSearch<T, TProjection>
MatchString(string)
Specify the matching criteria with a JSON string
public PagedSearch<T, TProjection> MatchString(string jsonString)
Parameters
jsonStringstring{ Title : 'The Power Of Now' }
Returns
- PagedSearch<T, TProjection>
Option(Action<AggregateOptions>)
Specify an option for this find command (use multiple times if needed)
public PagedSearch<T, TProjection> Option(Action<AggregateOptions> option)
Parameters
optionAction<AggregateOptions>x => x.OptionName = OptionValue
Returns
- PagedSearch<T, TProjection>
PageNumber(int)
Specify the page number to get
public PagedSearch<T, TProjection> PageNumber(int pageNumber)
Parameters
pageNumberintThe page number
Returns
- PagedSearch<T, TProjection>
PageSize(int)
Specify the number of items per page
public PagedSearch<T, TProjection> PageSize(int pageSize)
Parameters
pageSizeintThe size of a page
Returns
- PagedSearch<T, TProjection>
Project(Func<ProjectionDefinitionBuilder<T>, ProjectionDefinition<T, TProjection>>)
Specify how to project the results using a projection expression
public PagedSearch<T, TProjection> Project(Func<ProjectionDefinitionBuilder<T>, ProjectionDefinition<T, TProjection>> projection)
Parameters
projectionFunc<ProjectionDefinitionBuilder<T>, ProjectionDefinition<T, TProjection>>p => p.Include("Prop1").Exclude("Prop2")
Returns
- PagedSearch<T, TProjection>
Project(Expression<Func<T, TProjection>>)
Specify how to project the results using a lambda expression
public PagedSearch<T, TProjection> Project(Expression<Func<T, TProjection>> expression)
Parameters
expressionExpression<Func<T, TProjection>>x => new Test { PropName = x.Prop }
Returns
- PagedSearch<T, TProjection>
ProjectExcluding(Expression<Func<T, object?>>)
Specify how to project the results using an exclusion projection expression.
public PagedSearch<T, TProjection> ProjectExcluding(Expression<Func<T, object?>> exclusion)
Parameters
exclusionExpression<Func<T, object>>x => new { x.PropToExclude, x.AnotherPropToExclude }
Returns
- PagedSearch<T, TProjection>
Sort(Func<SortDefinitionBuilder<T>, SortDefinition<T>>)
Specify how to sort using a sort expression
public PagedSearch<T, TProjection> Sort(Func<SortDefinitionBuilder<T>, SortDefinition<T>> sortFunction)
Parameters
sortFunctionFunc<SortDefinitionBuilder<T>, SortDefinition<T>>s => s.Ascending("Prop1").MetaTextScore("Prop2")
Returns
- PagedSearch<T, TProjection>
Sort(Expression<Func<T, object?>>, Order)
Specify which property and order to use for sorting (use multiple times if needed)
public PagedSearch<T, TProjection> Sort(Expression<Func<T, object?>> propertyToSortBy, Order sortOrder)
Parameters
propertyToSortByExpression<Func<T, object>>x => x.Prop
sortOrderOrderThe sort order
Returns
- PagedSearch<T, TProjection>
SortByTextScore()
Sort the results of a text search by the MetaTextScore
TIP: Use this method after .Project() if you need to do a projection also
public PagedSearch<T, TProjection> SortByTextScore()
Returns
- PagedSearch<T, TProjection>
SortByTextScore(Expression<Func<T, object?>>?)
Sort the results of a text search by the MetaTextScore and get back the score as well
TIP: Use this method after .Project() if you need to do a projection also
public PagedSearch<T, TProjection> SortByTextScore(Expression<Func<T, object?>>? scoreProperty)
Parameters
scorePropertyExpression<Func<T, object>>x => x.TextScoreProp
Returns
- PagedSearch<T, TProjection>
WithFluent<TFluent>(TFluent)
Begins the paged search aggregation pipeline with the provided fluent pipeline.
TIP: This method must be first in the chain, and it cannot be used with .Match()
public PagedSearch<T, TProjection> WithFluent<TFluent>(TFluent fluentPipeline) where TFluent : IAggregateFluent<T>
Parameters
fluentPipelineTFluentThe input IAggregateFluent pipeline
Returns
- PagedSearch<T, TProjection>
Type Parameters
TFluentThe type of the input pipeline