SearchResult Took field now returns full time in Search()
likewise, MultiSearch used by aliases spanning multiple will also return full time in MultiSearch() closes #163
This commit is contained in:
parent
daeaa2c129
commit
0771f813ce
|
@ -12,6 +12,7 @@ package bleve
|
|||
import (
|
||||
"sort"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/blevesearch/bleve/document"
|
||||
"github.com/blevesearch/bleve/index"
|
||||
|
@ -378,6 +379,7 @@ func createChildSearchRequest(req *SearchRequest) *SearchRequest {
|
|||
// MultiSearch executes a SearchRequest across multiple
|
||||
// Index objects, then merges the results.
|
||||
func MultiSearch(req *SearchRequest, indexes ...Index) (*SearchResult, error) {
|
||||
searchStart := time.Now()
|
||||
results := make(chan *SearchResult)
|
||||
errs := make(chan error)
|
||||
|
||||
|
@ -459,6 +461,8 @@ func MultiSearch(req *SearchRequest, indexes ...Index) (*SearchResult, error) {
|
|||
|
||||
// fix up original request
|
||||
sr.Request = req
|
||||
searchDuration := time.Since(searchStart)
|
||||
sr.Took = searchDuration
|
||||
|
||||
return sr, nil
|
||||
}
|
||||
|
|
|
@ -443,7 +443,6 @@ func TestIndexAliasMulti(t *testing.T) {
|
|||
Score: 1.0,
|
||||
},
|
||||
},
|
||||
Took: 1 * time.Second,
|
||||
MaxScore: 1.0,
|
||||
}}
|
||||
ei2Count := uint64(8)
|
||||
|
@ -458,7 +457,6 @@ func TestIndexAliasMulti(t *testing.T) {
|
|||
Score: 2.0,
|
||||
},
|
||||
},
|
||||
Took: 2 * time.Second,
|
||||
MaxScore: 2.0,
|
||||
}}
|
||||
|
||||
|
@ -544,13 +542,14 @@ func TestIndexAliasMulti(t *testing.T) {
|
|||
Score: 1.0,
|
||||
},
|
||||
},
|
||||
Took: 3 * time.Second,
|
||||
MaxScore: 2.0,
|
||||
}
|
||||
results, err := alias.Search(sr)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
// cheat and ensure that Took field matches since it invovles time
|
||||
expected.Took = results.Took
|
||||
if !reflect.DeepEqual(results, expected) {
|
||||
t.Errorf("expected %#v, got %#v", expected, results)
|
||||
}
|
||||
|
@ -571,7 +570,6 @@ func TestMultiSearchNoError(t *testing.T) {
|
|||
Score: 1.0,
|
||||
},
|
||||
},
|
||||
Took: 1 * time.Second,
|
||||
MaxScore: 1.0,
|
||||
}}
|
||||
ei2 := &stubIndex{err: nil, searchResult: &SearchResult{
|
||||
|
@ -582,7 +580,6 @@ func TestMultiSearchNoError(t *testing.T) {
|
|||
Score: 2.0,
|
||||
},
|
||||
},
|
||||
Took: 2 * time.Second,
|
||||
MaxScore: 2.0,
|
||||
}}
|
||||
|
||||
|
@ -600,7 +597,6 @@ func TestMultiSearchNoError(t *testing.T) {
|
|||
Score: 1.0,
|
||||
},
|
||||
},
|
||||
Took: 3 * time.Second,
|
||||
MaxScore: 2.0,
|
||||
}
|
||||
|
||||
|
@ -608,6 +604,8 @@ func TestMultiSearchNoError(t *testing.T) {
|
|||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
// cheat and ensure that Took field matches since it invovles time
|
||||
expected.Took = results.Took
|
||||
if !reflect.DeepEqual(results, expected) {
|
||||
t.Errorf("expected %#v, got %#v", expected, results)
|
||||
}
|
||||
|
|
|
@ -495,7 +495,7 @@ func (i *indexImpl) Search(req *SearchRequest) (*SearchResult, error) {
|
|||
Hits: hits,
|
||||
Total: collector.Total(),
|
||||
MaxScore: collector.MaxScore(),
|
||||
Took: collector.Took(),
|
||||
Took: searchDuration,
|
||||
Facets: collector.FacetResults(),
|
||||
}, nil
|
||||
}
|
||||
|
|
|
@ -290,7 +290,6 @@ func (sr *SearchResult) String() string {
|
|||
func (sr *SearchResult) Merge(other *SearchResult) {
|
||||
sr.Hits = append(sr.Hits, other.Hits...)
|
||||
sr.Total += other.Total
|
||||
sr.Took += other.Took
|
||||
if other.MaxScore > sr.MaxScore {
|
||||
sr.MaxScore = other.MaxScore
|
||||
}
|
||||
|
|
|
@ -74,7 +74,6 @@ func TestSearchResultString(t *testing.T) {
|
|||
func TestSearchResultMerge(t *testing.T) {
|
||||
l := &SearchResult{
|
||||
Total: 1,
|
||||
Took: 1 * time.Second,
|
||||
MaxScore: 1,
|
||||
Hits: search.DocumentMatchCollection{
|
||||
&search.DocumentMatch{
|
||||
|
@ -86,7 +85,6 @@ func TestSearchResultMerge(t *testing.T) {
|
|||
|
||||
r := &SearchResult{
|
||||
Total: 1,
|
||||
Took: 2 * time.Second,
|
||||
MaxScore: 2,
|
||||
Hits: search.DocumentMatchCollection{
|
||||
&search.DocumentMatch{
|
||||
|
@ -98,7 +96,6 @@ func TestSearchResultMerge(t *testing.T) {
|
|||
|
||||
expected := &SearchResult{
|
||||
Total: 2,
|
||||
Took: 3 * time.Second,
|
||||
MaxScore: 2,
|
||||
Hits: search.DocumentMatchCollection{
|
||||
&search.DocumentMatch{
|
||||
|
|
Loading…
Reference in New Issue