Skip to content

Commit

Permalink
Hotfix/negative bug (#2)
Browse files Browse the repository at this point in the history
* dig negative bug

* fix negative bug
name refactor fro design reason
  • Loading branch information
echoface authored May 20, 2021
1 parent f35dfee commit 10799a4
Show file tree
Hide file tree
Showing 9 changed files with 727 additions and 398 deletions.
4 changes: 2 additions & 2 deletions be_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ type (
newPostingEntriesIfNeeded(k int) *PostingEntries
completeIndex()

//public Interface
//ConfigureIndexer public Interface
ConfigureIndexer(settings *IndexerSettings)
Retrieve(queries Assignments) (result DocIDList, err error)

//debug api
//DumpEntries debug api
DumpEntries() string
DumpEntriesSummary() string
}
Expand Down
47 changes: 23 additions & 24 deletions be_indexer_compact.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,60 +97,59 @@ func (bi *CompactedBEIndex) Retrieve(queries Assignments) (result DocIDList, err
idAssigns: idAssigns,
}

plgs := make([]*FieldScannerGroup, 0, len(ctx.idAssigns))
fieldScanners := make(FieldScanners, 0, len(ctx.idAssigns))

if len(bi.wildcardEntries) > 0 {
pl := NewPostingList(bi.wildcardKey, bi.wildcardEntries)
plgs = append(plgs, NewFieldPostingListGroup(pl))
pl := NewEntriesCursor(bi.wildcardKey, bi.wildcardEntries)
fieldScanners = append(fieldScanners, NewFieldScanner(pl))
}

for field, ids := range ctx.idAssigns {
desc := bi.fieldDesc[field]

pls := make([]*EntriesScanner, 0, len(ids))
entriesScanners := make(CursorGroup, 0, len(ids))
for _, id := range ids {
key := NewKey(desc.ID, id)
if entries := bi.postingList.getEntries(key); len(entries) > 0 {
pls = append(pls, NewPostingList(key, entries))
entriesScanners = append(entriesScanners, NewEntriesCursor(key, entries))
}
}
if len(pls) > 0 {
plgs = append(plgs, NewFieldPostingListGroup(pls...))
if len(entriesScanners) > 0 {
fieldScanners = append(fieldScanners, NewFieldScanner(entriesScanners...))
}
}

if len(plgs) == 0 {
if len(fieldScanners) == 0 {
return result, nil
}

result = make([]DocID, 0, 128)

SortPostingListGroups(plgs)
fieldScanners.Sort()
RETRIEVE:
for {
eid := plgs[0].GetCurEntryID()
eid := fieldScanners[0].GetCurEntryID()

// K mean for this plgs, a doc match need k number same eid in every plg
// K mean for this fieldScanners, a doc match need k number same eid in every plg
k := eid.GetConjID().Size()
if k == 0 {
k = 1
}
// remove finished posting list
for plgs[len(plgs)-1].GetCurEntryID().IsNULLEntry() {
plgs = plgs[:len(plgs)-1]
for len(fieldScanners) > 0 && fieldScanners[len(fieldScanners)-1].GetCurEntryID().IsNULLEntry() {
fieldScanners = fieldScanners[:len(fieldScanners)-1]
}
// mean any conjunction its size = k will not match, wil can fast skip to min entry that conjunction size > k
if k > len(plgs) {
if k > len(fieldScanners) {
break RETRIEVE
}

// k <= plgsCount
// check whether eid plgs[k-1].GetCurEntryID equal
endEID := plgs[k-1].GetCurEntryID()
// check whether eid fieldScanners[k-1].GetCurEntryID equal
endEID := fieldScanners[k-1].GetCurEntryID()

nextID := endEID

if eid == endEID {
nextID := NewEntryID(endEID.GetConjID(), false)
if endEID.GetConjID() == eid.GetConjID() {

nextID = endEID + 1

Expand All @@ -160,20 +159,20 @@ RETRIEVE:

} else { //exclude

for i := k; i < len(plgs); i++ {
if plgs[i].GetCurConjID() != eid.GetConjID() {
for i := k; i < len(fieldScanners); i++ {
if fieldScanners[i].GetCurConjID() != eid.GetConjID() {
break
}
plgs[i].Skip(nextID)
fieldScanners[i].Skip(nextID)
}
}
}
// 推进游标
for i := 0; i < k; i++ {
plgs[i].SkipTo(nextID)
fieldScanners[i].SkipTo(nextID)
}

SortPostingListGroups(plgs)
fieldScanners.Sort()
}
return result, nil
}
Expand Down
55 changes: 27 additions & 28 deletions be_indexer_ksized.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,69 +75,68 @@ func (bi *SizeGroupedBEIndex) getKSizeEntries(k int) *PostingEntries {
return bi.sizeEntries[k]
}

func (bi *SizeGroupedBEIndex) initPostingList(ctx *RetrieveContext, k int) FieldScannerGroups {
func (bi *SizeGroupedBEIndex) initPlEntriesScanners(ctx *RetrieveContext, k int) FieldScanners {

plgs := make([]*FieldScannerGroup, 0, len(ctx.idAssigns))
fieldScanners := make(FieldScanners, 0, len(ctx.idAssigns))

if k == 0 && len(bi.wildcardEntries) > 0 {
pl := NewPostingList(bi.wildcardKey, bi.wildcardEntries)
plgs = append(plgs, NewFieldPostingListGroup(pl))
pl := NewEntriesCursor(bi.wildcardKey, bi.wildcardEntries)
fieldScanners = append(fieldScanners, NewFieldScanner(pl))
}

kSizeEntries := bi.getKSizeEntries(k)
for field, ids := range ctx.idAssigns {

desc := bi.fieldDesc[field]

pls := make(EntriesScanners, 0, len(ids))
pls := make(CursorGroup, 0, len(ids))
for _, id := range ids {
key := NewKey(desc.ID, id)
if entries := kSizeEntries.getEntries(key); len(entries) > 0 {
pls = append(pls, NewPostingList(key, entries))
pls = append(pls, NewEntriesCursor(key, entries))
}
}
if len(pls) > 0 {
plgs = append(plgs, NewFieldPostingListGroup(pls...))
fieldScanners = append(fieldScanners, NewFieldScanner(pls...))
}
}
return plgs
return fieldScanners
}

// retrieveK MOVE TO: FieldScannerGroups ?
func (bi *SizeGroupedBEIndex) retrieveK(plgList FieldScannerGroups, k int) (result []DocID) {
// retrieveK MOVE TO: FieldScanners ?
func (bi *SizeGroupedBEIndex) retrieveK(fieldScanners FieldScanners, k int) (result []DocID) {
result = make([]DocID, 0, 256)

//sort.Sort(plgList)
SortPostingListGroups(plgList)
for !plgList[k-1].GetCurEntryID().IsNULLEntry() {
//sort.Sort(fieldScanners)
fieldScanners.Sort()
for !fieldScanners[k-1].GetCurEntryID().IsNULLEntry() {

eid := plgList[0].GetCurEntryID()
endEID := plgList[k-1].GetCurEntryID()
eid := fieldScanners[0].GetCurEntryID()
endEID := fieldScanners[k-1].GetCurEntryID()

nextID := endEID
if eid == endEID {
nextID := NewEntryID(endEID.GetConjID(), false)

if eid.GetConjID() == endEID.GetConjID() {
nextID = endEID + 1

if eid.IsInclude() {
result = append(result, eid.GetConjID().DocID())

} else { //exclude

for i := k; i < plgList.Len(); i++ {
if plgList[i].GetCurConjID() != eid.GetConjID() {
for i := k; i < fieldScanners.Len(); i++ {
if fieldScanners[i].GetCurConjID() != eid.GetConjID() {
break
}
plgList[i].Skip(nextID)
fieldScanners[i].Skip(nextID)
}

}
}
// 推进游标
for i := 0; i < k; i++ {
plgList[i].SkipTo(nextID)
fieldScanners[i].SkipTo(nextID)
}
//sort.Sort(plgList)
SortPostingListGroups(plgList)
//sort.Sort(fieldScanners)
fieldScanners.Sort()
}
return result
}
Expand All @@ -156,16 +155,16 @@ func (bi *SizeGroupedBEIndex) Retrieve(queries Assignments) (result DocIDList, e

for k := util.MinInt(queries.Size(), bi.maxK()); k >= 0; k-- {

plgs := bi.initPostingList(ctx, k)
fieldScanners := bi.initPlEntriesScanners(ctx, k)

tempK := k
if tempK == 0 {
tempK = 1
}
if len(plgs) < tempK {
if len(fieldScanners) < tempK {
continue
}
res := bi.retrieveK(plgs, tempK)
res := bi.retrieveK(fieldScanners, tempK)
result = append(result, res...)
}
return result, nil
Expand Down
Loading

0 comments on commit 10799a4

Please sign in to comment.