Ejemplo n.º 1
0
func NewMatchAllSearcher(indexReader index.IndexReader, boost float64, explain bool) (*MatchAllSearcher, error) {
	reader, err := indexReader.DocIDReader("", "")
	if err != nil {
		return nil, err
	}
	scorer := scorers.NewConstantScorer(1.0, boost, explain)
	return &MatchAllSearcher{
		indexReader: indexReader,
		reader:      reader,
		scorer:      scorer,
	}, nil
}
Ejemplo n.º 2
0
func NewDocIDSearcher(indexReader index.IndexReader, ids []string, boost float64,
	explain bool) (searcher *DocIDSearcher, err error) {

	kept := make([]string, len(ids))
	copy(kept, ids)
	sort.Strings(kept)

	if len(ids) > 0 {
		var idReader index.DocIDReader
		endTerm := string(incrementBytes([]byte(kept[len(kept)-1])))
		idReader, err = indexReader.DocIDReader(kept[0], endTerm)
		if err != nil {
			return nil, err
		}
		defer func() {
			if cerr := idReader.Close(); err == nil && cerr != nil {
				err = cerr
			}
		}()
		j := 0
		for _, id := range kept {
			doc, err := idReader.Advance(id)
			if err != nil {
				return nil, err
			}
			// Non-duplicate match
			if doc == id && (j == 0 || kept[j-1] != id) {
				kept[j] = id
				j++
			}
		}
		kept = kept[:j]
	}

	scorer := scorers.NewConstantScorer(1.0, boost, explain)
	return &DocIDSearcher{
		ids:    kept,
		scorer: scorer,
	}, nil
}