示例#1
0
func listIndexIds(index bleve.Index) ([]string, error) {
	idx, _, err := index.Advanced()
	if err != nil {
		return nil, err
	}
	reader, err := idx.Reader()
	if err != nil {
		return nil, err
	}
	defer reader.Close()
	idReader, err := reader.DocIDReaderAll()
	if err != nil {
		return nil, err
	}
	defer idReader.Close()
	ids := []string{}
	for {
		id, err := idReader.Next()
		if err != nil {
			return nil, err
		}
		if id == nil {
			break
		}
		extId, err := reader.ExternalID(id)
		if err != nil {
			return nil, err
		}
		ids = append(ids, extId)
	}
	return ids, nil
}
示例#2
0
文件: main.go 项目: jakubkulhan/bleve
func dumpDictionary(index bleve.Index, field string) {
	i, _, err := index.Advanced()
	if err != nil {
		log.Fatal(err)
	}
	r, err := i.Reader()
	if err != nil {
		log.Fatal(err)
	}
	d, err := r.FieldDict(field)
	if err != nil {
		log.Fatal(err)
	}

	de, err := d.Next()
	for err == nil && de != nil {
		fmt.Printf("%s - %d\n", de.Term, de.Count)
		de, err = d.Next()
	}
}