97902e2619
1. text analysis is now done before the write lock is acquired 2. there is now a pool of analysis workers 3. the size of this pool is configurable 4. this allows for documents in a batch to be analyzed concurrently as a part of benchmarking these changes i've also introduce a new null storage implementation. this should never be used, as it does not actualy build an index. it does however let us go through all the normal indexing machinery, without incuring any indexing I/O. this is very helpful in measuring improvements made to the text analsysis pipeline, which are often overshadowed by indexing times in benchmarks actually building an index.
74 lines
3.7 KiB
Go
74 lines
3.7 KiB
Go
// Copyright (c) 2014 Couchbase, Inc.
|
|
// Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
|
|
// except in compliance with the License. You may obtain a copy of the License at
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
// Unless required by applicable law or agreed to in writing, software distributed under the
|
|
// License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
|
// either express or implied. See the License for the specific language governing permissions
|
|
// and limitations under the License.
|
|
|
|
package searchers
|
|
|
|
import (
|
|
"math"
|
|
"regexp"
|
|
|
|
"github.com/blevesearch/bleve/analysis"
|
|
"github.com/blevesearch/bleve/analysis/tokenizers/regexp_tokenizer"
|
|
"github.com/blevesearch/bleve/document"
|
|
"github.com/blevesearch/bleve/index"
|
|
"github.com/blevesearch/bleve/index/store/inmem"
|
|
"github.com/blevesearch/bleve/index/upside_down"
|
|
)
|
|
|
|
var twoDocIndex index.Index //= upside_down.NewUpsideDownCouch(inmem.MustOpen())
|
|
|
|
func init() {
|
|
inMemStore, _ := inmem.Open()
|
|
analysisQueue := upside_down.NewAnalysisQueue(1)
|
|
twoDocIndex = upside_down.NewUpsideDownCouch(inMemStore, analysisQueue)
|
|
for _, doc := range twoDocIndexDocs {
|
|
twoDocIndex.Update(doc)
|
|
}
|
|
}
|
|
|
|
// create a simpler analyzer which will support these tests
|
|
var testAnalyzer = &analysis.Analyzer{
|
|
Tokenizer: regexp_tokenizer.NewRegexpTokenizer(regexp.MustCompile(`\w+`)),
|
|
}
|
|
|
|
// sets up some mock data used in many tests in this package
|
|
var twoDocIndexDescIndexingOptions = document.DefaultTextIndexingOptions | document.IncludeTermVectors
|
|
|
|
var twoDocIndexDocs = []*document.Document{
|
|
// must have 4/4 beer
|
|
document.NewDocument("1").
|
|
AddField(document.NewTextField("name", []uint64{}, []byte("marty"))).
|
|
AddField(document.NewTextFieldCustom("desc", []uint64{}, []byte("beer beer beer beer"), twoDocIndexDescIndexingOptions, testAnalyzer)).
|
|
AddField(document.NewTextFieldWithAnalyzer("street", []uint64{}, []byte("couchbase way"), testAnalyzer)),
|
|
// must have 1/4 beer
|
|
document.NewDocument("2").
|
|
AddField(document.NewTextField("name", []uint64{}, []byte("steve"))).
|
|
AddField(document.NewTextFieldCustom("desc", []uint64{}, []byte("angst beer couch database"), twoDocIndexDescIndexingOptions, testAnalyzer)).
|
|
AddField(document.NewTextFieldWithAnalyzer("street", []uint64{}, []byte("couchbase way"), testAnalyzer)).
|
|
AddField(document.NewTextFieldWithAnalyzer("title", []uint64{}, []byte("mister"), testAnalyzer)),
|
|
// must have 1/4 beer
|
|
document.NewDocument("3").
|
|
AddField(document.NewTextField("name", []uint64{}, []byte("dustin"))).
|
|
AddField(document.NewTextFieldCustom("desc", []uint64{}, []byte("apple beer column dank"), twoDocIndexDescIndexingOptions, testAnalyzer)).
|
|
AddField(document.NewTextFieldWithAnalyzer("title", []uint64{}, []byte("mister"), testAnalyzer)),
|
|
// must have 65/65 beer
|
|
document.NewDocument("4").
|
|
AddField(document.NewTextField("name", []uint64{}, []byte("ravi"))).
|
|
AddField(document.NewTextFieldCustom("desc", []uint64{}, []byte("beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer beer"), twoDocIndexDescIndexingOptions, testAnalyzer)),
|
|
// must have 0/x beer
|
|
document.NewDocument("5").
|
|
AddField(document.NewTextField("name", []uint64{}, []byte("bobert"))).
|
|
AddField(document.NewTextFieldCustom("desc", []uint64{}, []byte("water"), twoDocIndexDescIndexingOptions, testAnalyzer)).
|
|
AddField(document.NewTextFieldWithAnalyzer("title", []uint64{}, []byte("mister"), testAnalyzer)),
|
|
}
|
|
|
|
func scoresCloseEnough(a, b float64) bool {
|
|
return math.Abs(a-b) < 0.001
|
|
}
|