Skip to content

Commit

Permalink
Update executor to return documents
Browse files Browse the repository at this point in the history
  • Loading branch information
nbroyles committed Jan 5, 2021
1 parent 8318fe5 commit e88ee26
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 45 deletions.
4 changes: 2 additions & 2 deletions src/m3ninx/search/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ var (
errExecutorClosed = errors.New("executor is closed")
)

type newIteratorFn func(s search.Searcher, rs index.Readers) (doc.MetadataIterator, error)
type newIteratorFn func(s search.Searcher, rs index.Readers) (doc.Iterator, error)

type executor struct {
sync.RWMutex
Expand All @@ -52,7 +52,7 @@ func NewExecutor(rs index.Readers) search.Executor {
}
}

func (e *executor) Execute(q search.Query) (doc.MetadataIterator, error) {
func (e *executor) Execute(q search.Query) (doc.Iterator, error) {
e.RLock()
defer e.RUnlock()
if e.closed {
Expand Down
4 changes: 2 additions & 2 deletions src/m3ninx/search/executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type testIterator struct{}
func newTestIterator() testIterator { return testIterator{} }

func (it testIterator) Next() bool { return false }
func (it testIterator) Current() doc.Metadata { return doc.Metadata{} }
func (it testIterator) Current() doc.Document { return doc.Document{} }
func (it testIterator) Err() error { return nil }
func (it testIterator) Close() error { return nil }

Expand All @@ -58,7 +58,7 @@ func TestExecutor(t *testing.T) {
e := NewExecutor(rs).(*executor)

// Override newIteratorFn to return test iterator.
e.newIteratorFn = func(_ search.Searcher, _ index.Readers) (doc.MetadataIterator, error) {
e.newIteratorFn = func(_ search.Searcher, _ index.Readers) (doc.Iterator, error) {
return newTestIterator(), nil
}

Expand Down
16 changes: 8 additions & 8 deletions src/m3ninx/search/executor/iterator.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@ type iterator struct {
readers index.Readers

idx int
currDoc doc.Metadata
currIter doc.MetadataIterator
currDoc doc.Document
currIter doc.Iterator

err error
closed bool
}

func newIterator(s search.Searcher, rs index.Readers) (doc.MetadataIterator, error) {
func newIterator(s search.Searcher, rs index.Readers) (doc.Iterator, error) {
it := &iterator{
searcher: s,
readers: rs,
Expand Down Expand Up @@ -91,7 +91,7 @@ func (it *iterator) Next() bool {
return true
}

func (it *iterator) Current() doc.Metadata {
func (it *iterator) Current() doc.Document {
return it.currDoc
}

Expand All @@ -108,9 +108,9 @@ func (it *iterator) Close() error {
}

// nextIter gets the next document iterator by getting the next postings list from
// the it's searcher and then getting the documents for that postings list from the
// corresponding reader associated with that postings list.
func (it *iterator) nextIter() (doc.MetadataIterator, bool, error) {
// the it's searcher and then getting the encoded documents for that postings list from
// the corresponding reader associated with that postings list.
func (it *iterator) nextIter() (doc.Iterator, bool, error) {
it.idx++
if it.idx >= len(it.readers) {
return nil, false, nil
Expand All @@ -122,7 +122,7 @@ func (it *iterator) nextIter() (doc.MetadataIterator, bool, error) {
return nil, false, err
}

iter, err := reader.MetadataIterator(pl)
iter, err := reader.Docs(pl)
if err != nil {
return nil, false, err
}
Expand Down
37 changes: 8 additions & 29 deletions src/m3ninx/search/executor/iterator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,35 +44,14 @@ func TestIterator(t *testing.T) {
require.NoError(t, secondPL.Insert(67))

// Set up Readers.
docs := []doc.Metadata{
{
Fields: []doc.Field{
{
Name: []byte("apple"),
Value: []byte("red"),
},
},
},
{
Fields: []doc.Field{
{
Name: []byte("banana"),
Value: []byte("yellow"),
},
},
},
{
Fields: []doc.Field{
{
Name: []byte("carrot"),
Value: []byte("orange"),
},
},
},
docs := []doc.Document{
doc.NewDocumentFromEncoded(doc.Encoded{Bytes: []byte("encodedbytes1")}),
doc.NewDocumentFromEncoded(doc.Encoded{Bytes: []byte("encodedbytes2")}),
doc.NewDocumentFromEncoded(doc.Encoded{Bytes: []byte("encodedbytes3")}),
}

firstDocIter := doc.NewMockMetadataIterator(mockCtrl)
secondDocIter := doc.NewMockMetadataIterator(mockCtrl)
firstDocIter := doc.NewMockIterator(mockCtrl)
secondDocIter := doc.NewMockIterator(mockCtrl)
gomock.InOrder(
firstDocIter.EXPECT().Next().Return(true),
firstDocIter.EXPECT().Current().Return(docs[0]),
Expand All @@ -92,8 +71,8 @@ func TestIterator(t *testing.T) {
firstReader := index.NewMockReader(mockCtrl)
secondReader := index.NewMockReader(mockCtrl)
gomock.InOrder(
firstReader.EXPECT().MetadataIterator(firstPL).Return(firstDocIter, nil),
secondReader.EXPECT().MetadataIterator(secondPL).Return(secondDocIter, nil),
firstReader.EXPECT().Docs(firstPL).Return(firstDocIter, nil),
secondReader.EXPECT().Docs(secondPL).Return(secondDocIter, nil),
)

searcher := search.NewMockSearcher(mockCtrl)
Expand Down
6 changes: 3 additions & 3 deletions src/m3ninx/search/search_mock.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/m3ninx/search/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import (
// Executor is responsible for executing queries over a snapshot.
type Executor interface {
// Execute executes a query over the Executor's snapshot.
Execute(q Query) (doc.MetadataIterator, error)
Execute(q Query) (doc.Iterator, error)

// Close closes the iterator.
Close() error
Expand Down

0 comments on commit e88ee26

Please sign in to comment.