Showing 3 of 4 files from the diff.

@@ -4,7 +4,6 @@
Loading
4 4
package sdb
5 5
6 6
import (
7 -
	"github.com/blevesearch/bleve"
8 7
	"github.com/dgraph-io/badger/v2"
9 8
)
10 9
@@ -41,16 +40,12 @@
Loading
41 40
}
42 41
43 42
func (db *DB) cleanIndex() error {
44 -
	bq := bleve.NewMatchAllQuery()
45 -
	req := bleve.NewSearchRequest(bq)
46 -
47 -
	res, err := db.si.Search(req)
48 -
	if err != nil {
49 -
		return bleveError(err)
50 -
	}
43 +
	tx := db.NewTx(RO)
44 +
	defer tx.Discard()
51 45
52 -
	for _, hit := range res.Hits {
53 -
		if err = db.si.Delete(hit.ID); err != nil {
46 +
	result, err := tx.Find("")
47 +
	for _, id := range result {
48 +
		if err = db.si.Delete(string(id)); err != nil {
54 49
			return bleveError(err)
55 50
		}
56 51
	}

@@ -20,16 +20,10 @@
Loading
20 20
	SearchIndexDir = "search-index"
21 21
)
22 22
23 -
type BleveOptions struct {
24 -
	Dir          string
25 -
	DoctypeField string
26 -
	DocMappings  map[string]*mapping.DocumentMapping
27 -
}
28 -
29 23
// Options are parameters for initializing a database.
30 24
type Options struct {
31 25
	// Database location.
32 -
	Directory string
26 +
	Dir string
33 27
34 28
	Badger badger.Options
35 29
	Bleve  BleveOptions
@@ -49,8 +43,8 @@
Loading
49 43
	badgerOpts.Compression = options.None
50 44
51 45
	return Options{
52 -
		Directory: dir,
53 -
		Badger:    badgerOpts,
46 +
		Dir:    dir,
47 +
		Badger: badgerOpts,
54 48
55 49
		Bleve: BleveOptions{
56 50
			Dir:          filepath.Join(dir, SearchIndexDir),
@@ -84,3 +78,9 @@
Loading
84 78
85 79
	return opts, nil
86 80
}
81 +
82 +
type BleveOptions struct {
83 +
	Dir          string
84 +
	DoctypeField string
85 +
	DocMappings  map[string]*mapping.DocumentMapping
86 +
}
87 87
imilarity index 95%
88 88
ename from pkg/sdb/sdb_example_test.go
89 89
ename to pkg/sdb/sdb-example_test.go

@@ -7,6 +7,7 @@
Loading
7 7
	"errors"
8 8
9 9
	"github.com/blevesearch/bleve"
10 +
	"github.com/blevesearch/bleve/search/query"
10 11
	"github.com/dgraph-io/badger/v2"
11 12
	"github.com/niubaoshu/gotiny"
12 13
)
@@ -94,20 +95,26 @@
Loading
94 95
// the query language syntax. sort is a list of field names used for sorting,
95 96
// any field prefixed by a hyphen (-) will user reverse order.
96 97
func (tx *Tx) Find(q string, sort ...string) ([][]byte, error) {
97 -
	if q == "" && len(sort) == 0 {
98 -
		return nil, nil
98 +
	var bq query.Query
99 +
100 +
	if q == "" {
101 +
		bq = bleve.NewMatchAllQuery()
102 +
	} else {
103 +
		bq = bleve.NewQueryStringQuery(q)
99 104
	}
100 105
101 -
	result := [][]byte{}
102 -
	bq := bleve.NewQueryStringQuery(q)
103 106
	req := bleve.NewSearchRequest(bq)
104 -
	req.SortBy(sort)
107 +
108 +
	if len(sort) > 0 {
109 +
		req.SortBy(sort)
110 +
	}
105 111
106 112
	res, err := tx.si.Search(req)
107 113
	if err != nil {
108 114
		return nil, bleveError(err)
109 115
	}
110 116
117 +
	result := [][]byte{}
111 118
	for _, hit := range res.Hits {
112 119
		result = append(result, []byte(hit.ID))
113 120
	}
@@ -138,6 +145,21 @@
Loading
138 145
	return nil
139 146
}
140 147
148 +
// Prefix fetches all the keys from the database with the given prefix.
149 +
func (tx *Tx) Prefix(prefix []byte) [][]byte {
150 +
	it := tx.dbTx.NewIterator(badger.DefaultIteratorOptions)
151 +
	defer it.Close()
152 +
153 +
	result := [][]byte{}
154 +
	for it.Seek(prefix); it.ValidForPrefix(prefix); it.Next() {
155 +
		buf := tx.db.buffers.Get()
156 +
		result = append(result, it.Item().KeyCopy(buf.Bytes()))
157 +
		tx.db.buffers.Add(buf)
158 +
	}
159 +
160 +
	return result
161 +
}
162 +
141 163
// Set set v as value of the given key. This operation happens in memory, it
142 164
// will be written to the database once Commit is called. v must be a pointer.
143 165
func (tx *Tx) Set(key []byte, v interface{}) (err error) {
Files Coverage
pkg/sdb 82.98%
Project Totals (5 files) 82.98%
38.4
TRAVIS_OS_NAME=linux
1.13=.13

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading