0
0
Fork 0

refactor FinalizeID into ExternalID and InternalID

This commit is contained in:
Marty Schoch 2016-08-20 14:03:18 -04:00
parent f531835d5c
commit da9339bcdf
4 changed files with 14 additions and 5 deletions

View File

@ -87,7 +87,8 @@ type IndexReader interface {
DocCount() uint64
FinalizeDocID(id IndexInternalID) (string, error)
ExternalID(id IndexInternalID) (string, error)
InternalID(id string) (IndexInternalID, error)
Close() error
}

View File

@ -164,10 +164,14 @@ func (i *IndexReader) Close() error {
return i.kvreader.Close()
}
func (i *IndexReader) FinalizeDocID(id index.IndexInternalID) (string, error) {
func (i *IndexReader) ExternalID(id index.IndexInternalID) (string, error) {
return string(id), nil
}
func (i *IndexReader) InternalID(id string) (index.IndexInternalID, error) {
return index.IndexInternalID(id), nil
}
func incrementBytes(in []byte) []byte {
rv := make([]byte, len(in))
copy(rv, in)

View File

@ -115,10 +115,14 @@ func (sr *stubReader) DocCount() uint64 {
return 0
}
func (sr *stubReader) FinalizeDocID(id index.IndexInternalID) (string, error) {
func (sr *stubReader) ExternalID(id index.IndexInternalID) (string, error) {
return string(id), nil
}
func (sr *stubReader) InternalID(id string) (index.IndexInternalID, error) {
return []byte(id), nil
}
func (sr *stubReader) Close() error {
return nil
}

View File

@ -151,7 +151,7 @@ func (hc *TopNCollector) collectSingle(ctx *search.SearchContext, reader index.I
var err error
// see if we need to load ID (at this early stage, for example to sort on it)
if hc.needDocIds {
d.ID, err = reader.FinalizeDocID(d.IndexInternalID)
d.ID, err = reader.ExternalID(d.IndexInternalID)
if err != nil {
return err
}
@ -224,7 +224,7 @@ func (hc *TopNCollector) finalizeResults(r index.IndexReader) error {
if doc.ID == "" {
// look up the id since we need it for lookup
var err error
doc.ID, err = r.FinalizeDocID(doc.IndexInternalID)
doc.ID, err = r.ExternalID(doc.IndexInternalID)
if err != nil {
return err
}