0
0
Fork 0

better String() impl when request.Size=0

closes #107
This commit is contained in:
Marty Schoch 2014-10-10 18:08:20 -07:00
parent 64b0066121
commit 8be0652dc8
2 changed files with 26 additions and 8 deletions

View File

@ -15,6 +15,7 @@ package bleve
import (
"io/ioutil"
"os"
"strings"
"testing"
"time"
)
@ -345,6 +346,19 @@ func TestIndex(t *testing.T) {
if tagsCount != 2 {
t.Errorf("expected to find 2 values for tags")
}
termQuery = NewTermQuery("marti").SetField("name")
searchRequest = NewSearchRequest(termQuery)
searchRequest.Size = 0
searchResult, err = index.Search(searchRequest)
if err != nil {
t.Error(err)
}
srstring := searchResult.String()
if !strings.HasPrefix(srstring, "1 matches") {
t.Errorf("expected prefix '1 matches', got %s", srstring)
}
}
func TestIndexCreateNewOverExisting(t *testing.T) {

View File

@ -246,16 +246,20 @@ type SearchResult struct {
func (sr *SearchResult) String() string {
rv := ""
if len(sr.Hits) > 0 {
rv = fmt.Sprintf("%d matches, showing %d through %d, took %s\n", sr.Total, sr.Request.From+1, sr.Request.From+len(sr.Hits), sr.Took)
for i, hit := range sr.Hits {
rv += fmt.Sprintf("%5d. %s (%f)\n", i+sr.Request.From+1, hit.ID, hit.Score)
for fragmentField, fragments := range hit.Fragments {
rv += fmt.Sprintf("\t%s\n", fragmentField)
for _, fragment := range fragments {
rv += fmt.Sprintf("\t\t%s\n", fragment)
if sr.Total > 0 {
if sr.Request.Size > 0 {
rv = fmt.Sprintf("%d matches, showing %d through %d, took %s\n", sr.Total, sr.Request.From+1, sr.Request.From+len(sr.Hits), sr.Took)
for i, hit := range sr.Hits {
rv += fmt.Sprintf("%5d. %s (%f)\n", i+sr.Request.From+1, hit.ID, hit.Score)
for fragmentField, fragments := range hit.Fragments {
rv += fmt.Sprintf("\t%s\n", fragmentField)
for _, fragment := range fragments {
rv += fmt.Sprintf("\t\t%s\n", fragment)
}
}
}
} else {
rv = fmt.Sprintf("%d matches, took %s\n", sr.Total, sr.Took)
}
} else {
rv = "No matches"