當前位置: 首頁>>代碼示例>>Golang>>正文


Golang FacetResult.NumericRanges方法代碼示例

本文整理匯總了Golang中github.com/blevesearch/bleve/search.FacetResult.NumericRanges方法的典型用法代碼示例。如果您正苦於以下問題:Golang FacetResult.NumericRanges方法的具體用法?Golang FacetResult.NumericRanges怎麽用?Golang FacetResult.NumericRanges使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/blevesearch/bleve/search.FacetResult的用法示例。


在下文中一共展示了FacetResult.NumericRanges方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: Result

func (fb *NumericFacetBuilder) Result() search.FacetResult {
	rv := search.FacetResult{
		Field:   fb.field,
		Total:   fb.total,
		Missing: fb.missing,
	}

	// FIXME better implementation needed here this is quick and dirty
	topN := list.New()

	// walk entries and find top N
OUTER:
	for term, count := range fb.termsCount {
		numericRange := fb.ranges[term]
		tf := &search.NumericRangeFacet{
			Name:  term,
			Count: count,
			Min:   numericRange.min,
			Max:   numericRange.max,
		}

		for e := topN.Front(); e != nil; e = e.Next() {
			curr := e.Value.(*search.NumericRangeFacet)
			if tf.Count < curr.Count {

				topN.InsertBefore(tf, e)
				// if we just made the list too long
				if topN.Len() > fb.size {
					// remove the head
					topN.Remove(topN.Front())
				}
				continue OUTER
			}
		}
		// if we got to the end, we still have to add it
		topN.PushBack(tf)
		if topN.Len() > fb.size {
			// remove the head
			topN.Remove(topN.Front())
		}

	}

	// we now have the list of the top N facets
	rv.NumericRanges = make([]*search.NumericRangeFacet, topN.Len())
	i := 0
	notOther := 0
	for e := topN.Back(); e != nil; e = e.Prev() {
		rv.NumericRanges[i] = e.Value.(*search.NumericRangeFacet)
		i++
		notOther += e.Value.(*search.NumericRangeFacet).Count
	}
	rv.Other = fb.total - notOther

	return rv
}
開發者ID:bozzcq,項目名稱:bleve,代碼行數:56,代碼來源:facet_builder_numeric.go

示例2: Result

func (fb *NumericFacetBuilder) Result() *search.FacetResult {
	rv := search.FacetResult{
		Field:   fb.field,
		Total:   fb.total,
		Missing: fb.missing,
	}

	rv.NumericRanges = make([]*search.NumericRangeFacet, 0, len(fb.termsCount))

	for term, count := range fb.termsCount {
		numericRange := fb.ranges[term]
		tf := &search.NumericRangeFacet{
			Name:  term,
			Count: count,
			Min:   numericRange.min,
			Max:   numericRange.max,
		}

		rv.NumericRanges = append(rv.NumericRanges, tf)
	}

	sort.Sort(rv.NumericRanges)

	// we now have the list of the top N facets
	if fb.size < len(rv.NumericRanges) {
		rv.NumericRanges = rv.NumericRanges[:fb.size]
	}

	notOther := 0
	for _, nr := range rv.NumericRanges {
		notOther += nr.Count
	}
	rv.Other = fb.total - notOther

	return &rv
}
開發者ID:bcampbell,項目名稱:bleve,代碼行數:36,代碼來源:facet_builder_numeric.go


注:本文中的github.com/blevesearch/bleve/search.FacetResult.NumericRanges方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。