<commit_before>package core

import (
	"pilosa/db"
	"pilosa/index"
	"pilosa/query"
	"sort"

	"github.com/davecgh/go-spew/spew"
)

func (self *Service) CountQueryStepHandler(msg *db.Message) {
	//spew.Dump("COUNT QUERYSTEP")
	qs := msg.Data.(query.CountQueryStep)
	input := qs.Input
	value, _ := self.Hold.Get(input, 10)
	var bh index.BitmapHandle
	switch val := value.(type) {
	case index.BitmapHandle:
		bh = val
	case []byte:
		bh, _ = self.Index.FromBytes(qs.Location.FragmentId, val)
	}
	count, err := self.Index.Count(qs.Location.FragmentId, bh)
	if err != nil {
		spew.Dump(err)
	}
	//spew.Dump("SLICE COUNT", count)
	result_message := db.Message{Data: query.CountQueryResult{&query.BaseQueryResult{Id: qs.Id, Data: count}}}
	self.Transport.Send(&result_message, qs.Destination.ProcessId)
}

func (self *Service) TopNQueryStepHandler(msg *db.Message) {
	//spew.Dump("TOP-N QUERYSTEP")
	qs := msg.Data.(query.TopNQueryStep)
	input := qs.Input
	value, _ := self.Hold.Get(input, 10)
	var bh index.BitmapHandle
	switch val := value.(type) {
	case index.BitmapHandle:
		bh = val
	case []byte:
		bh, _ = self.Index.FromBytes(qs.Location.FragmentId, val)
	}
	topn, err := self.Index.TopN(qs.Location.FragmentId, bh, qs.N)
	if err != nil {
		spew.Dump(err)
	}
	result_message := db.Message{Data: query.TopNQueryResult{&query.BaseQueryResult{Id: qs.Id, Data: topn}}}
	self.Transport.Send(&result_message, qs.Destination.ProcessId)
}

func (self *Service) UnionQueryStepHandler(msg *db.Message) {
	//spew.Dump("UNION QUERYSTEP")<commit_msg>added stub for category<commit_after>package core

import (
	"pilosa/db"
	"pilosa/index"
	"pilosa/query"
	"sort"

	"github.com/davecgh/go-spew/spew"
)

func (self *Service) CountQueryStepHandler(msg *db.Message) {
	//spew.Dump("COUNT QUERYSTEP")
	qs := msg.Data.(query.CountQueryStep)
	input := qs.Input
	value, _ := self.Hold.Get(input, 10)
	var bh index.BitmapHandle
	switch val := value.(type) {
	case index.BitmapHandle:
		bh = val
	case []byte:
		bh, _ = self.Index.FromBytes(qs.Location.FragmentId, val)
	}
	count, err := self.Index.Count(qs.Location.FragmentId, bh)
	if err != nil {
		spew.Dump(err)
	}
	//spew.Dump("SLICE COUNT", count)
	result_message := db.Message{Data: query.CountQueryResult{&query.BaseQueryResult{Id: qs.Id, Data: count}}}
	self.Transport.Send(&result_message, qs.Destination.ProcessId)
}

func (self *Service) TopNQueryStepHandler(msg *db.Message) {
	//spew.Dump("TOP-N QUERYSTEP")
	qs := msg.Data.(query.TopNQueryStep)
	//TRAVIS SEE HERE
	//need categories in qs I just added so it would compile
	var categoryleaves []int
	input := qs.Input
	value, _ := self.Hold.Get(input, 10)
	var bh index.BitmapHandle
	switch val := value.(type) {
	case index.BitmapHandle:
		bh = val
	case []byte:
		bh, _ = self.Index.FromBytes(qs.Location.FragmentId, val)
	}
	topn, err := self.Index.TopN(qs.Location.FragmentId, bh, qs.N, categoryleaves)
	if err != nil {
		spew.Dump(err)
	}
	result_message := db.Message{Data: query.TopNQueryResult{&query.BaseQueryResult{Id: qs.Id, Data: topn}}}
	self.Transport.Send(&result_message, qs.Destination.ProcessId)
}

func (self *Service) UnionQueryStepHandler(msg *db.Message) {
	//spew.Dump("UNION QUERYSTEP")
{'fraction_non_alphanumeric': 0.15651358950328023, 'fraction_numerical': 0.002499218994064355, 'mean_word_length': 4.549393414211439, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5060024', 'n_tokens_mistral': 1283, 'n_tokens_neox': 1250, 'n_words': 238}