Skip to content

Commit

Permalink
Merge pull request #299 from nikcio/docs/sorting
Browse files Browse the repository at this point in the history
Added docs on limiting results
  • Loading branch information
Shazwazza authored Nov 29, 2022
2 parents 64d2b1b + 35f7f7d commit a869cbb
Showing 1 changed file with 31 additions and 1 deletion.
32 changes: 31 additions & 1 deletion docs/sorting.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,37 @@ var orderedDescendingResults = searcher

## Limiting results

_TODO: Fill this in..._
To limit results we can use the `QueryOptions` class when executing a search query. The `QueryOptions` class provides the ability to skip and take.

Examples:

```csharp
var searcher = indexer.GetSearcher();

var takeFirstTenInIndex = searcher
.CreateQuery()
.All()
.Execute(QueryOptions.SkipTake(0, 10))

var skipFiveAndTakeFirstTenInIndex = searcher
.CreateQuery()
.All()
.Execute(QueryOptions.SkipTake(5, 10))

var takeThreeResults = searcher
.CreateQuery("content")
.Field("writerName", "administrator")
.OrderBy(new SortableField("name", SortType.String))
.Execute(QueryOptions.SkipTake(0, 3));

var takeSevenHundredResults = searcher
.CreateQuery("content")
.Field("writerName", "administrator")
.OrderByDescending(new SortableField("name", SortType.String))
.Execute(QueryOptions.SkipTake(0, 700));
```

By default when using `Execute()` or `Execute(QueryOptions.SkipTake(0))` where no take parameter is provided the take of the search will be set to `QueryOptions.DefaultMaxResults` (500).

## Paging

Expand Down

0 comments on commit a869cbb

Please sign in to comment.