When I try to make a search query with bleve I always get 10 or less results. How can I increase this limit or make a search between all the data?
Here is code example, where I expect to get 35 results, but getting 10 (ps calc.Rand()
function is giving random bytes):
package search
import (
"testing"
"github.com/blevesearch/bleve/v2"
)
func TestSearcher(t *testing.T) {
mapping := bleve.NewIndexMapping()
searcher, _ := bleve.New("search/src", mapping)
for i := 0; i < 35; i++ {
searcher.Index(string(calc.Rand()), "stuff")
}
query := bleve.NewMatchQuery("stuff")
search := bleve.NewSearchRequest(query)
searchRez, _ := searcher.Search(search)
t.Error(len(searchRez.Hits))
}
Result I get:
--- FAIL: TestSearcher (2.33s)
/Users/ ... /search/search_test.go:86: 10
Result I expect:
--- FAIL: TestSearcher (2.33s)
/Users/ ... /search/search_test.go:86: 35
How do I access all the 35 values, that are stored by this index?
Set the field Size
on SearchRequest
:
Size/From describe how much and which part of the result set to return.
search := bleve.NewSearchRequest(query)
search.Size = 35 // or the page size you want
searchRez, _ := searcher.Search(search)
fmt.Println(len(searchRez.Hits)) // prints 35
or with pagination, you set the field From
incrementally based on page size. A contrived example:
count, _ := searcher.DocCount()
for i := 0; i < int(count); i += 10 /* page size */ {
search.From = i
searchRez, _ := searcher.Search(search)
fmt.Println(len(searchRez.Hits)) // prints 10 10 10 5
}