Reports all results
This commit is contained in:
27
indexer.go
27
indexer.go
@@ -15,6 +15,8 @@ import (
|
||||
"github.com/peterbourgon/diskv"
|
||||
)
|
||||
|
||||
type SearchResult bleve.SearchResult
|
||||
|
||||
type Indexer interface {
|
||||
Index(a *Album) error
|
||||
Get(ID AlbumID) (*Album, error)
|
||||
@@ -173,19 +175,28 @@ func (i *bleveIndexer) Search(query string) ([]*Album, error) {
|
||||
blq := bleve.NewQueryStringQuery(query)
|
||||
search := bleve.NewSearchRequest(blq)
|
||||
search.Highlight = bleve.NewHighlight()
|
||||
searchResults, err := i.bl.Search(search)
|
||||
sRes, err := i.bl.Search(search)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Could not perform search on the index: %s", err)
|
||||
}
|
||||
|
||||
res := make([]*Album, 0, searchResults.Total)
|
||||
for _, d := range searchResults.Hits {
|
||||
a, err := i.get(d.ID)
|
||||
if err != nil {
|
||||
return res, err
|
||||
res := make([]*Album, 0, sRes.Total)
|
||||
for len(res) < int(sRes.Total) {
|
||||
if len(res) != 0 {
|
||||
//fetches the next results
|
||||
search.From = len(res)
|
||||
sRes, err = i.bl.Search(search)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("Could not perform search on the index: %s", err)
|
||||
}
|
||||
}
|
||||
for _, d := range sRes.Hits {
|
||||
a, err := i.get(d.ID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
res = append(res, a)
|
||||
}
|
||||
|
||||
res = append(res, a)
|
||||
}
|
||||
|
||||
return res, nil
|
||||
|
||||
Reference in New Issue
Block a user