0
0
Fork 0

switch back to single DocumentMatch struct

instead of separate DocumentMatch/DocumentMatchInternal

rules are simple, everything operates on the IndexInternalID field
until the results are returned, then ID is set correctly
the IndexInternalID field is not exported to JSON
This commit is contained in:
Marty Schoch 2016-08-01 14:58:02 -04:00
parent 1aacd9bad5
commit e188fe35f7
34 changed files with 448 additions and 480 deletions

View File

@ -11,11 +11,11 @@ import (
)
func benchHelper(numOfMatches int, collector search.Collector, b *testing.B) {
matches := make([]*search.DocumentMatchInternal, 0, numOfMatches)
matches := make([]*search.DocumentMatch, 0, numOfMatches)
for i := 0; i < numOfMatches; i++ {
matches = append(matches, &search.DocumentMatchInternal{
ID: index.IndexInternalID(strconv.Itoa(i)),
Score: rand.Float64(),
matches = append(matches, &search.DocumentMatch{
IndexInternalID: index.IndexInternalID(strconv.Itoa(i)),
Score: rand.Float64(),
})
}

View File

@ -64,8 +64,8 @@ var COLLECT_CHECK_DONE_EVERY = uint64(1024)
func (tksc *TopScoreCollector) Collect(ctx context.Context, searcher search.Searcher, reader index.IndexReader) error {
startTime := time.Now()
var err error
var pre search.DocumentMatchInternal // A single pre-alloc'ed, reused instance.
var next *search.DocumentMatchInternal
var pre search.DocumentMatch // A single pre-alloc'ed, reused instance.
var next *search.DocumentMatch
select {
case <-ctx.Done():
return ctx.Err()
@ -103,7 +103,7 @@ func (tksc *TopScoreCollector) Collect(ctx context.Context, searcher search.Sear
return nil
}
func (tksc *TopScoreCollector) collectSingle(dmIn *search.DocumentMatchInternal) {
func (tksc *TopScoreCollector) collectSingle(dmIn *search.DocumentMatch) {
// increment total hits
tksc.total++
@ -119,18 +119,18 @@ func (tksc *TopScoreCollector) collectSingle(dmIn *search.DocumentMatchInternal)
// Because the dmIn will be the single, pre-allocated, reused
// instance, we need to copy the dmIn into a new, standalone
// instance before inserting into our candidate results list.
dm := &search.DocumentMatchInternal{}
dm := &search.DocumentMatch{}
*dm = *dmIn
for e := tksc.results.Front(); e != nil; e = e.Next() {
curr := e.Value.(*search.DocumentMatchInternal)
curr := e.Value.(*search.DocumentMatch)
if dm.Score <= curr.Score {
tksc.results.InsertBefore(dm, e)
// if we just made the list too long
if tksc.results.Len() > (tksc.k + tksc.skip) {
// remove the head
tksc.minScore = tksc.results.Remove(tksc.results.Front()).(*search.DocumentMatchInternal).Score
tksc.minScore = tksc.results.Remove(tksc.results.Front()).(*search.DocumentMatch).Score
}
return
}
@ -139,7 +139,7 @@ func (tksc *TopScoreCollector) collectSingle(dmIn *search.DocumentMatchInternal)
tksc.results.PushBack(dm)
if tksc.results.Len() > (tksc.k + tksc.skip) {
// remove the head
tksc.minScore = tksc.results.Remove(tksc.results.Front()).(*search.DocumentMatchInternal).Score
tksc.minScore = tksc.results.Remove(tksc.results.Front()).(*search.DocumentMatch).Score
}
}
@ -158,7 +158,8 @@ func (tksc *TopScoreCollector) finalizeResults(r index.IndexReader) (search.Docu
continue
}
var err error
rv[i], err = e.Value.(*search.DocumentMatchInternal).Finalize(r)
rv[i] = e.Value.(*search.DocumentMatch)
rv[i].ID, err = r.FinalizeDocID(rv[i].IndexInternalID)
if err != nil {
return nil, err
}

View File

@ -24,62 +24,62 @@ func TestTop10Scores(t *testing.T) {
// the top-10 scores are > 10
// everything else is less than 10
searcher := &stubSearcher{
matches: []*search.DocumentMatchInternal{
&search.DocumentMatchInternal{
ID: index.IndexInternalID("a"),
Score: 11,
matches: []*search.DocumentMatch{
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("a"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("b"),
Score: 9,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("b"),
Score: 9,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("c"),
Score: 11,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("c"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("d"),
Score: 9,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("d"),
Score: 9,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("e"),
Score: 11,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("e"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("f"),
Score: 9,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("f"),
Score: 9,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("g"),
Score: 11,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("g"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("h"),
Score: 9,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("h"),
Score: 9,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("i"),
Score: 11,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("i"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("j"),
Score: 11,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("j"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("k"),
Score: 11,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("k"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("l"),
Score: 99,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("l"),
Score: 99,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("m"),
Score: 11,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("m"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("n"),
Score: 11,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("n"),
Score: 11,
},
},
}
@ -132,62 +132,62 @@ func TestTop10ScoresSkip10(t *testing.T) {
// the top-10 scores are > 10
// everything else is less than 10
searcher := &stubSearcher{
matches: []*search.DocumentMatchInternal{
&search.DocumentMatchInternal{
ID: index.IndexInternalID("a"),
Score: 11,
matches: []*search.DocumentMatch{
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("a"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("b"),
Score: 9.5,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("b"),
Score: 9.5,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("c"),
Score: 11,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("c"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("d"),
Score: 9,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("d"),
Score: 9,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("e"),
Score: 11,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("e"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("f"),
Score: 9,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("f"),
Score: 9,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("g"),
Score: 11,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("g"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("h"),
Score: 9,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("h"),
Score: 9,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("i"),
Score: 11,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("i"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("j"),
Score: 11,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("j"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("k"),
Score: 11,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("k"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("l"),
Score: 99,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("l"),
Score: 99,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("m"),
Score: 11,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("m"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("n"),
Score: 11,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("n"),
Score: 11,
},
},
}
@ -228,62 +228,62 @@ func TestPaginationSameScores(t *testing.T) {
// a stub search with more than 10 matches
// all documents have the same score
searcher := &stubSearcher{
matches: []*search.DocumentMatchInternal{
&search.DocumentMatchInternal{
ID: index.IndexInternalID("a"),
Score: 5,
matches: []*search.DocumentMatch{
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("a"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("b"),
Score: 5,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("b"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("c"),
Score: 5,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("c"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("d"),
Score: 5,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("d"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("e"),
Score: 5,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("e"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("f"),
Score: 5,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("f"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("g"),
Score: 5,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("g"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("h"),
Score: 5,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("h"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("i"),
Score: 5,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("i"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("j"),
Score: 5,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("j"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("k"),
Score: 5,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("k"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("l"),
Score: 5,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("l"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("m"),
Score: 5,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("m"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("n"),
Score: 5,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("n"),
Score: 5,
},
},
}
@ -314,62 +314,62 @@ func TestPaginationSameScores(t *testing.T) {
// a stub search with more than 10 matches
// all documents have the same score
searcher = &stubSearcher{
matches: []*search.DocumentMatchInternal{
&search.DocumentMatchInternal{
ID: index.IndexInternalID("a"),
Score: 5,
matches: []*search.DocumentMatch{
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("a"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("b"),
Score: 5,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("b"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("c"),
Score: 5,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("c"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("d"),
Score: 5,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("d"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("e"),
Score: 5,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("e"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("f"),
Score: 5,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("f"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("g"),
Score: 5,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("g"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("h"),
Score: 5,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("h"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("i"),
Score: 5,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("i"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("j"),
Score: 5,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("j"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("k"),
Score: 5,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("k"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("l"),
Score: 5,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("l"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("m"),
Score: 5,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("m"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: index.IndexInternalID("n"),
Score: 5,
&search.DocumentMatch{
IndexInternalID: index.IndexInternalID("n"),
Score: 5,
},
},
}

View File

@ -17,10 +17,10 @@ import (
type stubSearcher struct {
index int
matches []*search.DocumentMatchInternal
matches []*search.DocumentMatch
}
func (ss *stubSearcher) Next(preAllocated *search.DocumentMatchInternal) (*search.DocumentMatchInternal, error) {
func (ss *stubSearcher) Next(preAllocated *search.DocumentMatch) (*search.DocumentMatch, error) {
if ss.index < len(ss.matches) {
rv := ss.matches[ss.index]
ss.index++
@ -29,9 +29,9 @@ func (ss *stubSearcher) Next(preAllocated *search.DocumentMatchInternal) (*searc
return nil, nil
}
func (ss *stubSearcher) Advance(ID index.IndexInternalID, preAllocated *search.DocumentMatchInternal) (*search.DocumentMatchInternal, error) {
func (ss *stubSearcher) Advance(ID index.IndexInternalID, preAllocated *search.DocumentMatch) (*search.DocumentMatch, error) {
for ss.index < len(ss.matches) && ss.matches[ss.index].ID.Compare(ID) < 0 {
for ss.index < len(ss.matches) && ss.matches[ss.index].IndexInternalID.Compare(ID) < 0 {
ss.index++
}
if ss.index < len(ss.matches) {

View File

@ -37,12 +37,12 @@ func (fb *FacetsBuilder) Add(name string, facetBuilder FacetBuilder) {
fb.facets[name] = facetBuilder
}
func (fb *FacetsBuilder) Update(docMatch *DocumentMatchInternal) error {
func (fb *FacetsBuilder) Update(docMatch *DocumentMatch) error {
var fields []string
for _, facetBuilder := range fb.facets {
fields = append(fields, facetBuilder.Field())
}
fieldTerms, err := fb.indexReader.DocumentFieldTermsForFields(docMatch.ID, fields)
fieldTerms, err := fb.indexReader.DocumentFieldTermsForFields(docMatch.IndexInternalID, fields)
if err != nil {
return err
}

View File

@ -23,9 +23,9 @@ func NewConjunctionQueryScorer(explain bool) *ConjunctionQueryScorer {
}
}
func (s *ConjunctionQueryScorer) Score(constituents []*search.DocumentMatchInternal) *search.DocumentMatchInternal {
rv := search.DocumentMatchInternal{
ID: constituents[0].ID,
func (s *ConjunctionQueryScorer) Score(constituents []*search.DocumentMatch) *search.DocumentMatch {
rv := search.DocumentMatch{
IndexInternalID: constituents[0].IndexInternalID,
}
var sum float64

View File

@ -65,7 +65,7 @@ func (s *ConstantScorer) SetQueryNorm(qnorm float64) {
}
}
func (s *ConstantScorer) Score(id index.IndexInternalID) *search.DocumentMatchInternal {
func (s *ConstantScorer) Score(id index.IndexInternalID) *search.DocumentMatch {
var scoreExplanation *search.Explanation
score := s.constant
@ -92,9 +92,9 @@ func (s *ConstantScorer) Score(id index.IndexInternalID) *search.DocumentMatchIn
}
}
rv := search.DocumentMatchInternal{
ID: id,
Score: score,
rv := search.DocumentMatch{
IndexInternalID: id,
Score: score,
}
if s.explain {
rv.Expl = scoreExplanation

View File

@ -23,7 +23,7 @@ func TestConstantScorer(t *testing.T) {
tests := []struct {
termMatch *index.TermFieldDoc
result *search.DocumentMatchInternal
result *search.DocumentMatch
}{
// test some simple math
{
@ -40,9 +40,9 @@ func TestConstantScorer(t *testing.T) {
},
},
},
result: &search.DocumentMatchInternal{
ID: index.IndexInternalID("one"),
Score: 1.0,
result: &search.DocumentMatch{
IndexInternalID: index.IndexInternalID("one"),
Score: 1.0,
Expl: &search.Explanation{
Value: 1.0,
Message: "ConstantScore()",
@ -68,7 +68,7 @@ func TestConstantScorerWithQueryNorm(t *testing.T) {
tests := []struct {
termMatch *index.TermFieldDoc
result *search.DocumentMatchInternal
result *search.DocumentMatch
}{
{
termMatch: &index.TermFieldDoc{
@ -76,9 +76,9 @@ func TestConstantScorerWithQueryNorm(t *testing.T) {
Freq: 1,
Norm: 1.0,
},
result: &search.DocumentMatchInternal{
ID: index.IndexInternalID("one"),
Score: 2.0,
result: &search.DocumentMatch{
IndexInternalID: index.IndexInternalID("one"),
Score: 2.0,
Expl: &search.Explanation{
Value: 2.0,
Message: "weight(^1.000000), product of:",

View File

@ -25,9 +25,9 @@ func NewDisjunctionQueryScorer(explain bool) *DisjunctionQueryScorer {
}
}
func (s *DisjunctionQueryScorer) Score(constituents []*search.DocumentMatchInternal, countMatch, countTotal int) *search.DocumentMatchInternal {
rv := search.DocumentMatchInternal{
ID: constituents[0].ID,
func (s *DisjunctionQueryScorer) Score(constituents []*search.DocumentMatch, countMatch, countTotal int) *search.DocumentMatch {
rv := search.DocumentMatch{
IndexInternalID: constituents[0].IndexInternalID,
}
var sum float64

View File

@ -83,7 +83,7 @@ func (s *TermQueryScorer) SetQueryNorm(qnorm float64) {
}
}
func (s *TermQueryScorer) Score(termMatch *index.TermFieldDoc, preAllocated *search.DocumentMatchInternal) *search.DocumentMatchInternal {
func (s *TermQueryScorer) Score(termMatch *index.TermFieldDoc, preAllocated *search.DocumentMatch) *search.DocumentMatch {
var scoreExplanation *search.Explanation
// need to compute score
@ -130,9 +130,9 @@ func (s *TermQueryScorer) Score(termMatch *index.TermFieldDoc, preAllocated *sea
rv := preAllocated
if rv == nil {
rv = &search.DocumentMatchInternal{}
rv = &search.DocumentMatch{}
}
rv.ID = termMatch.ID
rv.IndexInternalID = termMatch.ID
rv.Score = score
if s.explain {
rv.Expl = scoreExplanation

View File

@ -30,7 +30,7 @@ func TestTermScorer(t *testing.T) {
tests := []struct {
termMatch *index.TermFieldDoc
result *search.DocumentMatchInternal
result *search.DocumentMatch
}{
// test some simple math
{
@ -47,9 +47,9 @@ func TestTermScorer(t *testing.T) {
},
},
},
result: &search.DocumentMatchInternal{
ID: index.IndexInternalID("one"),
Score: math.Sqrt(1.0) * idf,
result: &search.DocumentMatch{
IndexInternalID: index.IndexInternalID("one"),
Score: math.Sqrt(1.0) * idf,
Expl: &search.Explanation{
Value: math.Sqrt(1.0) * idf,
Message: "fieldWeight(desc:beer in one), product of:",
@ -88,9 +88,9 @@ func TestTermScorer(t *testing.T) {
Freq: 1,
Norm: 1.0,
},
result: &search.DocumentMatchInternal{
ID: index.IndexInternalID("one"),
Score: math.Sqrt(1.0) * idf,
result: &search.DocumentMatch{
IndexInternalID: index.IndexInternalID("one"),
Score: math.Sqrt(1.0) * idf,
Expl: &search.Explanation{
Value: math.Sqrt(1.0) * idf,
Message: "fieldWeight(desc:beer in one), product of:",
@ -118,9 +118,9 @@ func TestTermScorer(t *testing.T) {
Freq: 65,
Norm: 1.0,
},
result: &search.DocumentMatchInternal{
ID: index.IndexInternalID("one"),
Score: math.Sqrt(65) * idf,
result: &search.DocumentMatch{
IndexInternalID: index.IndexInternalID("one"),
Score: math.Sqrt(65) * idf,
Expl: &search.Explanation{
Value: math.Sqrt(65) * idf,
Message: "fieldWeight(desc:beer in one), product of:",
@ -173,7 +173,7 @@ func TestTermScorerWithQueryNorm(t *testing.T) {
tests := []struct {
termMatch *index.TermFieldDoc
result *search.DocumentMatchInternal
result *search.DocumentMatch
}{
{
termMatch: &index.TermFieldDoc{
@ -181,9 +181,9 @@ func TestTermScorerWithQueryNorm(t *testing.T) {
Freq: 1,
Norm: 1.0,
},
result: &search.DocumentMatchInternal{
ID: index.IndexInternalID("one"),
Score: math.Sqrt(1.0) * idf * 3.0 * idf * 2.0,
result: &search.DocumentMatch{
IndexInternalID: index.IndexInternalID("one"),
Score: math.Sqrt(1.0) * idf * 3.0 * idf * 2.0,
Expl: &search.Explanation{
Value: math.Sqrt(1.0) * idf * 3.0 * idf * 2.0,
Message: "weight(desc:beer^3.000000 in one), product of:",

View File

@ -52,47 +52,14 @@ type FieldTermLocationMap map[string]TermLocationMap
type FieldFragmentMap map[string][]string
type DocumentMatchInternal struct {
Index string
ID index.IndexInternalID
Score float64
Expl *Explanation
Locations FieldTermLocationMap
Fragments FieldFragmentMap
// Fields contains the values for document fields listed in
// SearchRequest.Fields. Text fields are returned as strings, numeric
// fields as float64s and date fields as time.RFC3339 formatted strings.
Fields map[string]interface{}
}
func (dm *DocumentMatchInternal) Reset() *DocumentMatchInternal {
*dm = DocumentMatchInternal{}
return dm
}
func (dm *DocumentMatchInternal) Finalize(r index.IndexReader) (rv *DocumentMatch, err error) {
rv = &DocumentMatch{}
rv.ID, err = r.FinalizeDocID(dm.ID)
if err != nil {
return nil, err
}
rv.Index = dm.Index
rv.Expl = dm.Expl
rv.Fields = dm.Fields
rv.Fragments = dm.Fragments
rv.Locations = dm.Locations
rv.Score = dm.Score
return rv, nil
}
type DocumentMatch struct {
Index string `json:"index,omitempty"`
ID string `json:"id"`
Score float64 `json:"score"`
Expl *Explanation `json:"explanation,omitempty"`
Locations FieldTermLocationMap `json:"locations,omitempty"`
Fragments FieldFragmentMap `json:"fragments,omitempty"`
Index string `json:"index,omitempty"`
ID string `json:"id"`
IndexInternalID index.IndexInternalID `json:"-"`
Score float64 `json:"score"`
Expl *Explanation `json:"explanation,omitempty"`
Locations FieldTermLocationMap `json:"locations,omitempty"`
Fragments FieldFragmentMap `json:"fragments,omitempty"`
// Fields contains the values for document fields listed in
// SearchRequest.Fields. Text fields are returned as strings, numeric
@ -133,8 +100,8 @@ func (c DocumentMatchCollection) Swap(i, j int) { c[i], c[j] = c[j], c[i] }
func (c DocumentMatchCollection) Less(i, j int) bool { return c[i].Score > c[j].Score }
type Searcher interface {
Next(preAllocated *DocumentMatchInternal) (*DocumentMatchInternal, error)
Advance(ID index.IndexInternalID, preAllocated *DocumentMatchInternal) (*DocumentMatchInternal, error)
Next(preAllocated *DocumentMatch) (*DocumentMatch, error)
Advance(ID index.IndexInternalID, preAllocated *DocumentMatch) (*DocumentMatch, error)
Close() error
Weight() float64
SetQueryNorm(float64)

View File

@ -24,9 +24,9 @@ type BooleanSearcher struct {
shouldSearcher search.Searcher
mustNotSearcher search.Searcher
queryNorm float64
currMust *search.DocumentMatchInternal
currShould *search.DocumentMatchInternal
currMustNot *search.DocumentMatchInternal
currMust *search.DocumentMatch
currShould *search.DocumentMatch
currMustNot *search.DocumentMatch
currentID index.IndexInternalID
min uint64
scorer *scorers.ConjunctionQueryScorer
@ -91,9 +91,9 @@ func (s *BooleanSearcher) initSearchers() error {
}
if s.mustSearcher != nil && s.currMust != nil {
s.currentID = s.currMust.ID
s.currentID = s.currMust.IndexInternalID
} else if s.mustSearcher == nil && s.currShould != nil {
s.currentID = s.currShould.ID
s.currentID = s.currShould.IndexInternalID
} else {
s.currentID = nil
}
@ -118,9 +118,9 @@ func (s *BooleanSearcher) advanceNextMust() error {
}
if s.mustSearcher != nil && s.currMust != nil {
s.currentID = s.currMust.ID
s.currentID = s.currMust.IndexInternalID
} else if s.mustSearcher == nil && s.currShould != nil {
s.currentID = s.currShould.ID
s.currentID = s.currShould.IndexInternalID
} else {
s.currentID = nil
}
@ -148,7 +148,7 @@ func (s *BooleanSearcher) SetQueryNorm(qnorm float64) {
}
}
func (s *BooleanSearcher) Next(preAllocated *search.DocumentMatchInternal) (*search.DocumentMatchInternal, error) {
func (s *BooleanSearcher) Next(preAllocated *search.DocumentMatch) (*search.DocumentMatch, error) {
if !s.initialized {
err := s.initSearchers()
@ -158,16 +158,16 @@ func (s *BooleanSearcher) Next(preAllocated *search.DocumentMatchInternal) (*sea
}
var err error
var rv *search.DocumentMatchInternal
var rv *search.DocumentMatch
for s.currentID != nil {
if s.currMustNot != nil && s.currMustNot.ID.Compare(s.currentID) < 0 {
if s.currMustNot != nil && s.currMustNot.IndexInternalID.Compare(s.currentID) < 0 {
// advance must not searcher to our candidate entry
s.currMustNot, err = s.mustNotSearcher.Advance(s.currentID, nil)
if err != nil {
return nil, err
}
if s.currMustNot != nil && s.currMustNot.ID.Equals(s.currentID) {
if s.currMustNot != nil && s.currMustNot.IndexInternalID.Equals(s.currentID) {
// the candidate is excluded
err = s.advanceNextMust()
if err != nil {
@ -175,7 +175,7 @@ func (s *BooleanSearcher) Next(preAllocated *search.DocumentMatchInternal) (*sea
}
continue
}
} else if s.currMustNot != nil && s.currMustNot.ID.Equals(s.currentID) {
} else if s.currMustNot != nil && s.currMustNot.IndexInternalID.Equals(s.currentID) {
// the candidate is excluded
err = s.advanceNextMust()
if err != nil {
@ -184,22 +184,22 @@ func (s *BooleanSearcher) Next(preAllocated *search.DocumentMatchInternal) (*sea
continue
}
if s.currShould != nil && s.currShould.ID.Compare(s.currentID) < 0 {
if s.currShould != nil && s.currShould.IndexInternalID.Compare(s.currentID) < 0 {
// advance should searcher to our candidate entry
s.currShould, err = s.shouldSearcher.Advance(s.currentID, nil)
if err != nil {
return nil, err
}
if s.currShould != nil && s.currShould.ID.Equals(s.currentID) {
if s.currShould != nil && s.currShould.IndexInternalID.Equals(s.currentID) {
// score bonus matches should
var cons []*search.DocumentMatchInternal
var cons []*search.DocumentMatch
if s.currMust != nil {
cons = []*search.DocumentMatchInternal{
cons = []*search.DocumentMatch{
s.currMust,
s.currShould,
}
} else {
cons = []*search.DocumentMatchInternal{
cons = []*search.DocumentMatch{
s.currShould,
}
}
@ -211,23 +211,23 @@ func (s *BooleanSearcher) Next(preAllocated *search.DocumentMatchInternal) (*sea
break
} else if s.shouldSearcher.Min() == 0 {
// match is OK anyway
rv = s.scorer.Score([]*search.DocumentMatchInternal{s.currMust})
rv = s.scorer.Score([]*search.DocumentMatch{s.currMust})
err = s.advanceNextMust()
if err != nil {
return nil, err
}
break
}
} else if s.currShould != nil && s.currShould.ID.Equals(s.currentID) {
} else if s.currShould != nil && s.currShould.IndexInternalID.Equals(s.currentID) {
// score bonus matches should
var cons []*search.DocumentMatchInternal
var cons []*search.DocumentMatch
if s.currMust != nil {
cons = []*search.DocumentMatchInternal{
cons = []*search.DocumentMatch{
s.currMust,
s.currShould,
}
} else {
cons = []*search.DocumentMatchInternal{
cons = []*search.DocumentMatch{
s.currShould,
}
}
@ -239,7 +239,7 @@ func (s *BooleanSearcher) Next(preAllocated *search.DocumentMatchInternal) (*sea
break
} else if s.shouldSearcher == nil || s.shouldSearcher.Min() == 0 {
// match is OK anyway
rv = s.scorer.Score([]*search.DocumentMatchInternal{s.currMust})
rv = s.scorer.Score([]*search.DocumentMatch{s.currMust})
err = s.advanceNextMust()
if err != nil {
return nil, err
@ -255,7 +255,7 @@ func (s *BooleanSearcher) Next(preAllocated *search.DocumentMatchInternal) (*sea
return rv, nil
}
func (s *BooleanSearcher) Advance(ID index.IndexInternalID, preAllocated *search.DocumentMatchInternal) (*search.DocumentMatchInternal, error) {
func (s *BooleanSearcher) Advance(ID index.IndexInternalID, preAllocated *search.DocumentMatch) (*search.DocumentMatch, error) {
if !s.initialized {
err := s.initSearchers()
@ -285,9 +285,9 @@ func (s *BooleanSearcher) Advance(ID index.IndexInternalID, preAllocated *search
}
if s.mustSearcher != nil && s.currMust != nil {
s.currentID = s.currMust.ID
s.currentID = s.currMust.IndexInternalID
} else if s.mustSearcher == nil && s.currShould != nil {
s.currentID = s.currShould.ID
s.currentID = s.currShould.IndexInternalID
} else {
s.currentID = nil
}

View File

@ -243,93 +243,93 @@ func TestBooleanSearch(t *testing.T) {
tests := []struct {
searcher search.Searcher
results []*search.DocumentMatchInternal
results []*search.DocumentMatch
}{
{
searcher: booleanSearcher,
results: []*search.DocumentMatchInternal{
results: []*search.DocumentMatch{
{
ID: index.IndexInternalID("1"),
Score: 0.9818005051949021,
IndexInternalID: index.IndexInternalID("1"),
Score: 0.9818005051949021,
},
{
ID: index.IndexInternalID("3"),
Score: 0.808709699395535,
IndexInternalID: index.IndexInternalID("3"),
Score: 0.808709699395535,
},
{
ID: index.IndexInternalID("4"),
Score: 0.34618161159873423,
IndexInternalID: index.IndexInternalID("4"),
Score: 0.34618161159873423,
},
},
},
{
searcher: booleanSearcher2,
results: []*search.DocumentMatchInternal{
results: []*search.DocumentMatch{
{
ID: index.IndexInternalID("1"),
Score: 0.6775110856165737,
IndexInternalID: index.IndexInternalID("1"),
Score: 0.6775110856165737,
},
{
ID: index.IndexInternalID("3"),
Score: 0.6775110856165737,
IndexInternalID: index.IndexInternalID("3"),
Score: 0.6775110856165737,
},
},
},
// no MUST or SHOULD clauses yields no results
{
searcher: booleanSearcher3,
results: []*search.DocumentMatchInternal{},
results: []*search.DocumentMatch{},
},
{
searcher: booleanSearcher4,
results: []*search.DocumentMatchInternal{
results: []*search.DocumentMatch{
{
ID: index.IndexInternalID("1"),
Score: 1.0,
IndexInternalID: index.IndexInternalID("1"),
Score: 1.0,
},
{
ID: index.IndexInternalID("3"),
Score: 0.5,
IndexInternalID: index.IndexInternalID("3"),
Score: 0.5,
},
{
ID: index.IndexInternalID("4"),
Score: 1.0,
IndexInternalID: index.IndexInternalID("4"),
Score: 1.0,
},
},
},
{
searcher: booleanSearcher5,
results: []*search.DocumentMatchInternal{
results: []*search.DocumentMatch{
{
ID: index.IndexInternalID("3"),
Score: 0.5,
IndexInternalID: index.IndexInternalID("3"),
Score: 0.5,
},
{
ID: index.IndexInternalID("4"),
Score: 1.0,
IndexInternalID: index.IndexInternalID("4"),
Score: 1.0,
},
},
},
{
searcher: booleanSearcher6,
results: []*search.DocumentMatchInternal{},
results: []*search.DocumentMatch{},
},
// test a conjunction query with a nested boolean
{
searcher: conjunctionSearcher7,
results: []*search.DocumentMatchInternal{
results: []*search.DocumentMatch{
{
ID: index.IndexInternalID("1"),
Score: 2.0097428702814377,
IndexInternalID: index.IndexInternalID("1"),
Score: 2.0097428702814377,
},
},
},
{
searcher: conjunctionSearcher8,
results: []*search.DocumentMatchInternal{
results: []*search.DocumentMatch{
{
ID: index.IndexInternalID("3"),
Score: 2.0681575785068107,
IndexInternalID: index.IndexInternalID("3"),
Score: 2.0681575785068107,
},
},
},
@ -347,8 +347,8 @@ func TestBooleanSearch(t *testing.T) {
i := 0
for err == nil && next != nil {
if i < len(test.results) {
if !next.ID.Equals(test.results[i].ID) {
t.Errorf("expected result %d to have id %s got %s for test %d", i, test.results[i].ID, next.ID, testIndex)
if !next.IndexInternalID.Equals(test.results[i].IndexInternalID) {
t.Errorf("expected result %d to have id %s got %s for test %d", i, test.results[i].IndexInternalID, next.IndexInternalID, testIndex)
}
if !scoresCloseEnough(next.Score, test.results[i].Score) {
t.Errorf("expected result %d to have score %v got %v for test %d", i, test.results[i].Score, next.Score, testIndex)

View File

@ -24,7 +24,7 @@ type ConjunctionSearcher struct {
searchers OrderedSearcherList
explain bool
queryNorm float64
currs []*search.DocumentMatchInternal
currs []*search.DocumentMatch
currentID index.IndexInternalID
scorer *scorers.ConjunctionQueryScorer
}
@ -42,7 +42,7 @@ func NewConjunctionSearcher(indexReader index.IndexReader, qsearchers []search.S
indexReader: indexReader,
explain: explain,
searchers: searchers,
currs: make([]*search.DocumentMatchInternal, len(searchers)),
currs: make([]*search.DocumentMatch, len(searchers)),
scorer: scorers.NewConjunctionQueryScorer(explain),
}
rv.computeQueryNorm()
@ -75,7 +75,7 @@ func (s *ConjunctionSearcher) initSearchers() error {
if len(s.currs) > 0 {
if s.currs[0] != nil {
s.currentID = s.currs[0].ID
s.currentID = s.currs[0].IndexInternalID
} else {
s.currentID = nil
}
@ -99,21 +99,21 @@ func (s *ConjunctionSearcher) SetQueryNorm(qnorm float64) {
}
}
func (s *ConjunctionSearcher) Next(preAllocated *search.DocumentMatchInternal) (*search.DocumentMatchInternal, error) {
func (s *ConjunctionSearcher) Next(preAllocated *search.DocumentMatch) (*search.DocumentMatch, error) {
if !s.initialized {
err := s.initSearchers()
if err != nil {
return nil, err
}
}
var rv *search.DocumentMatchInternal
var rv *search.DocumentMatch
var err error
OUTER:
for s.currentID != nil {
for i, termSearcher := range s.searchers {
if s.currs[i] != nil && !s.currs[i].ID.Equals(s.currentID) {
if s.currentID.Compare(s.currs[i].ID) < 0 {
s.currentID = s.currs[i].ID
if s.currs[i] != nil && !s.currs[i].IndexInternalID.Equals(s.currentID) {
if s.currentID.Compare(s.currs[i].IndexInternalID) < 0 {
s.currentID = s.currs[i].IndexInternalID
continue OUTER
}
// this reader doesn't have the currentID, try to advance
@ -125,10 +125,10 @@ OUTER:
s.currentID = nil
continue OUTER
}
if !s.currs[i].ID.Equals(s.currentID) {
if !s.currs[i].IndexInternalID.Equals(s.currentID) {
// we just advanced, so it doesn't match, it must be greater
// no need to call next
s.currentID = s.currs[i].ID
s.currentID = s.currs[i].IndexInternalID
continue OUTER
}
} else if s.currs[i] == nil {
@ -147,7 +147,7 @@ OUTER:
if s.currs[0] == nil {
s.currentID = nil
} else {
s.currentID = s.currs[0].ID
s.currentID = s.currs[0].IndexInternalID
}
// don't continue now, wait for the next call to Next()
break
@ -155,7 +155,7 @@ OUTER:
return rv, nil
}
func (s *ConjunctionSearcher) Advance(ID index.IndexInternalID, preAllocated *search.DocumentMatchInternal) (*search.DocumentMatchInternal, error) {
func (s *ConjunctionSearcher) Advance(ID index.IndexInternalID, preAllocated *search.DocumentMatch) (*search.DocumentMatch, error) {
if !s.initialized {
err := s.initSearchers()
if err != nil {

View File

@ -123,58 +123,58 @@ func TestConjunctionSearch(t *testing.T) {
tests := []struct {
searcher search.Searcher
results []*search.DocumentMatchInternal
results []*search.DocumentMatch
}{
{
searcher: beerAndMartySearcher,
results: []*search.DocumentMatchInternal{
results: []*search.DocumentMatch{
{
ID: index.IndexInternalID("1"),
Score: 2.0097428702814377,
IndexInternalID: index.IndexInternalID("1"),
Score: 2.0097428702814377,
},
},
},
{
searcher: angstAndBeerSearcher,
results: []*search.DocumentMatchInternal{
results: []*search.DocumentMatch{
{
ID: index.IndexInternalID("2"),
Score: 1.0807601687084403,
IndexInternalID: index.IndexInternalID("2"),
Score: 1.0807601687084403,
},
},
},
{
searcher: beerAndJackSearcher,
results: []*search.DocumentMatchInternal{},
results: []*search.DocumentMatch{},
},
{
searcher: beerAndMisterSearcher,
results: []*search.DocumentMatchInternal{
results: []*search.DocumentMatch{
{
ID: index.IndexInternalID("2"),
Score: 1.2877980334016337,
IndexInternalID: index.IndexInternalID("2"),
Score: 1.2877980334016337,
},
{
ID: index.IndexInternalID("3"),
Score: 1.2877980334016337,
IndexInternalID: index.IndexInternalID("3"),
Score: 1.2877980334016337,
},
},
},
{
searcher: couchbaseAndMisterSearcher,
results: []*search.DocumentMatchInternal{
results: []*search.DocumentMatch{
{
ID: index.IndexInternalID("2"),
Score: 1.4436599157093672,
IndexInternalID: index.IndexInternalID("2"),
Score: 1.4436599157093672,
},
},
},
{
searcher: beerAndCouchbaseAndMisterSearcher,
results: []*search.DocumentMatchInternal{
results: []*search.DocumentMatch{
{
ID: index.IndexInternalID("2"),
Score: 1.441614953806971,
IndexInternalID: index.IndexInternalID("2"),
Score: 1.441614953806971,
},
},
},
@ -192,8 +192,8 @@ func TestConjunctionSearch(t *testing.T) {
i := 0
for err == nil && next != nil {
if i < len(test.results) {
if !next.ID.Equals(test.results[i].ID) {
t.Errorf("expected result %d to have id %s got %s for test %d", i, test.results[i].ID, next.ID, testIndex)
if !next.IndexInternalID.Equals(test.results[i].IndexInternalID) {
t.Errorf("expected result %d to have id %s got %s for test %d", i, test.results[i].IndexInternalID, next.IndexInternalID, testIndex)
}
if !scoresCloseEnough(next.Score, test.results[i].Score) {
t.Errorf("expected result %d to have score %v got %v for test %d", i, test.results[i].Score, next.Score, testIndex)

View File

@ -29,7 +29,7 @@ type DisjunctionSearcher struct {
indexReader index.IndexReader
searchers OrderedSearcherList
queryNorm float64
currs []*search.DocumentMatchInternal
currs []*search.DocumentMatch
currentID index.IndexInternalID
scorer *scorers.DisjunctionQueryScorer
min float64
@ -61,7 +61,7 @@ func NewDisjunctionSearcher(indexReader index.IndexReader, qsearchers []search.S
rv := DisjunctionSearcher{
indexReader: indexReader,
searchers: searchers,
currs: make([]*search.DocumentMatchInternal, len(searchers)),
currs: make([]*search.DocumentMatch, len(searchers)),
scorer: scorers.NewDisjunctionQueryScorer(explain),
min: min,
}
@ -101,8 +101,8 @@ func (s *DisjunctionSearcher) initSearchers() error {
func (s *DisjunctionSearcher) nextSmallestID() index.IndexInternalID {
var rv index.IndexInternalID
for _, curr := range s.currs {
if curr != nil && (curr.ID.Compare(rv) < 0 || rv == nil) {
rv = curr.ID
if curr != nil && (curr.IndexInternalID.Compare(rv) < 0 || rv == nil) {
rv = curr.IndexInternalID
}
}
return rv
@ -122,7 +122,7 @@ func (s *DisjunctionSearcher) SetQueryNorm(qnorm float64) {
}
}
func (s *DisjunctionSearcher) Next(preAllocated *search.DocumentMatchInternal) (*search.DocumentMatchInternal, error) {
func (s *DisjunctionSearcher) Next(preAllocated *search.DocumentMatch) (*search.DocumentMatch, error) {
if !s.initialized {
err := s.initSearchers()
if err != nil {
@ -130,13 +130,13 @@ func (s *DisjunctionSearcher) Next(preAllocated *search.DocumentMatchInternal) (
}
}
var err error
var rv *search.DocumentMatchInternal
matching := make([]*search.DocumentMatchInternal, 0, len(s.searchers))
var rv *search.DocumentMatch
matching := make([]*search.DocumentMatch, 0, len(s.searchers))
found := false
for !found && s.currentID != nil {
for _, curr := range s.currs {
if curr != nil && curr.ID.Equals(s.currentID) {
if curr != nil && curr.IndexInternalID.Equals(s.currentID) {
matching = append(matching, curr)
}
}
@ -148,10 +148,10 @@ func (s *DisjunctionSearcher) Next(preAllocated *search.DocumentMatchInternal) (
}
// reset matching
matching = make([]*search.DocumentMatchInternal, 0)
matching = make([]*search.DocumentMatch, 0)
// invoke next on all the matching searchers
for i, curr := range s.currs {
if curr != nil && curr.ID.Equals(s.currentID) {
if curr != nil && curr.IndexInternalID.Equals(s.currentID) {
searcher := s.searchers[i]
s.currs[i], err = searcher.Next(nil)
if err != nil {
@ -164,7 +164,7 @@ func (s *DisjunctionSearcher) Next(preAllocated *search.DocumentMatchInternal) (
return rv, nil
}
func (s *DisjunctionSearcher) Advance(ID index.IndexInternalID, preAllocated *search.DocumentMatchInternal) (*search.DocumentMatchInternal, error) {
func (s *DisjunctionSearcher) Advance(ID index.IndexInternalID, preAllocated *search.DocumentMatch) (*search.DocumentMatch, error) {
if !s.initialized {
err := s.initSearchers()
if err != nil {

View File

@ -66,36 +66,36 @@ func TestDisjunctionSearch(t *testing.T) {
tests := []struct {
searcher search.Searcher
results []*search.DocumentMatchInternal
results []*search.DocumentMatch
}{
{
searcher: martyOrDustinSearcher,
results: []*search.DocumentMatchInternal{
results: []*search.DocumentMatch{
{
ID: index.IndexInternalID("1"),
Score: 0.6775110856165737,
IndexInternalID: index.IndexInternalID("1"),
Score: 0.6775110856165737,
},
{
ID: index.IndexInternalID("3"),
Score: 0.6775110856165737,
IndexInternalID: index.IndexInternalID("3"),
Score: 0.6775110856165737,
},
},
},
// test a nested disjunction
{
searcher: nestedRaviOrMartyOrDustinSearcher,
results: []*search.DocumentMatchInternal{
results: []*search.DocumentMatch{
{
ID: index.IndexInternalID("1"),
Score: 0.2765927424732821,
IndexInternalID: index.IndexInternalID("1"),
Score: 0.2765927424732821,
},
{
ID: index.IndexInternalID("3"),
Score: 0.2765927424732821,
IndexInternalID: index.IndexInternalID("3"),
Score: 0.2765927424732821,
},
{
ID: index.IndexInternalID("4"),
Score: 0.5531854849465642,
IndexInternalID: index.IndexInternalID("4"),
Score: 0.5531854849465642,
},
},
},
@ -113,8 +113,8 @@ func TestDisjunctionSearch(t *testing.T) {
i := 0
for err == nil && next != nil {
if i < len(test.results) {
if !next.ID.Equals(test.results[i].ID) {
t.Errorf("expected result %d to have id %s got %s for test %d", i, test.results[i].ID, next.ID, testIndex)
if !next.IndexInternalID.Equals(test.results[i].IndexInternalID) {
t.Errorf("expected result %d to have id %s got %s for test %d", i, test.results[i].IndexInternalID, next.IndexInternalID, testIndex)
}
if !scoresCloseEnough(next.Score, test.results[i].Score) {
t.Errorf("expected result %d to have score %v got %v for test %d", i, test.results[i].Score, next.Score, testIndex)

View File

@ -82,7 +82,7 @@ func (s *DocIDSearcher) SetQueryNorm(qnorm float64) {
s.scorer.SetQueryNorm(qnorm)
}
func (s *DocIDSearcher) Next(preAllocated *search.DocumentMatchInternal) (*search.DocumentMatchInternal, error) {
func (s *DocIDSearcher) Next(preAllocated *search.DocumentMatch) (*search.DocumentMatch, error) {
// if s.current >= len(s.ids) {
// return nil, nil
// }
@ -103,7 +103,7 @@ func (s *DocIDSearcher) Next(preAllocated *search.DocumentMatchInternal) (*searc
return docMatch, nil
}
func (s *DocIDSearcher) Advance(ID index.IndexInternalID, preAllocated *search.DocumentMatchInternal) (*search.DocumentMatchInternal, error) {
func (s *DocIDSearcher) Advance(ID index.IndexInternalID, preAllocated *search.DocumentMatch) (*search.DocumentMatch, error) {
// s.current = sort.SearchStrings(s.ids, ID)
// return s.Next(preAllocated)

View File

@ -68,8 +68,8 @@ func testDocIDSearcher(t *testing.T, indexed, searched, wanted []string) {
if err != nil {
t.Fatal(err)
}
if !index.IndexInternalID(id).Equals(m.ID) {
t.Fatalf("expected %v at position %v, got %v", id, i, m.ID)
if !index.IndexInternalID(id).Equals(m.IndexInternalID) {
t.Fatalf("expected %v at position %v, got %v", id, i, m.IndexInternalID)
}
}
m, err := searcher.Next(nil)
@ -77,7 +77,7 @@ func testDocIDSearcher(t *testing.T, indexed, searched, wanted []string) {
t.Fatal(err)
}
if m != nil {
t.Fatalf("expected nil past the end of the sequence, got %v", m.ID)
t.Fatalf("expected nil past the end of the sequence, got %v", m.IndexInternalID)
}
// Check seeking
@ -91,7 +91,7 @@ func testDocIDSearcher(t *testing.T, indexed, searched, wanted []string) {
if err != nil {
t.Fatal(err)
}
if m == nil || !m.ID.Equals(index.IndexInternalID(id)) {
if m == nil || !m.IndexInternalID.Equals(index.IndexInternalID(id)) {
t.Fatalf("advancing to %v returned %v instead of %v", before, m, id)
}
}

View File

@ -107,12 +107,12 @@ func (s *FuzzySearcher) SetQueryNorm(qnorm float64) {
s.searcher.SetQueryNorm(qnorm)
}
func (s *FuzzySearcher) Next(preAllocated *search.DocumentMatchInternal) (*search.DocumentMatchInternal, error) {
func (s *FuzzySearcher) Next(preAllocated *search.DocumentMatch) (*search.DocumentMatch, error) {
return s.searcher.Next(preAllocated)
}
func (s *FuzzySearcher) Advance(ID index.IndexInternalID, preAllocated *search.DocumentMatchInternal) (*search.DocumentMatchInternal, error) {
func (s *FuzzySearcher) Advance(ID index.IndexInternalID, preAllocated *search.DocumentMatch) (*search.DocumentMatch, error) {
return s.searcher.Advance(ID, preAllocated)
}

View File

@ -51,48 +51,48 @@ func TestFuzzySearch(t *testing.T) {
tests := []struct {
searcher search.Searcher
results []*search.DocumentMatchInternal
results []*search.DocumentMatch
}{
{
searcher: fuzzySearcherbeet,
results: []*search.DocumentMatchInternal{
results: []*search.DocumentMatch{
{
ID: index.IndexInternalID("1"),
Score: 1.0,
IndexInternalID: index.IndexInternalID("1"),
Score: 1.0,
},
{
ID: index.IndexInternalID("2"),
Score: 0.5,
IndexInternalID: index.IndexInternalID("2"),
Score: 0.5,
},
{
ID: index.IndexInternalID("3"),
Score: 0.5,
IndexInternalID: index.IndexInternalID("3"),
Score: 0.5,
},
{
ID: index.IndexInternalID("4"),
Score: 0.9999999838027345,
IndexInternalID: index.IndexInternalID("4"),
Score: 0.9999999838027345,
},
},
},
{
searcher: fuzzySearcherdouches,
results: []*search.DocumentMatchInternal{},
results: []*search.DocumentMatch{},
},
{
searcher: fuzzySearcheraplee,
results: []*search.DocumentMatchInternal{
results: []*search.DocumentMatch{
{
ID: index.IndexInternalID("3"),
Score: 0.9581453659370776,
IndexInternalID: index.IndexInternalID("3"),
Score: 0.9581453659370776,
},
},
},
{
searcher: fuzzySearcherprefix,
results: []*search.DocumentMatchInternal{
results: []*search.DocumentMatch{
{
ID: index.IndexInternalID("5"),
Score: 1.916290731874155,
IndexInternalID: index.IndexInternalID("5"),
Score: 1.916290731874155,
},
},
},
@ -110,8 +110,8 @@ func TestFuzzySearch(t *testing.T) {
i := 0
for err == nil && next != nil {
if i < len(test.results) {
if !next.ID.Equals(test.results[i].ID) {
t.Errorf("expected result %d to have id %s got %s for test %d", i, test.results[i].ID, next.ID, testIndex)
if !next.IndexInternalID.Equals(test.results[i].IndexInternalID) {
t.Errorf("expected result %d to have id %s got %s for test %d", i, test.results[i].IndexInternalID, next.IndexInternalID, testIndex)
}
if next.Score != test.results[i].Score {
t.Errorf("expected result %d to have score %v got %v for test %d", i, test.results[i].Score, next.Score, testIndex)

View File

@ -46,7 +46,7 @@ func (s *MatchAllSearcher) SetQueryNorm(qnorm float64) {
s.scorer.SetQueryNorm(qnorm)
}
func (s *MatchAllSearcher) Next(preAllocated *search.DocumentMatchInternal) (*search.DocumentMatchInternal, error) {
func (s *MatchAllSearcher) Next(preAllocated *search.DocumentMatch) (*search.DocumentMatch, error) {
id, err := s.reader.Next()
if err != nil {
return nil, err
@ -63,7 +63,7 @@ func (s *MatchAllSearcher) Next(preAllocated *search.DocumentMatchInternal) (*se
}
func (s *MatchAllSearcher) Advance(ID index.IndexInternalID, preAllocated *search.DocumentMatchInternal) (*search.DocumentMatchInternal, error) {
func (s *MatchAllSearcher) Advance(ID index.IndexInternalID, preAllocated *search.DocumentMatch) (*search.DocumentMatch, error) {
id, err := s.reader.Advance(ID)
if err != nil {
return nil, err

View File

@ -42,57 +42,57 @@ func TestMatchAllSearch(t *testing.T) {
tests := []struct {
searcher search.Searcher
queryNorm float64
results []*search.DocumentMatchInternal
results []*search.DocumentMatch
}{
{
searcher: allSearcher,
queryNorm: 1.0,
results: []*search.DocumentMatchInternal{
results: []*search.DocumentMatch{
{
ID: index.IndexInternalID("1"),
Score: 1.0,
IndexInternalID: index.IndexInternalID("1"),
Score: 1.0,
},
{
ID: index.IndexInternalID("2"),
Score: 1.0,
IndexInternalID: index.IndexInternalID("2"),
Score: 1.0,
},
{
ID: index.IndexInternalID("3"),
Score: 1.0,
IndexInternalID: index.IndexInternalID("3"),
Score: 1.0,
},
{
ID: index.IndexInternalID("4"),
Score: 1.0,
IndexInternalID: index.IndexInternalID("4"),
Score: 1.0,
},
{
ID: index.IndexInternalID("5"),
Score: 1.0,
IndexInternalID: index.IndexInternalID("5"),
Score: 1.0,
},
},
},
{
searcher: allSearcher2,
queryNorm: 0.8333333,
results: []*search.DocumentMatchInternal{
results: []*search.DocumentMatch{
{
ID: index.IndexInternalID("1"),
Score: 1.0,
IndexInternalID: index.IndexInternalID("1"),
Score: 1.0,
},
{
ID: index.IndexInternalID("2"),
Score: 1.0,
IndexInternalID: index.IndexInternalID("2"),
Score: 1.0,
},
{
ID: index.IndexInternalID("3"),
Score: 1.0,
IndexInternalID: index.IndexInternalID("3"),
Score: 1.0,
},
{
ID: index.IndexInternalID("4"),
Score: 1.0,
IndexInternalID: index.IndexInternalID("4"),
Score: 1.0,
},
{
ID: index.IndexInternalID("5"),
Score: 1.0,
IndexInternalID: index.IndexInternalID("5"),
Score: 1.0,
},
},
},
@ -114,8 +114,8 @@ func TestMatchAllSearch(t *testing.T) {
i := 0
for err == nil && next != nil {
if i < len(test.results) {
if !next.ID.Equals(test.results[i].ID) {
t.Errorf("expected result %d to have id %s got %s for test %d", i, test.results[i].ID, next.ID, testIndex)
if !next.IndexInternalID.Equals(test.results[i].IndexInternalID) {
t.Errorf("expected result %d to have id %s got %s for test %d", i, test.results[i].IndexInternalID, next.IndexInternalID, testIndex)
}
if !scoresCloseEnough(next.Score, test.results[i].Score) {
t.Errorf("expected result %d to have score %v got %v for test %d", i, test.results[i].Score, next.Score, testIndex)

View File

@ -36,11 +36,11 @@ func (s *MatchNoneSearcher) SetQueryNorm(qnorm float64) {
}
func (s *MatchNoneSearcher) Next(preAllocated *search.DocumentMatchInternal) (*search.DocumentMatchInternal, error) {
func (s *MatchNoneSearcher) Next(preAllocated *search.DocumentMatch) (*search.DocumentMatch, error) {
return nil, nil
}
func (s *MatchNoneSearcher) Advance(ID index.IndexInternalID, preAllocated *search.DocumentMatchInternal) (*search.DocumentMatchInternal, error) {
func (s *MatchNoneSearcher) Advance(ID index.IndexInternalID, preAllocated *search.DocumentMatch) (*search.DocumentMatch, error) {
return nil, nil
}

View File

@ -35,11 +35,11 @@ func TestMatchNoneSearch(t *testing.T) {
tests := []struct {
searcher search.Searcher
results []*search.DocumentMatchInternal
results []*search.DocumentMatch
}{
{
searcher: noneSearcher,
results: []*search.DocumentMatchInternal{},
results: []*search.DocumentMatch{},
},
}
@ -55,8 +55,8 @@ func TestMatchNoneSearch(t *testing.T) {
i := 0
for err == nil && next != nil {
if i < len(test.results) {
if !next.ID.Equals(test.results[i].ID) {
t.Errorf("expected result %d to have id %s got %s for test %d", i, test.results[i].ID, next.ID, testIndex)
if !next.IndexInternalID.Equals(test.results[i].IndexInternalID) {
t.Errorf("expected result %d to have id %s got %s for test %d", i, test.results[i].IndexInternalID, next.IndexInternalID, testIndex)
}
if !scoresCloseEnough(next.Score, test.results[i].Score) {
t.Errorf("expected result %d to have score %v got %v for test %d", i, test.results[i].Score, next.Score, testIndex)

View File

@ -96,11 +96,11 @@ func (s *NumericRangeSearcher) SetQueryNorm(qnorm float64) {
s.searcher.SetQueryNorm(qnorm)
}
func (s *NumericRangeSearcher) Next(preAllocated *search.DocumentMatchInternal) (*search.DocumentMatchInternal, error) {
func (s *NumericRangeSearcher) Next(preAllocated *search.DocumentMatch) (*search.DocumentMatch, error) {
return s.searcher.Next(preAllocated)
}
func (s *NumericRangeSearcher) Advance(ID index.IndexInternalID, preAllocated *search.DocumentMatchInternal) (*search.DocumentMatchInternal, error) {
func (s *NumericRangeSearcher) Advance(ID index.IndexInternalID, preAllocated *search.DocumentMatch) (*search.DocumentMatch, error) {
return s.searcher.Advance(ID, preAllocated)
}

View File

@ -21,7 +21,7 @@ type PhraseSearcher struct {
indexReader index.IndexReader
mustSearcher *ConjunctionSearcher
queryNorm float64
currMust *search.DocumentMatchInternal
currMust *search.DocumentMatch
slop int
terms []string
}
@ -90,7 +90,7 @@ func (s *PhraseSearcher) SetQueryNorm(qnorm float64) {
s.mustSearcher.SetQueryNorm(qnorm)
}
func (s *PhraseSearcher) Next(preAllocated *search.DocumentMatchInternal) (*search.DocumentMatchInternal, error) {
func (s *PhraseSearcher) Next(preAllocated *search.DocumentMatch) (*search.DocumentMatch, error) {
if !s.initialized {
err := s.initSearchers()
if err != nil {
@ -98,7 +98,7 @@ func (s *PhraseSearcher) Next(preAllocated *search.DocumentMatchInternal) (*sear
}
}
var rv *search.DocumentMatchInternal
var rv *search.DocumentMatch
for s.currMust != nil {
rvftlm := make(search.FieldTermLocationMap, 0)
freq := 0
@ -160,7 +160,7 @@ func (s *PhraseSearcher) Next(preAllocated *search.DocumentMatchInternal) (*sear
return nil, nil
}
func (s *PhraseSearcher) Advance(ID index.IndexInternalID, preAllocated *search.DocumentMatchInternal) (*search.DocumentMatchInternal, error) {
func (s *PhraseSearcher) Advance(ID index.IndexInternalID, preAllocated *search.DocumentMatch) (*search.DocumentMatch, error) {
if !s.initialized {
err := s.initSearchers()
if err != nil {

View File

@ -48,14 +48,14 @@ func TestPhraseSearch(t *testing.T) {
tests := []struct {
searcher search.Searcher
results []*search.DocumentMatchInternal
results []*search.DocumentMatch
}{
{
searcher: phraseSearcher,
results: []*search.DocumentMatchInternal{
results: []*search.DocumentMatch{
{
ID: index.IndexInternalID("2"),
Score: 1.0807601687084403,
IndexInternalID: index.IndexInternalID("2"),
Score: 1.0807601687084403,
},
},
},
@ -73,8 +73,8 @@ func TestPhraseSearch(t *testing.T) {
i := 0
for err == nil && next != nil {
if i < len(test.results) {
if !next.ID.Equals(test.results[i].ID) {
t.Errorf("expected result %d to have id %s got %s for test %d", i, test.results[i].ID, next.ID, testIndex)
if !next.IndexInternalID.Equals(test.results[i].IndexInternalID) {
t.Errorf("expected result %d to have id %s got %s for test %d", i, test.results[i].IndexInternalID, next.IndexInternalID, testIndex)
}
if next.Score != test.results[i].Score {
t.Errorf("expected result %d to have score %v got %v for test %d", i, test.results[i].Score, next.Score, testIndex)

View File

@ -106,12 +106,12 @@ func (s *RegexpSearcher) SetQueryNorm(qnorm float64) {
s.searcher.SetQueryNorm(qnorm)
}
func (s *RegexpSearcher) Next(preAllocated *search.DocumentMatchInternal) (*search.DocumentMatchInternal, error) {
func (s *RegexpSearcher) Next(preAllocated *search.DocumentMatch) (*search.DocumentMatch, error) {
return s.searcher.Next(preAllocated)
}
func (s *RegexpSearcher) Advance(ID index.IndexInternalID, preAllocated *search.DocumentMatchInternal) (*search.DocumentMatchInternal, error) {
func (s *RegexpSearcher) Advance(ID index.IndexInternalID, preAllocated *search.DocumentMatch) (*search.DocumentMatch, error) {
return s.searcher.Advance(ID, preAllocated)
}

View File

@ -52,27 +52,27 @@ func TestRegexpSearch(t *testing.T) {
tests := []struct {
searcher search.Searcher
results []*search.DocumentMatchInternal
results []*search.DocumentMatch
}{
{
searcher: regexpSearcher,
results: []*search.DocumentMatchInternal{
results: []*search.DocumentMatch{
{
ID: index.IndexInternalID("1"),
Score: 1.916290731874155,
IndexInternalID: index.IndexInternalID("1"),
Score: 1.916290731874155,
},
},
},
{
searcher: regexpSearcherCo,
results: []*search.DocumentMatchInternal{
results: []*search.DocumentMatch{
{
ID: index.IndexInternalID("2"),
Score: 0.33875554280828685,
IndexInternalID: index.IndexInternalID("2"),
Score: 0.33875554280828685,
},
{
ID: index.IndexInternalID("3"),
Score: 0.33875554280828685,
IndexInternalID: index.IndexInternalID("3"),
Score: 0.33875554280828685,
},
},
},
@ -90,8 +90,8 @@ func TestRegexpSearch(t *testing.T) {
i := 0
for err == nil && next != nil {
if i < len(test.results) {
if !next.ID.Equals(test.results[i].ID) {
t.Errorf("expected result %d to have id %s got %s for test %d", i, test.results[i].ID, next.ID, testIndex)
if !next.IndexInternalID.Equals(test.results[i].IndexInternalID) {
t.Errorf("expected result %d to have id %s got %s for test %d", i, test.results[i].IndexInternalID, next.IndexInternalID, testIndex)
}
if next.Score != test.results[i].Score {
t.Errorf("expected result %d to have score %v got %v for test %d", i, test.results[i].Score, next.Score, testIndex)

View File

@ -53,7 +53,7 @@ func (s *TermSearcher) SetQueryNorm(qnorm float64) {
s.scorer.SetQueryNorm(qnorm)
}
func (s *TermSearcher) Next(preAllocated *search.DocumentMatchInternal) (*search.DocumentMatchInternal, error) {
func (s *TermSearcher) Next(preAllocated *search.DocumentMatch) (*search.DocumentMatch, error) {
termMatch, err := s.reader.Next(s.tfd.Reset())
if err != nil {
return nil, err
@ -70,7 +70,7 @@ func (s *TermSearcher) Next(preAllocated *search.DocumentMatchInternal) (*search
}
func (s *TermSearcher) Advance(ID index.IndexInternalID, preAllocated *search.DocumentMatchInternal) (*search.DocumentMatchInternal, error) {
func (s *TermSearcher) Advance(ID index.IndexInternalID, preAllocated *search.DocumentMatch) (*search.DocumentMatch, error) {
termMatch, err := s.reader.Advance(ID, s.tfd.Reset())
if err != nil {
return nil, err

View File

@ -70,12 +70,12 @@ func (s *TermPrefixSearcher) SetQueryNorm(qnorm float64) {
s.searcher.SetQueryNorm(qnorm)
}
func (s *TermPrefixSearcher) Next(preAllocated *search.DocumentMatchInternal) (*search.DocumentMatchInternal, error) {
func (s *TermPrefixSearcher) Next(preAllocated *search.DocumentMatch) (*search.DocumentMatch, error) {
return s.searcher.Next(preAllocated)
}
func (s *TermPrefixSearcher) Advance(ID index.IndexInternalID, preAllocated *search.DocumentMatchInternal) (*search.DocumentMatchInternal, error) {
func (s *TermPrefixSearcher) Advance(ID index.IndexInternalID, preAllocated *search.DocumentMatch) (*search.DocumentMatch, error) {
return s.searcher.Advance(ID, preAllocated)
}

View File

@ -167,15 +167,15 @@ func TestTermSearcher(t *testing.T) {
if err != nil {
t.Errorf("expected result, got %v", err)
}
if !docMatch.ID.Equals(index.IndexInternalID("a")) {
t.Errorf("expected result ID to be 'a', got '%s", docMatch.ID)
if !docMatch.IndexInternalID.Equals(index.IndexInternalID("a")) {
t.Errorf("expected result ID to be 'a', got '%s", docMatch.IndexInternalID)
}
docMatch, err = searcher.Advance(index.IndexInternalID("c"), nil)
if err != nil {
t.Errorf("expected result, got %v", err)
}
if !docMatch.ID.Equals(index.IndexInternalID("c")) {
t.Errorf("expected result ID to be 'c' got '%s'", docMatch.ID)
if !docMatch.IndexInternalID.Equals(index.IndexInternalID("c")) {
t.Errorf("expected result ID to be 'c' got '%s'", docMatch.IndexInternalID)
}
// try advancing past end