0
0
Fork 0

changed approach

IndexInternalID is now []byte
this is still opaque, and should still work for any future
index implementations as it is a least common denominator
choice, all implementations must internally represent the
id as []byte at some point for storage to disk
This commit is contained in:
Marty Schoch 2016-08-01 14:26:50 -04:00
parent 5aa9e95468
commit 1aacd9bad5
21 changed files with 172 additions and 207 deletions

View File

@ -10,6 +10,7 @@
package index
import (
"bytes"
"encoding/json"
"fmt"
"time"
@ -103,12 +104,14 @@ type TermFieldVector struct {
}
// IndexInternalID is an opaque document identifier interal to the index impl
// This allows us to delay the conversion to public identifier (string) and
// avoid it completely in other cases. It also servces to hide the underlying
// representation of a document identifer, allow more flexibility.
type IndexInternalID interface {
Equals(other IndexInternalID) bool
Compare(other IndexInternalID) int
type IndexInternalID []byte
func (id IndexInternalID) Equals(other IndexInternalID) bool {
return id.Compare(other) == 0
}
func (id IndexInternalID) Compare(other IndexInternalID) int {
return bytes.Compare(id, other)
}
type TermFieldDoc struct {

View File

@ -10,7 +10,6 @@
package upside_down
import (
"bytes"
"fmt"
"github.com/blevesearch/bleve/document"
@ -18,20 +17,6 @@ import (
"github.com/blevesearch/bleve/index/store"
)
type InternalId []byte
func (u InternalId) Compare(other index.IndexInternalID) int {
if other == nil {
// this internal ID is always greater than nil
return 1
}
return bytes.Compare(u, other.(InternalId))
}
func (u InternalId) Equals(other index.IndexInternalID) bool {
return u.Compare(other.(InternalId)) == 0
}
type IndexReader struct {
index *UpsideDownCouch
kvreader store.KVReader
@ -114,7 +99,7 @@ func (i *IndexReader) Document(id string) (doc *document.Document, err error) {
}
func (i *IndexReader) DocumentFieldTerms(id index.IndexInternalID) (index.FieldTerms, error) {
back, err := i.index.backIndexRowForDoc(i.kvreader, id.(InternalId))
back, err := i.index.backIndexRowForDoc(i.kvreader, id)
if err != nil {
return nil, err
}
@ -132,7 +117,7 @@ func (i *IndexReader) DocumentFieldTerms(id index.IndexInternalID) (index.FieldT
}
func (i *IndexReader) DocumentFieldTermsForFields(id index.IndexInternalID, fields []string) (index.FieldTerms, error) {
back, err := i.index.backIndexRowForDoc(i.kvreader, id.(InternalId))
back, err := i.index.backIndexRowForDoc(i.kvreader, id)
if err != nil {
return nil, err
}
@ -201,7 +186,7 @@ func (i *IndexReader) Close() error {
}
func (i *IndexReader) FinalizeDocID(id index.IndexInternalID) (string, error) {
return string(id.(InternalId)), nil
return string(id), nil
}
func incrementBytes(in []byte) []byte {

View File

@ -83,7 +83,7 @@ func (r *UpsideDownCouchTermFieldReader) Next(preAlloced *index.TermFieldDoc) (*
if rv == nil {
rv = &index.TermFieldDoc{}
}
rv.ID = InternalId(tfr.doc)
rv.ID = tfr.doc
rv.Freq = tfr.freq
rv.Norm = float64(tfr.norm)
if tfr.vectors != nil {
@ -96,8 +96,7 @@ func (r *UpsideDownCouchTermFieldReader) Next(preAlloced *index.TermFieldDoc) (*
return nil, nil
}
func (r *UpsideDownCouchTermFieldReader) Advance(docIDInternal index.IndexInternalID, preAlloced *index.TermFieldDoc) (*index.TermFieldDoc, error) {
docID := docIDInternal.(InternalId)
func (r *UpsideDownCouchTermFieldReader) Advance(docID index.IndexInternalID, preAlloced *index.TermFieldDoc) (*index.TermFieldDoc, error) {
if r.iterator != nil {
tfr := NewTermFrequencyRow(r.term, r.field, docID, 0, 0)
r.iterator.Seek(tfr.Key())
@ -111,7 +110,7 @@ func (r *UpsideDownCouchTermFieldReader) Advance(docIDInternal index.IndexIntern
if rv == nil {
rv = &index.TermFieldDoc{}
}
rv.ID = InternalId(tfr.doc)
rv.ID = tfr.doc
rv.Freq = tfr.freq
rv.Norm = float64(tfr.norm)
if tfr.vectors != nil {
@ -185,7 +184,7 @@ func (r *UpsideDownCouchDocIDReader) Next() (index.IndexInternalID, error) {
key, val, valid := r.iterator.Current()
if r.onlyMode {
var rv InternalId
var rv index.IndexInternalID
for valid && r.onlyPos < len(r.only) {
br, err := NewBackIndexRowKV(key, val)
if err != nil {
@ -200,7 +199,7 @@ func (r *UpsideDownCouchDocIDReader) Next() (index.IndexInternalID, error) {
key, val, valid = r.iterator.Current()
continue
} else {
rv = InternalId(br.doc)
rv = br.doc
break
}
}
@ -218,7 +217,7 @@ func (r *UpsideDownCouchDocIDReader) Next() (index.IndexInternalID, error) {
if err != nil {
return nil, err
}
rv := InternalId(br.doc)
rv := br.doc
r.iterator.Next()
return rv, nil
}
@ -227,14 +226,13 @@ func (r *UpsideDownCouchDocIDReader) Next() (index.IndexInternalID, error) {
}
func (r *UpsideDownCouchDocIDReader) Advance(docID index.IndexInternalID) (index.IndexInternalID, error) {
docIDInternal := docID.(InternalId)
bir := NewBackIndexRow(docIDInternal, nil, nil)
bir := NewBackIndexRow(docID, nil, nil)
r.iterator.Seek(bir.Key())
key, val, valid := r.iterator.Current()
r.onlyPos = sort.SearchStrings(r.only, string(docIDInternal))
r.onlyPos = sort.SearchStrings(r.only, string(docID))
if r.onlyMode {
var rv InternalId
var rv index.IndexInternalID
for valid && r.onlyPos < len(r.only) {
br, err := NewBackIndexRowKV(key, val)
if err != nil {
@ -248,7 +246,7 @@ func (r *UpsideDownCouchDocIDReader) Advance(docID index.IndexInternalID) (index
r.iterator.Seek(NewBackIndexRow([]byte(r.only[r.onlyPos]), nil, nil).Key())
continue
} else {
rv = InternalId(br.doc)
rv = br.doc
break
}
}
@ -265,7 +263,7 @@ func (r *UpsideDownCouchDocIDReader) Advance(docID index.IndexInternalID) (index
if err != nil {
return nil, err
}
rv := InternalId(br.doc)
rv := br.doc
r.iterator.Next()
return rv, nil
}

View File

@ -111,7 +111,7 @@ func TestIndexReader(t *testing.T) {
}
expectedMatch := &index.TermFieldDoc{
ID: InternalId("2"),
ID: index.IndexInternalID("2"),
Freq: 1,
Norm: 0.5773502588272095,
Vectors: []*index.TermFieldVector{
@ -145,17 +145,17 @@ func TestIndexReader(t *testing.T) {
t.Errorf("Error accessing term field reader: %v", err)
}
match, err = reader.Advance(InternalId("2"), nil)
match, err = reader.Advance(index.IndexInternalID("2"), nil)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
if match == nil {
t.Fatalf("Expected match, got nil")
}
if !match.ID.Equals(InternalId("2")) {
if !match.ID.Equals(index.IndexInternalID("2")) {
t.Errorf("Expected ID '2', got '%s'", match.ID)
}
match, err = reader.Advance(InternalId("3"), nil)
match, err = reader.Advance(index.IndexInternalID("3"), nil)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
@ -183,7 +183,7 @@ func TestIndexReader(t *testing.T) {
if match != nil {
t.Errorf("expected nil, got %v", match)
}
match, err = reader.Advance(InternalId("anywhere"), nil)
match, err = reader.Advance(index.IndexInternalID("anywhere"), nil)
if err != nil {
t.Errorf("unexpected error: %v", err)
}
@ -280,15 +280,15 @@ func TestIndexDocIdReader(t *testing.T) {
}
}()
id, err = reader2.Advance(InternalId("2"))
id, err = reader2.Advance(index.IndexInternalID("2"))
if err != nil {
t.Error(err)
}
if !id.Equals(InternalId("2")) {
if !id.Equals(index.IndexInternalID("2")) {
t.Errorf("expected to find id '2', got '%s'", id)
}
id, err = reader2.Advance(InternalId("3"))
id, err = reader2.Advance(index.IndexInternalID("3"))
if err != nil {
t.Error(err)
}

View File

@ -439,7 +439,7 @@ func (udc *UpsideDownCouch) Update(doc *document.Document) (err error) {
// first we lookup the backindex row for the doc id if it exists
// lookup the back index row
var backIndexRow *BackIndexRow
backIndexRow, err = udc.backIndexRowForDoc(kvreader, InternalId(doc.ID))
backIndexRow, err = udc.backIndexRowForDoc(kvreader, index.IndexInternalID(doc.ID))
if err != nil {
_ = kvreader.Close()
atomic.AddUint64(&udc.stats.errors, 1)
@ -627,7 +627,7 @@ func (udc *UpsideDownCouch) Delete(id string) (err error) {
// first we lookup the backindex row for the doc id if it exists
// lookup the back index row
var backIndexRow *BackIndexRow
backIndexRow, err = udc.backIndexRowForDoc(kvreader, InternalId(id))
backIndexRow, err = udc.backIndexRowForDoc(kvreader, index.IndexInternalID(id))
if err != nil {
_ = kvreader.Close()
atomic.AddUint64(&udc.stats.errors, 1)
@ -695,7 +695,7 @@ func (udc *UpsideDownCouch) deleteSingle(id string, backIndexRow *BackIndexRow,
return deleteRows
}
func (udc *UpsideDownCouch) backIndexRowForDoc(kvreader store.KVReader, docID InternalId) (*BackIndexRow, error) {
func (udc *UpsideDownCouch) backIndexRowForDoc(kvreader store.KVReader, docID index.IndexInternalID) (*BackIndexRow, error) {
// use a temporary row structure to build key
tempRow := &BackIndexRow{
doc: docID,
@ -833,7 +833,7 @@ func (udc *UpsideDownCouch) Batch(batch *index.Batch) (err error) {
}
for docID, doc := range batch.IndexOps {
backIndexRow, err := udc.backIndexRowForDoc(kvreader, InternalId(docID))
backIndexRow, err := udc.backIndexRowForDoc(kvreader, index.IndexInternalID(docID))
if err != nil {
docBackIndexRowErr = err
return

View File

@ -663,16 +663,16 @@ func TestIndexBatch(t *testing.T) {
if err != nil {
t.Error(err)
}
docIds := make([]InternalId, 0)
docIds := make([]index.IndexInternalID, 0)
docID, err := docIDReader.Next()
for docID != nil && err == nil {
docIds = append(docIds, docID.(InternalId))
docIds = append(docIds, docID)
docID, err = docIDReader.Next()
}
if err != nil {
t.Error(err)
}
expectedDocIds := []InternalId{InternalId("2"), InternalId("3")}
expectedDocIds := []index.IndexInternalID{index.IndexInternalID("2"), index.IndexInternalID("3")}
if !reflect.DeepEqual(docIds, expectedDocIds) {
t.Errorf("expected ids: %v, got ids: %v", expectedDocIds, docIds)
}
@ -1126,7 +1126,7 @@ func TestIndexTermReaderCompositeFields(t *testing.T) {
tfd, err := termFieldReader.Next(nil)
for tfd != nil && err == nil {
if !tfd.ID.Equals(InternalId("1")) {
if !tfd.ID.Equals(index.IndexInternalID("1")) {
t.Errorf("expected to find document id 1")
}
tfd, err = termFieldReader.Next(nil)
@ -1179,7 +1179,7 @@ func TestIndexDocumentFieldTerms(t *testing.T) {
}
}()
fieldTerms, err := indexReader.DocumentFieldTerms(InternalId("1"))
fieldTerms, err := indexReader.DocumentFieldTerms(index.IndexInternalID("1"))
if err != nil {
t.Error(err)
}

View File

@ -5,6 +5,7 @@ import (
"strconv"
"testing"
"github.com/blevesearch/bleve/index"
"github.com/blevesearch/bleve/search"
"golang.org/x/net/context"
)
@ -13,7 +14,7 @@ func benchHelper(numOfMatches int, collector search.Collector, b *testing.B) {
matches := make([]*search.DocumentMatchInternal, 0, numOfMatches)
for i := 0; i < numOfMatches; i++ {
matches = append(matches, &search.DocumentMatchInternal{
ID: testInternalId(strconv.Itoa(i)),
ID: index.IndexInternalID(strconv.Itoa(i)),
Score: rand.Float64(),
})
}

View File

@ -14,6 +14,7 @@ import (
"golang.org/x/net/context"
"github.com/blevesearch/bleve/index"
"github.com/blevesearch/bleve/search"
)
@ -25,59 +26,59 @@ func TestTop10Scores(t *testing.T) {
searcher := &stubSearcher{
matches: []*search.DocumentMatchInternal{
&search.DocumentMatchInternal{
ID: testInternalId("a"),
ID: index.IndexInternalID("a"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: testInternalId("b"),
ID: index.IndexInternalID("b"),
Score: 9,
},
&search.DocumentMatchInternal{
ID: testInternalId("c"),
ID: index.IndexInternalID("c"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: testInternalId("d"),
ID: index.IndexInternalID("d"),
Score: 9,
},
&search.DocumentMatchInternal{
ID: testInternalId("e"),
ID: index.IndexInternalID("e"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: testInternalId("f"),
ID: index.IndexInternalID("f"),
Score: 9,
},
&search.DocumentMatchInternal{
ID: testInternalId("g"),
ID: index.IndexInternalID("g"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: testInternalId("h"),
ID: index.IndexInternalID("h"),
Score: 9,
},
&search.DocumentMatchInternal{
ID: testInternalId("i"),
ID: index.IndexInternalID("i"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: testInternalId("j"),
ID: index.IndexInternalID("j"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: testInternalId("k"),
ID: index.IndexInternalID("k"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: testInternalId("l"),
ID: index.IndexInternalID("l"),
Score: 99,
},
&search.DocumentMatchInternal{
ID: testInternalId("m"),
ID: index.IndexInternalID("m"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: testInternalId("n"),
ID: index.IndexInternalID("n"),
Score: 11,
},
},
@ -133,59 +134,59 @@ func TestTop10ScoresSkip10(t *testing.T) {
searcher := &stubSearcher{
matches: []*search.DocumentMatchInternal{
&search.DocumentMatchInternal{
ID: testInternalId("a"),
ID: index.IndexInternalID("a"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: testInternalId("b"),
ID: index.IndexInternalID("b"),
Score: 9.5,
},
&search.DocumentMatchInternal{
ID: testInternalId("c"),
ID: index.IndexInternalID("c"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: testInternalId("d"),
ID: index.IndexInternalID("d"),
Score: 9,
},
&search.DocumentMatchInternal{
ID: testInternalId("e"),
ID: index.IndexInternalID("e"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: testInternalId("f"),
ID: index.IndexInternalID("f"),
Score: 9,
},
&search.DocumentMatchInternal{
ID: testInternalId("g"),
ID: index.IndexInternalID("g"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: testInternalId("h"),
ID: index.IndexInternalID("h"),
Score: 9,
},
&search.DocumentMatchInternal{
ID: testInternalId("i"),
ID: index.IndexInternalID("i"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: testInternalId("j"),
ID: index.IndexInternalID("j"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: testInternalId("k"),
ID: index.IndexInternalID("k"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: testInternalId("l"),
ID: index.IndexInternalID("l"),
Score: 99,
},
&search.DocumentMatchInternal{
ID: testInternalId("m"),
ID: index.IndexInternalID("m"),
Score: 11,
},
&search.DocumentMatchInternal{
ID: testInternalId("n"),
ID: index.IndexInternalID("n"),
Score: 11,
},
},
@ -229,59 +230,59 @@ func TestPaginationSameScores(t *testing.T) {
searcher := &stubSearcher{
matches: []*search.DocumentMatchInternal{
&search.DocumentMatchInternal{
ID: testInternalId("a"),
ID: index.IndexInternalID("a"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: testInternalId("b"),
ID: index.IndexInternalID("b"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: testInternalId("c"),
ID: index.IndexInternalID("c"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: testInternalId("d"),
ID: index.IndexInternalID("d"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: testInternalId("e"),
ID: index.IndexInternalID("e"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: testInternalId("f"),
ID: index.IndexInternalID("f"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: testInternalId("g"),
ID: index.IndexInternalID("g"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: testInternalId("h"),
ID: index.IndexInternalID("h"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: testInternalId("i"),
ID: index.IndexInternalID("i"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: testInternalId("j"),
ID: index.IndexInternalID("j"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: testInternalId("k"),
ID: index.IndexInternalID("k"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: testInternalId("l"),
ID: index.IndexInternalID("l"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: testInternalId("m"),
ID: index.IndexInternalID("m"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: testInternalId("n"),
ID: index.IndexInternalID("n"),
Score: 5,
},
},
@ -315,59 +316,59 @@ func TestPaginationSameScores(t *testing.T) {
searcher = &stubSearcher{
matches: []*search.DocumentMatchInternal{
&search.DocumentMatchInternal{
ID: testInternalId("a"),
ID: index.IndexInternalID("a"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: testInternalId("b"),
ID: index.IndexInternalID("b"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: testInternalId("c"),
ID: index.IndexInternalID("c"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: testInternalId("d"),
ID: index.IndexInternalID("d"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: testInternalId("e"),
ID: index.IndexInternalID("e"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: testInternalId("f"),
ID: index.IndexInternalID("f"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: testInternalId("g"),
ID: index.IndexInternalID("g"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: testInternalId("h"),
ID: index.IndexInternalID("h"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: testInternalId("i"),
ID: index.IndexInternalID("i"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: testInternalId("j"),
ID: index.IndexInternalID("j"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: testInternalId("k"),
ID: index.IndexInternalID("k"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: testInternalId("l"),
ID: index.IndexInternalID("l"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: testInternalId("m"),
ID: index.IndexInternalID("m"),
Score: 5,
},
&search.DocumentMatchInternal{
ID: testInternalId("n"),
ID: index.IndexInternalID("n"),
Score: 5,
},
},

View File

@ -10,8 +10,6 @@
package collectors
import (
"bytes"
"github.com/blevesearch/bleve/document"
"github.com/blevesearch/bleve/index"
"github.com/blevesearch/bleve/search"
@ -63,16 +61,6 @@ func (ss *stubSearcher) Min() int {
return 0
}
type testInternalId []byte
func (t testInternalId) Compare(other index.IndexInternalID) int {
return bytes.Compare(t, other.(testInternalId))
}
func (t testInternalId) Equals(other index.IndexInternalID) bool {
return t.Compare(other.(testInternalId)) == 0
}
type stubReader struct{}
func (sr *stubReader) TermFieldReader(term []byte, field string, includeFreq, includeNorm, includeTermVectors bool) (index.TermFieldReader, error) {
@ -124,7 +112,7 @@ func (sr *stubReader) DocCount() uint64 {
}
func (sr *stubReader) FinalizeDocID(id index.IndexInternalID) (string, error) {
return string(id.(testInternalId)), nil
return string(id), nil
}
func (sr *stubReader) Close() error {

View File

@ -28,7 +28,7 @@ func TestConstantScorer(t *testing.T) {
// test some simple math
{
termMatch: &index.TermFieldDoc{
ID: testInternalId("one"),
ID: index.IndexInternalID("one"),
Freq: 1,
Norm: 1.0,
Vectors: []*index.TermFieldVector{
@ -41,7 +41,7 @@ func TestConstantScorer(t *testing.T) {
},
},
result: &search.DocumentMatchInternal{
ID: testInternalId("one"),
ID: index.IndexInternalID("one"),
Score: 1.0,
Expl: &search.Explanation{
Value: 1.0,
@ -72,12 +72,12 @@ func TestConstantScorerWithQueryNorm(t *testing.T) {
}{
{
termMatch: &index.TermFieldDoc{
ID: testInternalId("one"),
ID: index.IndexInternalID("one"),
Freq: 1,
Norm: 1.0,
},
result: &search.DocumentMatchInternal{
ID: testInternalId("one"),
ID: index.IndexInternalID("one"),
Score: 2.0,
Expl: &search.Explanation{
Value: 2.0,

View File

@ -10,7 +10,6 @@
package scorers
import (
"bytes"
"math"
"reflect"
"testing"
@ -19,16 +18,6 @@ import (
"github.com/blevesearch/bleve/search"
)
type testInternalId []byte
func (t testInternalId) Compare(other index.IndexInternalID) int {
return bytes.Compare(t, other.(testInternalId))
}
func (t testInternalId) Equals(other index.IndexInternalID) bool {
return t.Compare(other.(testInternalId)) == 0
}
func TestTermScorer(t *testing.T) {
var docTotal uint64 = 100
@ -46,7 +35,7 @@ func TestTermScorer(t *testing.T) {
// test some simple math
{
termMatch: &index.TermFieldDoc{
ID: testInternalId("one"),
ID: index.IndexInternalID("one"),
Freq: 1,
Norm: 1.0,
Vectors: []*index.TermFieldVector{
@ -59,7 +48,7 @@ func TestTermScorer(t *testing.T) {
},
},
result: &search.DocumentMatchInternal{
ID: testInternalId("one"),
ID: index.IndexInternalID("one"),
Score: math.Sqrt(1.0) * idf,
Expl: &search.Explanation{
Value: math.Sqrt(1.0) * idf,
@ -95,12 +84,12 @@ func TestTermScorer(t *testing.T) {
// test the same thing again (score should be cached this time)
{
termMatch: &index.TermFieldDoc{
ID: testInternalId("one"),
ID: index.IndexInternalID("one"),
Freq: 1,
Norm: 1.0,
},
result: &search.DocumentMatchInternal{
ID: testInternalId("one"),
ID: index.IndexInternalID("one"),
Score: math.Sqrt(1.0) * idf,
Expl: &search.Explanation{
Value: math.Sqrt(1.0) * idf,
@ -125,12 +114,12 @@ func TestTermScorer(t *testing.T) {
// test a case where the sqrt isn't precalculated
{
termMatch: &index.TermFieldDoc{
ID: testInternalId("one"),
ID: index.IndexInternalID("one"),
Freq: 65,
Norm: 1.0,
},
result: &search.DocumentMatchInternal{
ID: testInternalId("one"),
ID: index.IndexInternalID("one"),
Score: math.Sqrt(65) * idf,
Expl: &search.Explanation{
Value: math.Sqrt(65) * idf,
@ -188,12 +177,12 @@ func TestTermScorerWithQueryNorm(t *testing.T) {
}{
{
termMatch: &index.TermFieldDoc{
ID: testInternalId("one"),
ID: index.IndexInternalID("one"),
Freq: 1,
Norm: 1.0,
},
result: &search.DocumentMatchInternal{
ID: testInternalId("one"),
ID: 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,

View File

@ -12,7 +12,7 @@ package searchers
import (
"testing"
"github.com/blevesearch/bleve/index/upside_down"
"github.com/blevesearch/bleve/index"
"github.com/blevesearch/bleve/search"
)
@ -249,15 +249,15 @@ func TestBooleanSearch(t *testing.T) {
searcher: booleanSearcher,
results: []*search.DocumentMatchInternal{
{
ID: upside_down.InternalId("1"),
ID: index.IndexInternalID("1"),
Score: 0.9818005051949021,
},
{
ID: upside_down.InternalId("3"),
ID: index.IndexInternalID("3"),
Score: 0.808709699395535,
},
{
ID: upside_down.InternalId("4"),
ID: index.IndexInternalID("4"),
Score: 0.34618161159873423,
},
},
@ -266,11 +266,11 @@ func TestBooleanSearch(t *testing.T) {
searcher: booleanSearcher2,
results: []*search.DocumentMatchInternal{
{
ID: upside_down.InternalId("1"),
ID: index.IndexInternalID("1"),
Score: 0.6775110856165737,
},
{
ID: upside_down.InternalId("3"),
ID: index.IndexInternalID("3"),
Score: 0.6775110856165737,
},
},
@ -284,15 +284,15 @@ func TestBooleanSearch(t *testing.T) {
searcher: booleanSearcher4,
results: []*search.DocumentMatchInternal{
{
ID: upside_down.InternalId("1"),
ID: index.IndexInternalID("1"),
Score: 1.0,
},
{
ID: upside_down.InternalId("3"),
ID: index.IndexInternalID("3"),
Score: 0.5,
},
{
ID: upside_down.InternalId("4"),
ID: index.IndexInternalID("4"),
Score: 1.0,
},
},
@ -301,11 +301,11 @@ func TestBooleanSearch(t *testing.T) {
searcher: booleanSearcher5,
results: []*search.DocumentMatchInternal{
{
ID: upside_down.InternalId("3"),
ID: index.IndexInternalID("3"),
Score: 0.5,
},
{
ID: upside_down.InternalId("4"),
ID: index.IndexInternalID("4"),
Score: 1.0,
},
},
@ -319,7 +319,7 @@ func TestBooleanSearch(t *testing.T) {
searcher: conjunctionSearcher7,
results: []*search.DocumentMatchInternal{
{
ID: upside_down.InternalId("1"),
ID: index.IndexInternalID("1"),
Score: 2.0097428702814377,
},
},
@ -328,7 +328,7 @@ func TestBooleanSearch(t *testing.T) {
searcher: conjunctionSearcher8,
results: []*search.DocumentMatchInternal{
{
ID: upside_down.InternalId("3"),
ID: index.IndexInternalID("3"),
Score: 2.0681575785068107,
},
},

View File

@ -12,7 +12,7 @@ package searchers
import (
"testing"
"github.com/blevesearch/bleve/index/upside_down"
"github.com/blevesearch/bleve/index"
"github.com/blevesearch/bleve/search"
)
@ -129,7 +129,7 @@ func TestConjunctionSearch(t *testing.T) {
searcher: beerAndMartySearcher,
results: []*search.DocumentMatchInternal{
{
ID: upside_down.InternalId("1"),
ID: index.IndexInternalID("1"),
Score: 2.0097428702814377,
},
},
@ -138,7 +138,7 @@ func TestConjunctionSearch(t *testing.T) {
searcher: angstAndBeerSearcher,
results: []*search.DocumentMatchInternal{
{
ID: upside_down.InternalId("2"),
ID: index.IndexInternalID("2"),
Score: 1.0807601687084403,
},
},
@ -151,11 +151,11 @@ func TestConjunctionSearch(t *testing.T) {
searcher: beerAndMisterSearcher,
results: []*search.DocumentMatchInternal{
{
ID: upside_down.InternalId("2"),
ID: index.IndexInternalID("2"),
Score: 1.2877980334016337,
},
{
ID: upside_down.InternalId("3"),
ID: index.IndexInternalID("3"),
Score: 1.2877980334016337,
},
},
@ -164,7 +164,7 @@ func TestConjunctionSearch(t *testing.T) {
searcher: couchbaseAndMisterSearcher,
results: []*search.DocumentMatchInternal{
{
ID: upside_down.InternalId("2"),
ID: index.IndexInternalID("2"),
Score: 1.4436599157093672,
},
},
@ -173,7 +173,7 @@ func TestConjunctionSearch(t *testing.T) {
searcher: beerAndCouchbaseAndMisterSearcher,
results: []*search.DocumentMatchInternal{
{
ID: upside_down.InternalId("2"),
ID: index.IndexInternalID("2"),
Score: 1.441614953806971,
},
},

View File

@ -12,7 +12,7 @@ package searchers
import (
"testing"
"github.com/blevesearch/bleve/index/upside_down"
"github.com/blevesearch/bleve/index"
"github.com/blevesearch/bleve/search"
)
@ -72,11 +72,11 @@ func TestDisjunctionSearch(t *testing.T) {
searcher: martyOrDustinSearcher,
results: []*search.DocumentMatchInternal{
{
ID: upside_down.InternalId("1"),
ID: index.IndexInternalID("1"),
Score: 0.6775110856165737,
},
{
ID: upside_down.InternalId("3"),
ID: index.IndexInternalID("3"),
Score: 0.6775110856165737,
},
},
@ -86,15 +86,15 @@ func TestDisjunctionSearch(t *testing.T) {
searcher: nestedRaviOrMartyOrDustinSearcher,
results: []*search.DocumentMatchInternal{
{
ID: upside_down.InternalId("1"),
ID: index.IndexInternalID("1"),
Score: 0.2765927424732821,
},
{
ID: upside_down.InternalId("3"),
ID: index.IndexInternalID("3"),
Score: 0.2765927424732821,
},
{
ID: upside_down.InternalId("4"),
ID: index.IndexInternalID("4"),
Score: 0.5531854849465642,
},
},
@ -159,7 +159,7 @@ func TestDisjunctionAdvance(t *testing.T) {
t.Fatal(err)
}
match, err := martyOrDustinSearcher.Advance(upside_down.InternalId("3"), nil)
match, err := martyOrDustinSearcher.Advance(index.IndexInternalID("3"), nil)
if err != nil {
t.Errorf("unexpected error: %v", err)
}

View File

@ -68,7 +68,7 @@ func testDocIDSearcher(t *testing.T, indexed, searched, wanted []string) {
if err != nil {
t.Fatal(err)
}
if !upside_down.InternalId(id).Equals(m.ID) {
if !index.IndexInternalID(id).Equals(m.ID) {
t.Fatalf("expected %v at position %v, got %v", id, i, m.ID)
}
}
@ -87,18 +87,18 @@ func testDocIDSearcher(t *testing.T, indexed, searched, wanted []string) {
}
before := id[:1]
for _, target := range []string{before, id} {
m, err := searcher.Advance(upside_down.InternalId(target), nil)
m, err := searcher.Advance(index.IndexInternalID(target), nil)
if err != nil {
t.Fatal(err)
}
if m == nil || !m.ID.Equals(upside_down.InternalId(id)) {
if m == nil || !m.ID.Equals(index.IndexInternalID(id)) {
t.Fatalf("advancing to %v returned %v instead of %v", before, m, id)
}
}
}
// Seek after the end of the sequence
after := "zzz"
m, err = searcher.Advance(upside_down.InternalId(after), nil)
m, err = searcher.Advance(index.IndexInternalID(after), nil)
if err != nil {
t.Fatal(err)
}

View File

@ -12,7 +12,7 @@ package searchers
import (
"testing"
"github.com/blevesearch/bleve/index/upside_down"
"github.com/blevesearch/bleve/index"
"github.com/blevesearch/bleve/search"
)
@ -57,19 +57,19 @@ func TestFuzzySearch(t *testing.T) {
searcher: fuzzySearcherbeet,
results: []*search.DocumentMatchInternal{
{
ID: upside_down.InternalId("1"),
ID: index.IndexInternalID("1"),
Score: 1.0,
},
{
ID: upside_down.InternalId("2"),
ID: index.IndexInternalID("2"),
Score: 0.5,
},
{
ID: upside_down.InternalId("3"),
ID: index.IndexInternalID("3"),
Score: 0.5,
},
{
ID: upside_down.InternalId("4"),
ID: index.IndexInternalID("4"),
Score: 0.9999999838027345,
},
},
@ -82,7 +82,7 @@ func TestFuzzySearch(t *testing.T) {
searcher: fuzzySearcheraplee,
results: []*search.DocumentMatchInternal{
{
ID: upside_down.InternalId("3"),
ID: index.IndexInternalID("3"),
Score: 0.9581453659370776,
},
},
@ -91,7 +91,7 @@ func TestFuzzySearch(t *testing.T) {
searcher: fuzzySearcherprefix,
results: []*search.DocumentMatchInternal{
{
ID: upside_down.InternalId("5"),
ID: index.IndexInternalID("5"),
Score: 1.916290731874155,
},
},

View File

@ -12,7 +12,7 @@ package searchers
import (
"testing"
"github.com/blevesearch/bleve/index/upside_down"
"github.com/blevesearch/bleve/index"
"github.com/blevesearch/bleve/search"
)
@ -49,23 +49,23 @@ func TestMatchAllSearch(t *testing.T) {
queryNorm: 1.0,
results: []*search.DocumentMatchInternal{
{
ID: upside_down.InternalId("1"),
ID: index.IndexInternalID("1"),
Score: 1.0,
},
{
ID: upside_down.InternalId("2"),
ID: index.IndexInternalID("2"),
Score: 1.0,
},
{
ID: upside_down.InternalId("3"),
ID: index.IndexInternalID("3"),
Score: 1.0,
},
{
ID: upside_down.InternalId("4"),
ID: index.IndexInternalID("4"),
Score: 1.0,
},
{
ID: upside_down.InternalId("5"),
ID: index.IndexInternalID("5"),
Score: 1.0,
},
},
@ -75,23 +75,23 @@ func TestMatchAllSearch(t *testing.T) {
queryNorm: 0.8333333,
results: []*search.DocumentMatchInternal{
{
ID: upside_down.InternalId("1"),
ID: index.IndexInternalID("1"),
Score: 1.0,
},
{
ID: upside_down.InternalId("2"),
ID: index.IndexInternalID("2"),
Score: 1.0,
},
{
ID: upside_down.InternalId("3"),
ID: index.IndexInternalID("3"),
Score: 1.0,
},
{
ID: upside_down.InternalId("4"),
ID: index.IndexInternalID("4"),
Score: 1.0,
},
{
ID: upside_down.InternalId("5"),
ID: index.IndexInternalID("5"),
Score: 1.0,
},
},

View File

@ -55,7 +55,7 @@ func TestMatchNoneSearch(t *testing.T) {
i := 0
for err == nil && next != nil {
if i < len(test.results) {
if next.ID != test.results[i].ID {
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 !scoresCloseEnough(next.Score, test.results[i].Score) {

View File

@ -12,7 +12,7 @@ package searchers
import (
"testing"
"github.com/blevesearch/bleve/index/upside_down"
"github.com/blevesearch/bleve/index"
"github.com/blevesearch/bleve/search"
)
@ -54,7 +54,7 @@ func TestPhraseSearch(t *testing.T) {
searcher: phraseSearcher,
results: []*search.DocumentMatchInternal{
{
ID: upside_down.InternalId("2"),
ID: index.IndexInternalID("2"),
Score: 1.0807601687084403,
},
},

View File

@ -13,7 +13,7 @@ import (
"regexp"
"testing"
"github.com/blevesearch/bleve/index/upside_down"
"github.com/blevesearch/bleve/index"
"github.com/blevesearch/bleve/search"
)
@ -58,7 +58,7 @@ func TestRegexpSearch(t *testing.T) {
searcher: regexpSearcher,
results: []*search.DocumentMatchInternal{
{
ID: upside_down.InternalId("1"),
ID: index.IndexInternalID("1"),
Score: 1.916290731874155,
},
},
@ -67,11 +67,11 @@ func TestRegexpSearch(t *testing.T) {
searcher: regexpSearcherCo,
results: []*search.DocumentMatchInternal{
{
ID: upside_down.InternalId("2"),
ID: index.IndexInternalID("2"),
Score: 0.33875554280828685,
},
{
ID: upside_down.InternalId("3"),
ID: index.IndexInternalID("3"),
Score: 0.33875554280828685,
},
},

View File

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