From 26bdd96552c3f99cba0db57fbff7de0a2b531dae Mon Sep 17 00:00:00 2001 From: travisturner Date: Mon, 29 Sep 2014 12:28:19 -0500 Subject: [PATCH] handle TopFill correctly for TopNAll queries (i.e. no filter) --- core/topn.go | 2 +- index/commands.go | 18 +++++++++++++----- index/fragment_container.go | 2 +- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/core/topn.go b/core/topn.go index 7483e13ae..c6ca3b109 100644 --- a/core/topn.go +++ b/core/topn.go @@ -102,7 +102,7 @@ func (self *Service) TopFillHandler(msg *db.Message) { //in order for this to ge topfill := msg.Data.(TopFill) topn, err := self.Index.TopFillBatch(topfill.Args) if err != nil { - log.Println("TopFileHandler:", err) + log.Println("TopFillHandler:", err) } result_message := db.Message{Data: query.FillResult{&query.BaseQueryResult{Id: &topfill.QueryId, Data: topn}}} diff --git a/index/commands.go b/index/commands.go index e6c953c14..d8cad61ee 100644 --- a/index/commands.go +++ b/index/commands.go @@ -306,11 +306,19 @@ func (self *CmdTopFill) Execute(f *Fragment) Calculation { for _, v := range self.args.Bitmaps { if f.exists(v) { a := f.NewHandle(v) - res := f.intersect([]BitmapHandle{self.args.Handle, a}) - bm, _ := f.getBitmap(res) - bc := BitCount(bm) - if bc > 0 { - result = append(result, Pair{v, bc}) + if self.args.Handle == 0 { + // return just the count + bm, _ := f.getBitmap(a) + if bm.Count() > 0 { + result = append(result, Pair{v, bm.Count()}) + } + } else { + res := f.intersect([]BitmapHandle{self.args.Handle, a}) + bm, _ := f.getBitmap(res) + bc := BitCount(bm) + if bc > 0 { + result = append(result, Pair{v, bc}) + } } } } diff --git a/index/fragment_container.go b/index/fragment_container.go index 702414e5d..8c6112178 100644 --- a/index/fragment_container.go +++ b/index/fragment_container.go @@ -186,7 +186,7 @@ func (self *FragmentContainer) TopNAll(frag_id util.SUUID, n int, categories []u } func (self *FragmentContainer) TopFillBatch(args []FillArgs) ([]Pair, error) { - //should probaly make this concurrent but then all hell breaks lose + //should probaly make this concurrent but then all hell breaks loose results := make(map[uint64]uint64) for _, v := range args { items, _ := self.TopFillFragment(v)