// ExportBleve will dump all the index rows from // the provided index and serialize them to the // provided Writer func ExportBleve(i index.Index, w io.Writer) error { kvpw := NewWriter(w) r, err := i.Reader() if err != nil { return fmt.Errorf("error getting reader: %v", err) } var dumpChan chan interface{} dumpChan = r.DumpAll() for dumpValue := range dumpChan { switch dumpValue := dumpValue.(type) { case index.IndexRow: p := KVPair{K: dumpValue.Key(), V: dumpValue.Value()} err = kvpw.Write(&p) if err != nil { return fmt.Errorf("error writing row: %v", err) } case error: return fmt.Errorf("error dumping row: %v", dumpValue) } } return nil }
func NewTermSearcher(index index.Index, term string, field string, boost float64, explain bool) (*TermSearcher, error) { reader, err := index.TermFieldReader([]byte(term), field) if err != nil { return nil, err } scorer := scorers.NewTermQueryScorer(term, field, boost, index.DocCount(), reader.Count(), explain) return &TermSearcher{ index: index, term: term, field: field, explain: explain, reader: reader, scorer: scorer, }, nil }
func NewTermPrefixSearcher(index index.Index, prefix string, field string, boost float64, explain bool) (*TermPrefixSearcher, error) { // find the terms with this prefix fieldReader, err := index.FieldReader(field, []byte(prefix), []byte(prefix)) // enumerate all the terms in the range qsearchers := make([]search.Searcher, 0, 25) tfd, err := fieldReader.Next() for err == nil && tfd != nil { qsearcher, err := NewTermSearcher(index, string(tfd.Term), field, 1.0, explain) if err != nil { return nil, err } qsearchers = append(qsearchers, qsearcher) tfd, err = fieldReader.Next() } // build disjunction searcher of these ranges searcher, err := NewDisjunctionSearcher(index, qsearchers, 0, explain) if err != nil { return nil, err } return &TermPrefixSearcher{ index: index, prefix: prefix, field: field, explain: explain, searcher: searcher, }, nil }
func NewMatchAllSearcher(index index.Index, boost float64, explain bool) (*MatchAllSearcher, error) { reader, err := index.DocIDReader("", "") if err != nil { return nil, err } scorer := scorers.NewConstantScorer(1.0, boost, explain) return &MatchAllSearcher{ index: index, reader: reader, scorer: scorer, }, nil }