Skip to content

Commit a869cbb

Browse files
authored
Merge pull request #299 from nikcio/docs/sorting
Added docs on limiting results
2 parents 64d2b1b + 35f7f7d commit a869cbb

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

docs/sorting.md

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,37 @@ var orderedDescendingResults = searcher
4646

4747
## Limiting results
4848

49-
_TODO: Fill this in..._
49+
To limit results we can use the `QueryOptions` class when executing a search query. The `QueryOptions` class provides the ability to skip and take.
50+
51+
Examples:
52+
53+
```csharp
54+
var searcher = indexer.GetSearcher();
55+
56+
var takeFirstTenInIndex = searcher
57+
.CreateQuery()
58+
.All()
59+
.Execute(QueryOptions.SkipTake(0, 10))
60+
61+
var skipFiveAndTakeFirstTenInIndex = searcher
62+
.CreateQuery()
63+
.All()
64+
.Execute(QueryOptions.SkipTake(5, 10))
65+
66+
var takeThreeResults = searcher
67+
.CreateQuery("content")
68+
.Field("writerName", "administrator")
69+
.OrderBy(new SortableField("name", SortType.String))
70+
.Execute(QueryOptions.SkipTake(0, 3));
71+
72+
var takeSevenHundredResults = searcher
73+
.CreateQuery("content")
74+
.Field("writerName", "administrator")
75+
.OrderByDescending(new SortableField("name", SortType.String))
76+
.Execute(QueryOptions.SkipTake(0, 700));
77+
```
78+
79+
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).
5080

5181
## Paging
5282

0 commit comments

Comments
 (0)