0
0

Merge pull request #487 from steveyen/optimize-facets-builder

Minor facets builder optimizations
This commit is contained in:
Marty Schoch 2016-10-26 14:14:25 -04:00 committed by GitHub
commit 1bd6451581
5 changed files with 12 additions and 15 deletions

View File

@ -87,7 +87,7 @@ type FieldTerms map[string][]string
// FieldsNotYetCached returns a list of fields not yet cached out of a larger list of fields // FieldsNotYetCached returns a list of fields not yet cached out of a larger list of fields
func (f FieldTerms) FieldsNotYetCached(fields []string) []string { func (f FieldTerms) FieldsNotYetCached(fields []string) []string {
var rv []string rv := make([]string, 0, len(fields))
for _, field := range fields { for _, field := range fields {
if _, ok := f[field]; !ok { if _, ok := f[field]; !ok {
rv = append(rv, field) rv = append(rv, field)

View File

@ -16,7 +16,7 @@ package store
import "encoding/json" import "encoding/json"
// KVStore is an abstraction for working with KV stores. Note that // KVStore is an abstraction for working with KV stores. Note that
// in order to be used with the bleve.registry, it must also implement // in order to be used with the bleve.registry, it must also implement
// a constructor function of the registry.KVStoreConstructor type. // a constructor function of the registry.KVStoreConstructor type.
type KVStore interface { type KVStore interface {

View File

@ -119,12 +119,7 @@ func (i *IndexReader) DocumentFieldTerms(id index.IndexInternalID, fields []stri
} }
for _, entry := range back.termEntries { for _, entry := range back.termEntries {
if field, ok := fieldsMap[uint16(*entry.Field)]; ok { if field, ok := fieldsMap[uint16(*entry.Field)]; ok {
terms, ok := rv[field] rv[field] = append(rv[field], *entry.Term)
if !ok {
terms = make([]string, 0)
}
terms = append(terms, *entry.Term)
rv[field] = terms
} }
} }
return rv, nil return rv, nil

View File

@ -28,8 +28,8 @@ func RegisterKVStore(name string, constructor KVStoreConstructor) {
stores[name] = constructor stores[name] = constructor
} }
// KVStoreConstructor is used to build a KVStore of a specific type when // KVStoreConstructor is used to build a KVStore of a specific type when
// specificied by the index configuration. In addition to meeting the // specificied by the index configuration. In addition to meeting the
// store.KVStore interface, KVStores must also support this constructor. // store.KVStore interface, KVStores must also support this constructor.
// Note that currently the values of config must // Note that currently the values of config must
// be able to be marshaled and unmarshaled using the encoding/json library (used // be able to be marshaled and unmarshaled using the encoding/json library (used

View File

@ -29,6 +29,7 @@ type FacetBuilder interface {
type FacetsBuilder struct { type FacetsBuilder struct {
indexReader index.IndexReader indexReader index.IndexReader
facets map[string]FacetBuilder facets map[string]FacetBuilder
fields []string
} }
func NewFacetsBuilder(indexReader index.IndexReader) *FacetsBuilder { func NewFacetsBuilder(indexReader index.IndexReader) *FacetsBuilder {
@ -43,14 +44,15 @@ func (fb *FacetsBuilder) Add(name string, facetBuilder FacetBuilder) {
} }
func (fb *FacetsBuilder) Update(docMatch *DocumentMatch) error { func (fb *FacetsBuilder) Update(docMatch *DocumentMatch) error {
var fields []string if fb.fields == nil {
for _, facetBuilder := range fb.facets { for _, facetBuilder := range fb.facets {
fields = append(fields, facetBuilder.Field()) fb.fields = append(fb.fields, facetBuilder.Field())
}
} }
if len(fields) > 0 { if len(fb.fields) > 0 {
// find out which fields haven't been loaded yet // find out which fields haven't been loaded yet
fieldsToLoad := docMatch.CachedFieldTerms.FieldsNotYetCached(fields) fieldsToLoad := docMatch.CachedFieldTerms.FieldsNotYetCached(fb.fields)
// look them up // look them up
fieldTerms, err := fb.indexReader.DocumentFieldTerms(docMatch.IndexInternalID, fieldsToLoad) fieldTerms, err := fb.indexReader.DocumentFieldTerms(docMatch.IndexInternalID, fieldsToLoad)
if err != nil { if err != nil {