refactor to make all the query classes private
This commit is contained in:
parent
607b038283
commit
f2c781fa21
|
@ -329,16 +329,16 @@ function SearchCtrl($scope, $http, $routeParams, $log, $sce) {
|
|||
var requestBody = {
|
||||
"query": {
|
||||
"must": {
|
||||
"terms":[],
|
||||
"conjuncts":[],
|
||||
"boost": 1.0,
|
||||
},
|
||||
"should":{
|
||||
"terms":[],
|
||||
"disjuncts":[],
|
||||
"boost": 1.0,
|
||||
"min": parseInt($scope.minShould, 10)
|
||||
},
|
||||
"must_not": {
|
||||
"terms": [],
|
||||
"disjuncts": [],
|
||||
"boost": 1.0,
|
||||
},
|
||||
"boost": 1.0,
|
||||
|
@ -353,27 +353,26 @@ function SearchCtrl($scope, $http, $routeParams, $log, $sce) {
|
|||
"term": clause.term,
|
||||
"field": clause.field,
|
||||
"boost": parseFloat(clause.boost),
|
||||
"explain": true
|
||||
};
|
||||
switch(clause.occur) {
|
||||
case "MUST":
|
||||
requestBody.query.must.terms.push(termQuery);
|
||||
requestBody.query.must.conjuncts.push(termQuery);
|
||||
break;
|
||||
case "SHOULD":
|
||||
requestBody.query.should.terms.push(termQuery);
|
||||
requestBody.query.should.disjuncts.push(termQuery);
|
||||
break;
|
||||
case "MUST NOT":
|
||||
requestBody.query.must_not.terms.push(termQuery);
|
||||
requestBody.query.must_not.disjuncts.push(termQuery);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (requestBody.query.must.terms.length === 0) {
|
||||
if (requestBody.query.must.conjuncts.length === 0) {
|
||||
delete requestBody.query.must;
|
||||
}
|
||||
if (requestBody.query.should.terms.length === 0) {
|
||||
if (requestBody.query.should.disjuncts.length === 0) {
|
||||
delete requestBody.query.should;
|
||||
}
|
||||
if (requestBody.query.must_not.terms.length === 0) {
|
||||
if (requestBody.query.must_not.disjuncts.length === 0) {
|
||||
delete requestBody.query.must_not;
|
||||
}
|
||||
|
||||
|
|
46
query.go
46
query.go
|
@ -17,6 +17,9 @@ import (
|
|||
|
||||
type Query interface {
|
||||
Boost() float64
|
||||
SetBoost(b float64) Query
|
||||
Field() string
|
||||
SetField(f string) Query
|
||||
Searcher(i *indexImpl, explain bool) (search.Searcher, error)
|
||||
Validate() error
|
||||
}
|
||||
|
@ -29,7 +32,7 @@ func ParseQuery(input []byte) (Query, error) {
|
|||
}
|
||||
_, isTermQuery := tmp["term"]
|
||||
if isTermQuery {
|
||||
var rv TermQuery
|
||||
var rv termQuery
|
||||
err := json.Unmarshal(input, &rv)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -41,7 +44,7 @@ func ParseQuery(input []byte) (Query, error) {
|
|||
}
|
||||
_, isMatchQuery := tmp["match"]
|
||||
if isMatchQuery {
|
||||
var rv MatchQuery
|
||||
var rv matchQuery
|
||||
err := json.Unmarshal(input, &rv)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -53,7 +56,7 @@ func ParseQuery(input []byte) (Query, error) {
|
|||
}
|
||||
_, isMatchPhraseQuery := tmp["match_phrase"]
|
||||
if isMatchPhraseQuery {
|
||||
var rv MatchPhraseQuery
|
||||
var rv matchPhraseQuery
|
||||
err := json.Unmarshal(input, &rv)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -67,7 +70,7 @@ func ParseQuery(input []byte) (Query, error) {
|
|||
_, hasShould := tmp["should"]
|
||||
_, hasMustNot := tmp["must_not"]
|
||||
if hasMust || hasShould || hasMustNot {
|
||||
var rv BooleanQuery
|
||||
var rv booleanQuery
|
||||
err := json.Unmarshal(input, &rv)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -79,7 +82,7 @@ func ParseQuery(input []byte) (Query, error) {
|
|||
}
|
||||
_, hasTerms := tmp["terms"]
|
||||
if hasTerms {
|
||||
var rv PhraseQuery
|
||||
var rv phraseQuery
|
||||
err := json.Unmarshal(input, &rv)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -94,9 +97,34 @@ func ParseQuery(input []byte) (Query, error) {
|
|||
}
|
||||
return &rv, nil
|
||||
}
|
||||
_, hasConjuncts := tmp["conjuncts"]
|
||||
if hasConjuncts {
|
||||
var rv conjunctionQuery
|
||||
err := json.Unmarshal(input, &rv)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if rv.Boost() == 0 {
|
||||
rv.SetBoost(1)
|
||||
}
|
||||
return &rv, nil
|
||||
}
|
||||
_, hasDisjuncts := tmp["disjuncts"]
|
||||
if hasDisjuncts {
|
||||
var rv disjunctionQuery
|
||||
err := json.Unmarshal(input, &rv)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if rv.Boost() == 0 {
|
||||
rv.SetBoost(1)
|
||||
}
|
||||
return &rv, nil
|
||||
}
|
||||
|
||||
_, hasSyntaxQuery := tmp["query"]
|
||||
if hasSyntaxQuery {
|
||||
var rv QueryStringQuery
|
||||
var rv queryStringQuery
|
||||
err := json.Unmarshal(input, &rv)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -109,7 +137,7 @@ func ParseQuery(input []byte) (Query, error) {
|
|||
_, hasMin := tmp["min"]
|
||||
_, hasMax := tmp["max"]
|
||||
if hasMin || hasMax {
|
||||
var rv NumericRangeQuery
|
||||
var rv numericRangeQuery
|
||||
err := json.Unmarshal(input, &rv)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -122,7 +150,7 @@ func ParseQuery(input []byte) (Query, error) {
|
|||
_, hasStart := tmp["start"]
|
||||
_, hasEnd := tmp["end"]
|
||||
if hasStart || hasEnd {
|
||||
var rv DateRangeQuery
|
||||
var rv dateRangeQuery
|
||||
err := json.Unmarshal(input, &rv)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -134,7 +162,7 @@ func ParseQuery(input []byte) (Query, error) {
|
|||
}
|
||||
_, hasPrefix := tmp["prefix"]
|
||||
if hasPrefix {
|
||||
var rv PrefixQuery
|
||||
var rv prefixQuery
|
||||
err := json.Unmarshal(input, &rv)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
125
query_boolean.go
125
query_boolean.go
|
@ -10,17 +10,20 @@
|
|||
package bleve
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/blevesearch/bleve/search"
|
||||
)
|
||||
|
||||
type BooleanQuery struct {
|
||||
Must *ConjunctionQuery `json:"must,omitempty"`
|
||||
Should *DisjunctionQuery `json:"should,omitempty"`
|
||||
MustNot *DisjunctionQuery `json:"must_not,omitempty"`
|
||||
BoostVal float64 `json:"boost,omitempty"`
|
||||
type booleanQuery struct {
|
||||
Must Query `json:"must,omitempty"`
|
||||
Should Query `json:"should,omitempty"`
|
||||
MustNot Query `json:"must_not,omitempty"`
|
||||
BoostVal float64 `json:"boost,omitempty"`
|
||||
}
|
||||
|
||||
func NewBooleanQuery(must []Query, should []Query, mustNot []Query) *BooleanQuery {
|
||||
func NewBooleanQuery(must []Query, should []Query, mustNot []Query) *booleanQuery {
|
||||
min := 0.0
|
||||
if len(should) > 0 {
|
||||
min = 1.0
|
||||
|
@ -28,63 +31,64 @@ func NewBooleanQuery(must []Query, should []Query, mustNot []Query) *BooleanQuer
|
|||
return NewBooleanQueryMinShould(must, should, mustNot, min)
|
||||
}
|
||||
|
||||
func NewBooleanQueryMinShould(must []Query, should []Query, mustNot []Query, minShould float64) *BooleanQuery {
|
||||
return &BooleanQuery{
|
||||
Must: NewConjunctionQuery(must),
|
||||
Should: NewDisjunctionQueryMin(should, minShould),
|
||||
MustNot: NewDisjunctionQuery(mustNot),
|
||||
func NewBooleanQueryMinShould(must []Query, should []Query, mustNot []Query, minShould float64) *booleanQuery {
|
||||
|
||||
rv := booleanQuery{
|
||||
BoostVal: 1.0,
|
||||
}
|
||||
if len(must) > 0 {
|
||||
rv.Must = NewConjunctionQuery(must)
|
||||
}
|
||||
if len(should) > 0 {
|
||||
rv.Should = NewDisjunctionQueryMin(should, minShould)
|
||||
}
|
||||
if len(mustNot) > 0 {
|
||||
rv.MustNot = NewDisjunctionQuery(mustNot)
|
||||
}
|
||||
|
||||
return &rv
|
||||
}
|
||||
|
||||
func (q *BooleanQuery) Boost() float64 {
|
||||
func (q *booleanQuery) Boost() float64 {
|
||||
return q.BoostVal
|
||||
}
|
||||
|
||||
func (q *BooleanQuery) SetBoost(b float64) *BooleanQuery {
|
||||
func (q *booleanQuery) SetBoost(b float64) Query {
|
||||
q.BoostVal = b
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *BooleanQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) {
|
||||
func (q *booleanQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) {
|
||||
var err error
|
||||
|
||||
var mustSearcher *search.ConjunctionSearcher
|
||||
var mustSearcher search.Searcher
|
||||
if q.Must != nil {
|
||||
ms, err := q.Must.Searcher(i, explain)
|
||||
mustSearcher, err = q.Must.Searcher(i, explain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if ms != nil {
|
||||
mustSearcher = ms.(*search.ConjunctionSearcher)
|
||||
}
|
||||
}
|
||||
|
||||
var shouldSearcher *search.DisjunctionSearcher
|
||||
var shouldSearcher search.Searcher
|
||||
if q.Should != nil {
|
||||
ss, err := q.Should.Searcher(i, explain)
|
||||
shouldSearcher, err = q.Should.Searcher(i, explain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if ss != nil {
|
||||
shouldSearcher = ss.(*search.DisjunctionSearcher)
|
||||
}
|
||||
}
|
||||
|
||||
var mustNotSearcher *search.DisjunctionSearcher
|
||||
var mustNotSearcher search.Searcher
|
||||
if q.MustNot != nil {
|
||||
mns, err := q.MustNot.Searcher(i, explain)
|
||||
mustNotSearcher, err = q.MustNot.Searcher(i, explain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if mns != nil {
|
||||
mustNotSearcher = mns.(*search.DisjunctionSearcher)
|
||||
}
|
||||
}
|
||||
|
||||
return search.NewBooleanSearcher(i.i, mustSearcher, shouldSearcher, mustNotSearcher, explain)
|
||||
}
|
||||
|
||||
func (q *BooleanQuery) Validate() error {
|
||||
func (q *booleanQuery) Validate() error {
|
||||
if q.Must != nil {
|
||||
err := q.Must.Validate()
|
||||
if err != nil {
|
||||
|
@ -106,8 +110,65 @@ func (q *BooleanQuery) Validate() error {
|
|||
if q.Must == nil && q.Should == nil {
|
||||
return ERROR_BOOLEAN_QUERY_NEEDS_MUST_OR_SHOULD
|
||||
}
|
||||
if q.Must != nil && len(q.Must.Conjuncts) == 0 && q.Should != nil && len(q.Should.Disjuncts) == 0 {
|
||||
return ERROR_BOOLEAN_QUERY_NEEDS_MUST_OR_SHOULD
|
||||
return nil
|
||||
}
|
||||
|
||||
func (q *booleanQuery) UnmarshalJSON(data []byte) error {
|
||||
tmp := struct {
|
||||
Must json.RawMessage `json:"must,omitempty"`
|
||||
Should json.RawMessage `json:"should,omitempty"`
|
||||
MustNot json.RawMessage `json:"must_not,omitempty"`
|
||||
BoostVal float64 `json:"boost,omitempty"`
|
||||
}{}
|
||||
err := json.Unmarshal(data, &tmp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if tmp.Must != nil {
|
||||
q.Must, err = ParseQuery(tmp.Must)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, isConjunctionQuery := q.Must.(*conjunctionQuery)
|
||||
if !isConjunctionQuery {
|
||||
return fmt.Errorf("must clause must be conjunction")
|
||||
}
|
||||
}
|
||||
|
||||
if tmp.Should != nil {
|
||||
q.Should, err = ParseQuery(tmp.Should)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, isDisjunctionQuery := q.Should.(*disjunctionQuery)
|
||||
if !isDisjunctionQuery {
|
||||
return fmt.Errorf("should clause must be disjunction")
|
||||
}
|
||||
}
|
||||
|
||||
if tmp.MustNot != nil {
|
||||
q.MustNot, err = ParseQuery(tmp.MustNot)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, isDisjunctionQuery := q.MustNot.(*disjunctionQuery)
|
||||
if !isDisjunctionQuery {
|
||||
return fmt.Errorf("must not clause must be disjunction")
|
||||
}
|
||||
}
|
||||
|
||||
q.BoostVal = tmp.BoostVal
|
||||
if q.BoostVal == 0 {
|
||||
q.BoostVal = 1
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (q *booleanQuery) Field() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (q *booleanQuery) SetField(f string) Query {
|
||||
return q
|
||||
}
|
||||
|
|
|
@ -15,36 +15,33 @@ import (
|
|||
"github.com/blevesearch/bleve/search"
|
||||
)
|
||||
|
||||
type ConjunctionQuery struct {
|
||||
Conjuncts []Query `json:"terms"`
|
||||
type conjunctionQuery struct {
|
||||
Conjuncts []Query `json:"conjuncts"`
|
||||
BoostVal float64 `json:"boost,omitempty"`
|
||||
}
|
||||
|
||||
func NewConjunctionQuery(conjuncts []Query) *ConjunctionQuery {
|
||||
if len(conjuncts) == 0 {
|
||||
return nil
|
||||
}
|
||||
return &ConjunctionQuery{
|
||||
func NewConjunctionQuery(conjuncts []Query) *conjunctionQuery {
|
||||
return &conjunctionQuery{
|
||||
Conjuncts: conjuncts,
|
||||
BoostVal: 1.0,
|
||||
}
|
||||
}
|
||||
|
||||
func (q *ConjunctionQuery) Boost() float64 {
|
||||
func (q *conjunctionQuery) Boost() float64 {
|
||||
return q.BoostVal
|
||||
}
|
||||
|
||||
func (q *ConjunctionQuery) SetBoost(b float64) *ConjunctionQuery {
|
||||
func (q *conjunctionQuery) SetBoost(b float64) Query {
|
||||
q.BoostVal = b
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *ConjunctionQuery) AddQuery(aq Query) *ConjunctionQuery {
|
||||
func (q *conjunctionQuery) AddQuery(aq Query) *conjunctionQuery {
|
||||
q.Conjuncts = append(q.Conjuncts, aq)
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *ConjunctionQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) {
|
||||
func (q *conjunctionQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) {
|
||||
searchers := make([]search.Searcher, len(q.Conjuncts))
|
||||
for in, conjunct := range q.Conjuncts {
|
||||
var err error
|
||||
|
@ -56,13 +53,13 @@ func (q *ConjunctionQuery) Searcher(i *indexImpl, explain bool) (search.Searcher
|
|||
return search.NewConjunctionSearcher(i.i, searchers, explain)
|
||||
}
|
||||
|
||||
func (q *ConjunctionQuery) Validate() error {
|
||||
func (q *conjunctionQuery) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (q *ConjunctionQuery) UnmarshalJSON(data []byte) error {
|
||||
func (q *conjunctionQuery) UnmarshalJSON(data []byte) error {
|
||||
tmp := struct {
|
||||
Conjuncts []json.RawMessage `json:"terms"`
|
||||
Conjuncts []json.RawMessage `json:"conjuncts"`
|
||||
BoostVal float64 `json:"boost,omitempty"`
|
||||
}{}
|
||||
err := json.Unmarshal(data, &tmp)
|
||||
|
@ -83,3 +80,11 @@ func (q *ConjunctionQuery) UnmarshalJSON(data []byte) error {
|
|||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (q *conjunctionQuery) Field() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (q *conjunctionQuery) SetField(f string) Query {
|
||||
return q
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ import (
|
|||
"github.com/blevesearch/bleve/search"
|
||||
)
|
||||
|
||||
type DateRangeQuery struct {
|
||||
type dateRangeQuery struct {
|
||||
Start *string `json:"start,omitempty"`
|
||||
End *string `json:"end,omitempty"`
|
||||
InclusiveStart *bool `json:"inclusive_start,omitempty"`
|
||||
|
@ -27,12 +27,12 @@ type DateRangeQuery struct {
|
|||
DateTimeParser *string `json:"datetime_parser,omitempty"`
|
||||
}
|
||||
|
||||
func NewDateRangeQuery(start, end *string) *DateRangeQuery {
|
||||
func NewDateRangeQuery(start, end *string) *dateRangeQuery {
|
||||
return NewDateRangeInclusiveQuery(start, end, nil, nil)
|
||||
}
|
||||
|
||||
func NewDateRangeInclusiveQuery(start, end *string, startInclusive, endInclusive *bool) *DateRangeQuery {
|
||||
return &DateRangeQuery{
|
||||
func NewDateRangeInclusiveQuery(start, end *string, startInclusive, endInclusive *bool) *dateRangeQuery {
|
||||
return &dateRangeQuery{
|
||||
Start: start,
|
||||
End: end,
|
||||
InclusiveStart: startInclusive,
|
||||
|
@ -41,25 +41,25 @@ func NewDateRangeInclusiveQuery(start, end *string, startInclusive, endInclusive
|
|||
}
|
||||
}
|
||||
|
||||
func (q *DateRangeQuery) Boost() float64 {
|
||||
func (q *dateRangeQuery) Boost() float64 {
|
||||
return q.BoostVal
|
||||
}
|
||||
|
||||
func (q *DateRangeQuery) SetBoost(b float64) *DateRangeQuery {
|
||||
func (q *dateRangeQuery) SetBoost(b float64) Query {
|
||||
q.BoostVal = b
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *DateRangeQuery) Field() string {
|
||||
func (q *dateRangeQuery) Field() string {
|
||||
return q.FieldVal
|
||||
}
|
||||
|
||||
func (q *DateRangeQuery) SetField(f string) *DateRangeQuery {
|
||||
func (q *dateRangeQuery) SetField(f string) Query {
|
||||
q.FieldVal = f
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *DateRangeQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) {
|
||||
func (q *dateRangeQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) {
|
||||
|
||||
dateTimeParserName := ""
|
||||
if q.DateTimeParser != nil {
|
||||
|
@ -98,7 +98,7 @@ func (q *DateRangeQuery) Searcher(i *indexImpl, explain bool) (search.Searcher,
|
|||
return search.NewNumericRangeSearcher(i.i, &min, &max, q.InclusiveStart, q.InclusiveEnd, field, q.BoostVal, explain)
|
||||
}
|
||||
|
||||
func (q *DateRangeQuery) Validate() error {
|
||||
func (q *dateRangeQuery) Validate() error {
|
||||
if q.Start == nil && q.Start == q.End {
|
||||
return fmt.Errorf("must specify start or end")
|
||||
}
|
||||
|
|
|
@ -15,57 +15,54 @@ import (
|
|||
"github.com/blevesearch/bleve/search"
|
||||
)
|
||||
|
||||
type DisjunctionQuery struct {
|
||||
Disjuncts []Query `json:"terms"`
|
||||
type disjunctionQuery struct {
|
||||
Disjuncts []Query `json:"disjuncts"`
|
||||
BoostVal float64 `json:"boost,omitempty"`
|
||||
MinVal float64 `json:"min"`
|
||||
}
|
||||
|
||||
func NewDisjunctionQuery(disjuncts []Query) *DisjunctionQuery {
|
||||
if len(disjuncts) == 0 {
|
||||
return nil
|
||||
}
|
||||
return &DisjunctionQuery{
|
||||
func NewDisjunctionQuery(disjuncts []Query) *disjunctionQuery {
|
||||
return &disjunctionQuery{
|
||||
Disjuncts: disjuncts,
|
||||
BoostVal: 1.0,
|
||||
}
|
||||
}
|
||||
|
||||
func NewDisjunctionQueryMin(disjuncts []Query, min float64) *DisjunctionQuery {
|
||||
func NewDisjunctionQueryMin(disjuncts []Query, min float64) *disjunctionQuery {
|
||||
if len(disjuncts) == 0 {
|
||||
return nil
|
||||
}
|
||||
return &DisjunctionQuery{
|
||||
return &disjunctionQuery{
|
||||
Disjuncts: disjuncts,
|
||||
BoostVal: 1.0,
|
||||
MinVal: min,
|
||||
}
|
||||
}
|
||||
|
||||
func (q *DisjunctionQuery) Boost() float64 {
|
||||
func (q *disjunctionQuery) Boost() float64 {
|
||||
return q.BoostVal
|
||||
}
|
||||
|
||||
func (q *DisjunctionQuery) SetBoost(b float64) *DisjunctionQuery {
|
||||
func (q *disjunctionQuery) SetBoost(b float64) Query {
|
||||
q.BoostVal = b
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *DisjunctionQuery) AddQuery(aq Query) *DisjunctionQuery {
|
||||
func (q *disjunctionQuery) AddQuery(aq Query) Query {
|
||||
q.Disjuncts = append(q.Disjuncts, aq)
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *DisjunctionQuery) Min() float64 {
|
||||
func (q *disjunctionQuery) Min() float64 {
|
||||
return q.MinVal
|
||||
}
|
||||
|
||||
func (q *DisjunctionQuery) SetMin(m float64) *DisjunctionQuery {
|
||||
func (q *disjunctionQuery) SetMin(m float64) Query {
|
||||
q.MinVal = m
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *DisjunctionQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) {
|
||||
func (q *disjunctionQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) {
|
||||
searchers := make([]search.Searcher, len(q.Disjuncts))
|
||||
for in, disjunct := range q.Disjuncts {
|
||||
var err error
|
||||
|
@ -77,16 +74,16 @@ func (q *DisjunctionQuery) Searcher(i *indexImpl, explain bool) (search.Searcher
|
|||
return search.NewDisjunctionSearcher(i.i, searchers, q.MinVal, explain)
|
||||
}
|
||||
|
||||
func (q *DisjunctionQuery) Validate() error {
|
||||
func (q *disjunctionQuery) Validate() error {
|
||||
if int(q.MinVal) > len(q.Disjuncts) {
|
||||
return ERROR_DISJUNCTION_FEWER_THAN_MIN_CLAUSES
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (q *DisjunctionQuery) UnmarshalJSON(data []byte) error {
|
||||
func (q *disjunctionQuery) UnmarshalJSON(data []byte) error {
|
||||
tmp := struct {
|
||||
Disjuncts []json.RawMessage `json:"terms"`
|
||||
Disjuncts []json.RawMessage `json:"disjuncts"`
|
||||
BoostVal float64 `json:"boost,omitempty"`
|
||||
MinVal float64 `json:"min"`
|
||||
}{}
|
||||
|
@ -109,3 +106,11 @@ func (q *DisjunctionQuery) UnmarshalJSON(data []byte) error {
|
|||
q.MinVal = tmp.MinVal
|
||||
return nil
|
||||
}
|
||||
|
||||
func (q *disjunctionQuery) Field() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (q *disjunctionQuery) SetField(f string) Query {
|
||||
return q
|
||||
}
|
||||
|
|
|
@ -15,39 +15,39 @@ import (
|
|||
"github.com/blevesearch/bleve/search"
|
||||
)
|
||||
|
||||
type MatchQuery struct {
|
||||
type matchQuery struct {
|
||||
Match string `json:"match"`
|
||||
FieldVal string `json:"field,omitempty"`
|
||||
Analyzer string `json:"analyzer,omitempty"`
|
||||
BoostVal float64 `json:"boost,omitempty"`
|
||||
}
|
||||
|
||||
func NewMatchQuery(match string) *MatchQuery {
|
||||
return &MatchQuery{
|
||||
func NewMatchQuery(match string) *matchQuery {
|
||||
return &matchQuery{
|
||||
Match: match,
|
||||
BoostVal: 1.0,
|
||||
}
|
||||
}
|
||||
|
||||
func (q *MatchQuery) Boost() float64 {
|
||||
func (q *matchQuery) Boost() float64 {
|
||||
return q.BoostVal
|
||||
}
|
||||
|
||||
func (q *MatchQuery) SetBoost(b float64) *MatchQuery {
|
||||
func (q *matchQuery) SetBoost(b float64) Query {
|
||||
q.BoostVal = b
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *MatchQuery) Field() string {
|
||||
func (q *matchQuery) Field() string {
|
||||
return q.FieldVal
|
||||
}
|
||||
|
||||
func (q *MatchQuery) SetField(f string) *MatchQuery {
|
||||
func (q *matchQuery) SetField(f string) Query {
|
||||
q.FieldVal = f
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *MatchQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) {
|
||||
func (q *matchQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) {
|
||||
|
||||
analyzerName := ""
|
||||
if q.Analyzer != "" {
|
||||
|
@ -76,9 +76,8 @@ func (q *MatchQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, erro
|
|||
SetBoost(q.BoostVal)
|
||||
}
|
||||
|
||||
shouldQuery := NewDisjunctionQuery(tqs).
|
||||
SetBoost(q.BoostVal).
|
||||
SetMin(1)
|
||||
shouldQuery := NewDisjunctionQueryMin(tqs, 1).
|
||||
SetBoost(q.BoostVal)
|
||||
|
||||
return shouldQuery.Searcher(i, explain)
|
||||
} else {
|
||||
|
@ -87,6 +86,6 @@ func (q *MatchQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, erro
|
|||
}
|
||||
}
|
||||
|
||||
func (q *MatchQuery) Validate() error {
|
||||
func (q *matchQuery) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -13,29 +13,37 @@ import (
|
|||
"github.com/blevesearch/bleve/search"
|
||||
)
|
||||
|
||||
type MatchAllQuery struct {
|
||||
type matchAllQuery struct {
|
||||
BoostVal float64 `json:"boost,omitempty"`
|
||||
}
|
||||
|
||||
func NewMatchAllQuery() *MatchAllQuery {
|
||||
return &MatchAllQuery{
|
||||
func NewMatchAllQuery() *matchAllQuery {
|
||||
return &matchAllQuery{
|
||||
BoostVal: 1.0,
|
||||
}
|
||||
}
|
||||
|
||||
func (q *MatchAllQuery) Boost() float64 {
|
||||
func (q *matchAllQuery) Boost() float64 {
|
||||
return q.BoostVal
|
||||
}
|
||||
|
||||
func (q *MatchAllQuery) SetBoost(b float64) *MatchAllQuery {
|
||||
func (q *matchAllQuery) SetBoost(b float64) Query {
|
||||
q.BoostVal = b
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *MatchAllQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) {
|
||||
func (q *matchAllQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) {
|
||||
return search.NewMatchAllSearcher(i.i, q.BoostVal, explain)
|
||||
}
|
||||
|
||||
func (q *MatchAllQuery) Validate() error {
|
||||
func (q *matchAllQuery) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (q *matchAllQuery) Field() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (q *matchAllQuery) SetField(f string) Query {
|
||||
return q
|
||||
}
|
||||
|
|
|
@ -13,29 +13,37 @@ import (
|
|||
"github.com/blevesearch/bleve/search"
|
||||
)
|
||||
|
||||
type MatchNoneQuery struct {
|
||||
type matchNoneQuery struct {
|
||||
BoostVal float64 `json:"boost,omitempty"`
|
||||
}
|
||||
|
||||
func NewMatchNoneQuery() *MatchNoneQuery {
|
||||
return &MatchNoneQuery{
|
||||
func NewMatchNoneQuery() *matchNoneQuery {
|
||||
return &matchNoneQuery{
|
||||
BoostVal: 1.0,
|
||||
}
|
||||
}
|
||||
|
||||
func (q *MatchNoneQuery) Boost() float64 {
|
||||
func (q *matchNoneQuery) Boost() float64 {
|
||||
return q.BoostVal
|
||||
}
|
||||
|
||||
func (q *MatchNoneQuery) SetBoost(b float64) *MatchNoneQuery {
|
||||
func (q *matchNoneQuery) SetBoost(b float64) Query {
|
||||
q.BoostVal = b
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *MatchNoneQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) {
|
||||
func (q *matchNoneQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) {
|
||||
return search.NewMatchNoneSearcher(i.i)
|
||||
}
|
||||
|
||||
func (q *MatchNoneQuery) Validate() error {
|
||||
func (q *matchNoneQuery) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (q *matchNoneQuery) Field() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (q *matchNoneQuery) SetField(f string) Query {
|
||||
return q
|
||||
}
|
||||
|
|
|
@ -15,39 +15,39 @@ import (
|
|||
"github.com/blevesearch/bleve/search"
|
||||
)
|
||||
|
||||
type MatchPhraseQuery struct {
|
||||
type matchPhraseQuery struct {
|
||||
MatchPhrase string `json:"match_phrase"`
|
||||
FieldVal string `json:"field,omitempty"`
|
||||
Analyzer string `json:"analyzer,omitempty"`
|
||||
BoostVal float64 `json:"boost,omitempty"`
|
||||
}
|
||||
|
||||
func NewMatchPhraseQuery(matchPhrase string) *MatchPhraseQuery {
|
||||
return &MatchPhraseQuery{
|
||||
func NewMatchPhraseQuery(matchPhrase string) *matchPhraseQuery {
|
||||
return &matchPhraseQuery{
|
||||
MatchPhrase: matchPhrase,
|
||||
BoostVal: 1.0,
|
||||
}
|
||||
}
|
||||
|
||||
func (q *MatchPhraseQuery) Boost() float64 {
|
||||
func (q *matchPhraseQuery) Boost() float64 {
|
||||
return q.BoostVal
|
||||
}
|
||||
|
||||
func (q *MatchPhraseQuery) SetBoost(b float64) *MatchPhraseQuery {
|
||||
func (q *matchPhraseQuery) SetBoost(b float64) Query {
|
||||
q.BoostVal = b
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *MatchPhraseQuery) Field() string {
|
||||
func (q *matchPhraseQuery) Field() string {
|
||||
return q.FieldVal
|
||||
}
|
||||
|
||||
func (q *MatchPhraseQuery) SetField(f string) *MatchPhraseQuery {
|
||||
func (q *matchPhraseQuery) SetField(f string) Query {
|
||||
q.FieldVal = f
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *MatchPhraseQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) {
|
||||
func (q *matchPhraseQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) {
|
||||
|
||||
analyzerName := ""
|
||||
if q.Analyzer != "" {
|
||||
|
@ -67,14 +67,12 @@ func (q *MatchPhraseQuery) Searcher(i *indexImpl, explain bool) (search.Searcher
|
|||
|
||||
tokens := analyzer.Analyze([]byte(q.MatchPhrase))
|
||||
if len(tokens) > 0 {
|
||||
tqs := make([]*TermQuery, len(tokens))
|
||||
ts := make([]string, len(tokens))
|
||||
for i, token := range tokens {
|
||||
tqs[i] = NewTermQuery(string(token.Term)).
|
||||
SetField(field).
|
||||
SetBoost(q.BoostVal)
|
||||
ts[i] = string(token.Term)
|
||||
}
|
||||
|
||||
phraseQuery := NewPhraseQuery(tqs)
|
||||
phraseQuery := NewPhraseQuery(ts, field).SetBoost(q.BoostVal)
|
||||
|
||||
return phraseQuery.Searcher(i, explain)
|
||||
} else {
|
||||
|
@ -83,6 +81,6 @@ func (q *MatchPhraseQuery) Searcher(i *indexImpl, explain bool) (search.Searcher
|
|||
}
|
||||
}
|
||||
|
||||
func (q *MatchPhraseQuery) Validate() error {
|
||||
func (q *matchPhraseQuery) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
"github.com/blevesearch/bleve/search"
|
||||
)
|
||||
|
||||
type NumericRangeQuery struct {
|
||||
type numericRangeQuery struct {
|
||||
Min *float64 `json:"min,omitempty"`
|
||||
Max *float64 `json:"max,omitempty"`
|
||||
InclusiveMin *bool `json:"inclusive_min,omitempty"`
|
||||
|
@ -22,12 +22,12 @@ type NumericRangeQuery struct {
|
|||
BoostVal float64 `json:"boost,omitempty"`
|
||||
}
|
||||
|
||||
func NewNumericRangeQuery(min, max *float64) *NumericRangeQuery {
|
||||
func NewNumericRangeQuery(min, max *float64) *numericRangeQuery {
|
||||
return NewNumericRangeInclusiveQuery(min, max, nil, nil)
|
||||
}
|
||||
|
||||
func NewNumericRangeInclusiveQuery(min, max *float64, minInclusive, maxInclusive *bool) *NumericRangeQuery {
|
||||
return &NumericRangeQuery{
|
||||
func NewNumericRangeInclusiveQuery(min, max *float64, minInclusive, maxInclusive *bool) *numericRangeQuery {
|
||||
return &numericRangeQuery{
|
||||
Min: min,
|
||||
Max: max,
|
||||
InclusiveMin: minInclusive,
|
||||
|
@ -36,25 +36,25 @@ func NewNumericRangeInclusiveQuery(min, max *float64, minInclusive, maxInclusive
|
|||
}
|
||||
}
|
||||
|
||||
func (q *NumericRangeQuery) Boost() float64 {
|
||||
func (q *numericRangeQuery) Boost() float64 {
|
||||
return q.BoostVal
|
||||
}
|
||||
|
||||
func (q *NumericRangeQuery) SetBoost(b float64) *NumericRangeQuery {
|
||||
func (q *numericRangeQuery) SetBoost(b float64) Query {
|
||||
q.BoostVal = b
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *NumericRangeQuery) Field() string {
|
||||
func (q *numericRangeQuery) Field() string {
|
||||
return q.FieldVal
|
||||
}
|
||||
|
||||
func (q *NumericRangeQuery) SetField(f string) *NumericRangeQuery {
|
||||
func (q *numericRangeQuery) SetField(f string) Query {
|
||||
q.FieldVal = f
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *NumericRangeQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) {
|
||||
func (q *numericRangeQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) {
|
||||
field := q.FieldVal
|
||||
if q.FieldVal == "" {
|
||||
field = i.m.DefaultField
|
||||
|
@ -62,7 +62,7 @@ func (q *NumericRangeQuery) Searcher(i *indexImpl, explain bool) (search.Searche
|
|||
return search.NewNumericRangeSearcher(i.i, q.Min, q.Max, q.InclusiveMin, q.InclusiveMax, field, q.BoostVal, explain)
|
||||
}
|
||||
|
||||
func (q *NumericRangeQuery) Validate() error {
|
||||
func (q *numericRangeQuery) Validate() error {
|
||||
if q.Min == nil && q.Min == q.Max {
|
||||
return ERROR_NUMERIC_QUERY_NO_BOUNDS
|
||||
}
|
||||
|
|
|
@ -10,40 +10,45 @@
|
|||
package bleve
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/blevesearch/bleve/search"
|
||||
)
|
||||
|
||||
type PhraseQuery struct {
|
||||
Terms []*TermQuery `json:"terms"`
|
||||
BoostVal float64 `json:"boost,omitempty"`
|
||||
type phraseQuery struct {
|
||||
Terms []Query `json:"terms"`
|
||||
BoostVal float64 `json:"boost,omitempty"`
|
||||
}
|
||||
|
||||
func NewPhraseQuery(terms []*TermQuery) *PhraseQuery {
|
||||
return &PhraseQuery{
|
||||
Terms: terms,
|
||||
func NewPhraseQuery(terms []string, field string) *phraseQuery {
|
||||
termQueries := make([]Query, len(terms))
|
||||
for i, term := range terms {
|
||||
termQueries[i] = NewTermQuery(term).SetField(field)
|
||||
}
|
||||
return &phraseQuery{
|
||||
Terms: termQueries,
|
||||
BoostVal: 1.0,
|
||||
}
|
||||
}
|
||||
|
||||
func (q *PhraseQuery) Boost() float64 {
|
||||
func (q *phraseQuery) Boost() float64 {
|
||||
return q.BoostVal
|
||||
}
|
||||
|
||||
func (q *PhraseQuery) SetBoost(b float64) *PhraseQuery {
|
||||
func (q *phraseQuery) SetBoost(b float64) Query {
|
||||
q.BoostVal = b
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *PhraseQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) {
|
||||
func (q *phraseQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) {
|
||||
|
||||
terms := make([]string, len(q.Terms))
|
||||
conjuncts := make([]Query, len(q.Terms))
|
||||
for i, term := range q.Terms {
|
||||
conjuncts[i] = term
|
||||
terms[i] = term.Term
|
||||
terms[i] = term.(*termQuery).Term
|
||||
}
|
||||
|
||||
conjunctionQuery := NewConjunctionQuery(conjuncts)
|
||||
conjunctionQuery := NewConjunctionQuery(q.Terms)
|
||||
conjunctionSearcher, err := conjunctionQuery.Searcher(i, explain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -51,9 +56,45 @@ func (q *PhraseQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, err
|
|||
return search.NewPhraseSearcher(i.i, conjunctionSearcher.(*search.ConjunctionSearcher), terms)
|
||||
}
|
||||
|
||||
func (q *PhraseQuery) Validate() error {
|
||||
func (q *phraseQuery) Validate() error {
|
||||
if len(q.Terms) < 1 {
|
||||
return ERROR_PHRASE_QUERY_NO_TERMS
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (q *phraseQuery) UnmarshalJSON(data []byte) error {
|
||||
tmp := struct {
|
||||
Terms []json.RawMessage `json:"terms"`
|
||||
BoostVal float64 `json:"boost,omitempty"`
|
||||
}{}
|
||||
err := json.Unmarshal(data, &tmp)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
q.Terms = make([]Query, len(tmp.Terms))
|
||||
for i, term := range tmp.Terms {
|
||||
query, err := ParseQuery(term)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
q.Terms[i] = query
|
||||
_, isTermQuery := query.(*termQuery)
|
||||
if !isTermQuery {
|
||||
return fmt.Errorf("phrase query can only contain term queries")
|
||||
}
|
||||
}
|
||||
q.BoostVal = tmp.BoostVal
|
||||
if q.BoostVal == 0 {
|
||||
q.BoostVal = 1
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (q *phraseQuery) Field() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (q *phraseQuery) SetField(f string) Query {
|
||||
return q
|
||||
}
|
||||
|
|
|
@ -13,38 +13,38 @@ import (
|
|||
"github.com/blevesearch/bleve/search"
|
||||
)
|
||||
|
||||
type PrefixQuery struct {
|
||||
type prefixQuery struct {
|
||||
Prefix string `json:"prefix"`
|
||||
FieldVal string `json:"field,omitempty"`
|
||||
BoostVal float64 `json:"boost,omitempty"`
|
||||
}
|
||||
|
||||
func NewPrefixQuery(prefix string) *PrefixQuery {
|
||||
return &PrefixQuery{
|
||||
func NewPrefixQuery(prefix string) *prefixQuery {
|
||||
return &prefixQuery{
|
||||
Prefix: prefix,
|
||||
BoostVal: 1.0,
|
||||
}
|
||||
}
|
||||
|
||||
func (q *PrefixQuery) Boost() float64 {
|
||||
func (q *prefixQuery) Boost() float64 {
|
||||
return q.BoostVal
|
||||
}
|
||||
|
||||
func (q *PrefixQuery) SetBoost(b float64) *PrefixQuery {
|
||||
func (q *prefixQuery) SetBoost(b float64) Query {
|
||||
q.BoostVal = b
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *PrefixQuery) Field() string {
|
||||
func (q *prefixQuery) Field() string {
|
||||
return q.FieldVal
|
||||
}
|
||||
|
||||
func (q *PrefixQuery) SetField(f string) *PrefixQuery {
|
||||
func (q *prefixQuery) SetField(f string) Query {
|
||||
q.FieldVal = f
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *PrefixQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) {
|
||||
func (q *prefixQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) {
|
||||
field := q.FieldVal
|
||||
if q.FieldVal == "" {
|
||||
field = i.m.DefaultField
|
||||
|
@ -52,6 +52,6 @@ func (q *PrefixQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, err
|
|||
return search.NewTermPrefixSearcher(i.i, q.Prefix, field, q.BoostVal, explain)
|
||||
}
|
||||
|
||||
func (q *PrefixQuery) Validate() error {
|
||||
func (q *prefixQuery) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -13,28 +13,28 @@ import (
|
|||
"github.com/blevesearch/bleve/search"
|
||||
)
|
||||
|
||||
type QueryStringQuery struct {
|
||||
type queryStringQuery struct {
|
||||
Query string `json:"query"`
|
||||
BoostVal float64 `json:"boost,omitempty"`
|
||||
}
|
||||
|
||||
func NewQueryStringQuery(query string) *QueryStringQuery {
|
||||
return &QueryStringQuery{
|
||||
func NewQueryStringQuery(query string) *queryStringQuery {
|
||||
return &queryStringQuery{
|
||||
Query: query,
|
||||
BoostVal: 1.0,
|
||||
}
|
||||
}
|
||||
|
||||
func (q *QueryStringQuery) Boost() float64 {
|
||||
func (q *queryStringQuery) Boost() float64 {
|
||||
return q.BoostVal
|
||||
}
|
||||
|
||||
func (q *QueryStringQuery) SetBoost(b float64) *QueryStringQuery {
|
||||
func (q *queryStringQuery) SetBoost(b float64) Query {
|
||||
q.BoostVal = b
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *QueryStringQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) {
|
||||
func (q *queryStringQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) {
|
||||
newQuery, err := ParseQuerySyntax(q.Query, i.m)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -42,6 +42,14 @@ func (q *QueryStringQuery) Searcher(i *indexImpl, explain bool) (search.Searcher
|
|||
return newQuery.Searcher(i, explain)
|
||||
}
|
||||
|
||||
func (q *QueryStringQuery) Validate() error {
|
||||
func (q *queryStringQuery) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (q *queryStringQuery) Field() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func (q *queryStringQuery) SetField(f string) Query {
|
||||
return q
|
||||
}
|
||||
|
|
|
@ -23,37 +23,38 @@ a = make([]family, 1)
|
|||
{
|
||||
var acc [18]bool
|
||||
var fun [18]func(rune) int
|
||||
acc[5] = true
|
||||
fun[5] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 110: return 2
|
||||
case 116: return 2
|
||||
case 117: return 2
|
||||
case 47: return 2
|
||||
case 92: return 3
|
||||
case 34: return 4
|
||||
case 98: return 2
|
||||
case 102: return 2
|
||||
case 114: return 2
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return 2
|
||||
case 65 <= r && r <= 70: return 2
|
||||
case 97 <= r && r <= 102: return 2
|
||||
default: return 2
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[10] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 47: return 2
|
||||
case 102: return 2
|
||||
case 92: return 4
|
||||
case 117: return 2
|
||||
case 34: return 3
|
||||
case 114: return 2
|
||||
case 116: return 2
|
||||
case 92: return 3
|
||||
case 34: return 4
|
||||
case 98: return 2
|
||||
case 110: return 2
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return 2
|
||||
case 65 <= r && r <= 70: return 2
|
||||
case 97 <= r && r <= 102: return 2
|
||||
default: return 2
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[9] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 102: return 2
|
||||
case 92: return 4
|
||||
case 117: return 2
|
||||
case 34: return 3
|
||||
case 114: return 2
|
||||
case 116: return 2
|
||||
case 98: return 2
|
||||
case 110: return 2
|
||||
case 116: return 2
|
||||
case 117: return 2
|
||||
case 47: return 2
|
||||
default:
|
||||
switch {
|
||||
|
@ -65,38 +66,39 @@ fun[9] = func(r rune) int {
|
|||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
acc[4] = true
|
||||
fun[4] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 34: return 5
|
||||
case 114: return 6
|
||||
case 116: return 7
|
||||
case 98: return 8
|
||||
case 110: return 9
|
||||
case 47: return 10
|
||||
case 102: return 11
|
||||
case 92: return 12
|
||||
case 117: return 13
|
||||
case 110: return -1
|
||||
case 116: return -1
|
||||
case 117: return -1
|
||||
case 47: return -1
|
||||
case 92: return -1
|
||||
case 34: return -1
|
||||
case 98: return -1
|
||||
case 102: return -1
|
||||
case 114: return -1
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return 2
|
||||
case 65 <= r && r <= 70: return 2
|
||||
case 97 <= r && r <= 102: return 2
|
||||
default: return 2
|
||||
case 48 <= r && r <= 57: return -1
|
||||
case 65 <= r && r <= 70: return -1
|
||||
case 97 <= r && r <= 102: return -1
|
||||
default: return -1
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[12] = func(r rune) int {
|
||||
fun[17] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 47: return 10
|
||||
case 102: return 11
|
||||
case 92: return 12
|
||||
case 117: return 13
|
||||
case 34: return 5
|
||||
case 114: return 6
|
||||
case 116: return 7
|
||||
case 98: return 8
|
||||
case 110: return 9
|
||||
case 102: return 2
|
||||
case 114: return 2
|
||||
case 110: return 2
|
||||
case 116: return 2
|
||||
case 117: return 2
|
||||
case 47: return 2
|
||||
case 92: return 3
|
||||
case 34: return 4
|
||||
case 98: return 2
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return 2
|
||||
|
@ -109,36 +111,36 @@ fun[12] = func(r rune) int {
|
|||
}
|
||||
fun[13] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 110: return 2
|
||||
case 47: return 2
|
||||
case 102: return 14
|
||||
case 92: return 4
|
||||
case 117: return 2
|
||||
case 34: return 3
|
||||
case 114: return 2
|
||||
case 116: return 2
|
||||
case 98: return 14
|
||||
case 98: return 6
|
||||
case 102: return 7
|
||||
case 114: return 8
|
||||
case 110: return 9
|
||||
case 116: return 10
|
||||
case 117: return 11
|
||||
case 47: return 12
|
||||
case 92: return 13
|
||||
case 34: return 5
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return 14
|
||||
case 65 <= r && r <= 70: return 14
|
||||
case 97 <= r && r <= 102: return 14
|
||||
case 48 <= r && r <= 57: return 2
|
||||
case 65 <= r && r <= 70: return 2
|
||||
case 97 <= r && r <= 102: return 2
|
||||
default: return 2
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[17] = func(r rune) int {
|
||||
fun[2] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 92: return 4
|
||||
case 117: return 2
|
||||
case 34: return 3
|
||||
case 114: return 2
|
||||
case 116: return 2
|
||||
case 98: return 2
|
||||
case 110: return 2
|
||||
case 47: return 2
|
||||
case 102: return 2
|
||||
case 114: return 2
|
||||
case 110: return 2
|
||||
case 116: return 2
|
||||
case 117: return 2
|
||||
case 47: return 2
|
||||
case 92: return 3
|
||||
case 34: return 4
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return 2
|
||||
|
@ -151,15 +153,15 @@ fun[17] = func(r rune) int {
|
|||
}
|
||||
fun[16] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 92: return 4
|
||||
case 117: return 2
|
||||
case 34: return 3
|
||||
case 114: return 2
|
||||
case 116: return 2
|
||||
case 98: return 17
|
||||
case 110: return 2
|
||||
case 47: return 2
|
||||
case 92: return 3
|
||||
case 34: return 4
|
||||
case 98: return 17
|
||||
case 102: return 17
|
||||
case 114: return 2
|
||||
case 110: return 2
|
||||
case 116: return 2
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return 17
|
||||
|
@ -170,17 +172,164 @@ fun[16] = func(r rune) int {
|
|||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[2] = func(r rune) int {
|
||||
fun[11] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 34: return 3
|
||||
case 114: return 2
|
||||
case 116: return 2
|
||||
case 98: return 2
|
||||
case 110: return 2
|
||||
case 47: return 2
|
||||
case 102: return 2
|
||||
case 92: return 4
|
||||
case 117: return 2
|
||||
case 47: return 2
|
||||
case 92: return 3
|
||||
case 34: return 4
|
||||
case 98: return 14
|
||||
case 102: return 14
|
||||
case 114: return 2
|
||||
case 110: return 2
|
||||
case 116: return 2
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return 14
|
||||
case 65 <= r && r <= 70: return 14
|
||||
case 97 <= r && r <= 102: return 14
|
||||
default: return 2
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[15] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 110: return 2
|
||||
case 116: return 2
|
||||
case 117: return 2
|
||||
case 47: return 2
|
||||
case 92: return 3
|
||||
case 34: return 4
|
||||
case 98: return 16
|
||||
case 102: return 16
|
||||
case 114: return 2
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return 16
|
||||
case 65 <= r && r <= 70: return 16
|
||||
case 97 <= r && r <= 102: return 16
|
||||
default: return 2
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[0] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 117: return -1
|
||||
case 47: return -1
|
||||
case 92: return -1
|
||||
case 34: return 1
|
||||
case 98: return -1
|
||||
case 102: return -1
|
||||
case 114: return -1
|
||||
case 110: return -1
|
||||
case 116: return -1
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return -1
|
||||
case 65 <= r && r <= 70: return -1
|
||||
case 97 <= r && r <= 102: return -1
|
||||
default: return -1
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[12] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 110: return 2
|
||||
case 116: return 2
|
||||
case 117: return 2
|
||||
case 47: return 2
|
||||
case 92: return 3
|
||||
case 34: return 4
|
||||
case 98: return 2
|
||||
case 102: return 2
|
||||
case 114: return 2
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return 2
|
||||
case 65 <= r && r <= 70: return 2
|
||||
case 97 <= r && r <= 102: return 2
|
||||
default: return 2
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[6] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 110: return 2
|
||||
case 116: return 2
|
||||
case 117: return 2
|
||||
case 47: return 2
|
||||
case 92: return 3
|
||||
case 34: return 4
|
||||
case 98: return 2
|
||||
case 102: return 2
|
||||
case 114: return 2
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return 2
|
||||
case 65 <= r && r <= 70: return 2
|
||||
case 97 <= r && r <= 102: return 2
|
||||
default: return 2
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[1] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 110: return 2
|
||||
case 116: return 2
|
||||
case 117: return 2
|
||||
case 47: return 2
|
||||
case 92: return 3
|
||||
case 34: return 4
|
||||
case 98: return 2
|
||||
case 102: return 2
|
||||
case 114: return 2
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return 2
|
||||
case 65 <= r && r <= 70: return 2
|
||||
case 97 <= r && r <= 102: return 2
|
||||
default: return 2
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[3] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 34: return 5
|
||||
case 98: return 6
|
||||
case 102: return 7
|
||||
case 114: return 8
|
||||
case 110: return 9
|
||||
case 116: return 10
|
||||
case 117: return 11
|
||||
case 47: return 12
|
||||
case 92: return 13
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return 2
|
||||
case 65 <= r && r <= 70: return 2
|
||||
case 97 <= r && r <= 102: return 2
|
||||
default: return 2
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[7] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 117: return 2
|
||||
case 47: return 2
|
||||
case 92: return 3
|
||||
case 34: return 4
|
||||
case 98: return 2
|
||||
case 102: return 2
|
||||
case 114: return 2
|
||||
case 110: return 2
|
||||
case 116: return 2
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return 2
|
||||
|
@ -194,14 +343,14 @@ fun[2] = func(r rune) int {
|
|||
fun[14] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 110: return 2
|
||||
case 47: return 2
|
||||
case 102: return 15
|
||||
case 92: return 4
|
||||
case 117: return 2
|
||||
case 34: return 3
|
||||
case 114: return 2
|
||||
case 116: return 2
|
||||
case 117: return 2
|
||||
case 47: return 2
|
||||
case 92: return 3
|
||||
case 34: return 4
|
||||
case 98: return 15
|
||||
case 102: return 15
|
||||
case 114: return 2
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return 15
|
||||
|
@ -212,59 +361,17 @@ fun[14] = func(r rune) int {
|
|||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[7] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 92: return 4
|
||||
case 117: return 2
|
||||
case 34: return 3
|
||||
case 114: return 2
|
||||
case 116: return 2
|
||||
case 98: return 2
|
||||
case 110: return 2
|
||||
case 47: return 2
|
||||
case 102: return 2
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return 2
|
||||
case 65 <= r && r <= 70: return 2
|
||||
case 97 <= r && r <= 102: return 2
|
||||
default: return 2
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[11] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 92: return 4
|
||||
case 117: return 2
|
||||
case 34: return 3
|
||||
case 114: return 2
|
||||
case 116: return 2
|
||||
case 98: return 2
|
||||
case 110: return 2
|
||||
case 47: return 2
|
||||
case 102: return 2
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return 2
|
||||
case 65 <= r && r <= 70: return 2
|
||||
case 97 <= r && r <= 102: return 2
|
||||
default: return 2
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[8] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 92: return 4
|
||||
case 117: return 2
|
||||
case 34: return 3
|
||||
case 114: return 2
|
||||
case 116: return 2
|
||||
case 98: return 2
|
||||
case 110: return 2
|
||||
case 47: return 2
|
||||
case 102: return 2
|
||||
case 114: return 2
|
||||
case 110: return 2
|
||||
case 116: return 2
|
||||
case 117: return 2
|
||||
case 47: return 2
|
||||
case 92: return 3
|
||||
case 34: return 4
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return 2
|
||||
|
@ -275,38 +382,17 @@ fun[8] = func(r rune) int {
|
|||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[15] = func(r rune) int {
|
||||
fun[9] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 34: return 3
|
||||
case 114: return 2
|
||||
case 116: return 2
|
||||
case 98: return 16
|
||||
case 110: return 2
|
||||
case 47: return 2
|
||||
case 102: return 16
|
||||
case 92: return 4
|
||||
case 117: return 2
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return 16
|
||||
case 65 <= r && r <= 70: return 16
|
||||
case 97 <= r && r <= 102: return 16
|
||||
default: return 2
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[6] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 110: return 2
|
||||
case 47: return 2
|
||||
case 102: return 2
|
||||
case 92: return 4
|
||||
case 117: return 2
|
||||
case 34: return 3
|
||||
case 114: return 2
|
||||
case 116: return 2
|
||||
case 98: return 2
|
||||
case 102: return 2
|
||||
case 114: return 2
|
||||
case 110: return 2
|
||||
case 116: return 2
|
||||
case 117: return 2
|
||||
case 47: return 2
|
||||
case 92: return 3
|
||||
case 34: return 4
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return 2
|
||||
|
@ -317,92 +403,6 @@ fun[6] = func(r rune) int {
|
|||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
acc[3] = true
|
||||
fun[3] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 114: return -1
|
||||
case 116: return -1
|
||||
case 98: return -1
|
||||
case 110: return -1
|
||||
case 47: return -1
|
||||
case 102: return -1
|
||||
case 92: return -1
|
||||
case 117: return -1
|
||||
case 34: return -1
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return -1
|
||||
case 65 <= r && r <= 70: return -1
|
||||
case 97 <= r && r <= 102: return -1
|
||||
default: return -1
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
acc[5] = true
|
||||
fun[5] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 110: return 2
|
||||
case 47: return 2
|
||||
case 102: return 2
|
||||
case 92: return 4
|
||||
case 117: return 2
|
||||
case 34: return 3
|
||||
case 114: return 2
|
||||
case 116: return 2
|
||||
case 98: return 2
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return 2
|
||||
case 65 <= r && r <= 70: return 2
|
||||
case 97 <= r && r <= 102: return 2
|
||||
default: return 2
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[1] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 117: return 2
|
||||
case 34: return 3
|
||||
case 114: return 2
|
||||
case 116: return 2
|
||||
case 98: return 2
|
||||
case 110: return 2
|
||||
case 47: return 2
|
||||
case 102: return 2
|
||||
case 92: return 4
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return 2
|
||||
case 65 <= r && r <= 70: return 2
|
||||
case 97 <= r && r <= 102: return 2
|
||||
default: return 2
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[0] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 110: return -1
|
||||
case 47: return -1
|
||||
case 102: return -1
|
||||
case 92: return -1
|
||||
case 117: return -1
|
||||
case 34: return 1
|
||||
case 114: return -1
|
||||
case 116: return -1
|
||||
case 98: return -1
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return -1
|
||||
case 65 <= r && r <= 70: return -1
|
||||
case 97 <= r && r <= 102: return -1
|
||||
default: return -1
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
a0[0].acc = acc[:]
|
||||
a0[0].f = fun[:]
|
||||
a0[0].id = 0
|
||||
|
@ -410,9 +410,10 @@ a0[0].id = 0
|
|||
{
|
||||
var acc [2]bool
|
||||
var fun [2]func(rune) int
|
||||
fun[0] = func(r rune) int {
|
||||
acc[1] = true
|
||||
fun[1] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 43: return 1
|
||||
case 43: return -1
|
||||
default:
|
||||
switch {
|
||||
default: return -1
|
||||
|
@ -420,10 +421,9 @@ fun[0] = func(r rune) int {
|
|||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
acc[1] = true
|
||||
fun[1] = func(r rune) int {
|
||||
fun[0] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 43: return -1
|
||||
case 43: return 1
|
||||
default:
|
||||
switch {
|
||||
default: return -1
|
||||
|
@ -466,9 +466,10 @@ a0[2].id = 2
|
|||
{
|
||||
var acc [2]bool
|
||||
var fun [2]func(rune) int
|
||||
fun[0] = func(r rune) int {
|
||||
acc[1] = true
|
||||
fun[1] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 58: return 1
|
||||
case 58: return -1
|
||||
default:
|
||||
switch {
|
||||
default: return -1
|
||||
|
@ -476,10 +477,9 @@ fun[0] = func(r rune) int {
|
|||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
acc[1] = true
|
||||
fun[1] = func(r rune) int {
|
||||
fun[0] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 58: return -1
|
||||
case 58: return 1
|
||||
default:
|
||||
switch {
|
||||
default: return -1
|
||||
|
@ -550,9 +550,10 @@ a0[5].id = 5
|
|||
{
|
||||
var acc [2]bool
|
||||
var fun [2]func(rune) int
|
||||
fun[0] = func(r rune) int {
|
||||
acc[1] = true
|
||||
fun[1] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 41: return 1
|
||||
case 41: return -1
|
||||
default:
|
||||
switch {
|
||||
default: return -1
|
||||
|
@ -560,10 +561,9 @@ fun[0] = func(r rune) int {
|
|||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
acc[1] = true
|
||||
fun[1] = func(r rune) int {
|
||||
fun[0] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 41: return -1
|
||||
case 41: return 1
|
||||
default:
|
||||
switch {
|
||||
default: return -1
|
||||
|
@ -578,10 +578,9 @@ a0[6].id = 6
|
|||
{
|
||||
var acc [2]bool
|
||||
var fun [2]func(rune) int
|
||||
acc[1] = true
|
||||
fun[1] = func(r rune) int {
|
||||
fun[0] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 62: return -1
|
||||
case 62: return 1
|
||||
default:
|
||||
switch {
|
||||
default: return -1
|
||||
|
@ -589,9 +588,10 @@ fun[1] = func(r rune) int {
|
|||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[0] = func(r rune) int {
|
||||
acc[1] = true
|
||||
fun[1] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 62: return 1
|
||||
case 62: return -1
|
||||
default:
|
||||
switch {
|
||||
default: return -1
|
||||
|
@ -606,10 +606,9 @@ a0[7].id = 7
|
|||
{
|
||||
var acc [2]bool
|
||||
var fun [2]func(rune) int
|
||||
acc[1] = true
|
||||
fun[1] = func(r rune) int {
|
||||
fun[0] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 60: return -1
|
||||
case 60: return 1
|
||||
default:
|
||||
switch {
|
||||
default: return -1
|
||||
|
@ -617,9 +616,10 @@ fun[1] = func(r rune) int {
|
|||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[0] = func(r rune) int {
|
||||
acc[1] = true
|
||||
fun[1] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 60: return 1
|
||||
case 60: return -1
|
||||
default:
|
||||
switch {
|
||||
default: return -1
|
||||
|
@ -662,48 +662,8 @@ a0[9].id = 9
|
|||
{
|
||||
var acc [8]bool
|
||||
var fun [8]func(rune) int
|
||||
acc[2] = true
|
||||
fun[2] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 46: return 4
|
||||
case 45: return -1
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 48: return -1
|
||||
case 49 <= r && r <= 57: return -1
|
||||
default: return -1
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[4] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 45: return -1
|
||||
case 46: return -1
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 48: return 6
|
||||
case 49 <= r && r <= 57: return 6
|
||||
default: return -1
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[1] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 46: return -1
|
||||
case 45: return -1
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 48: return 2
|
||||
case 49 <= r && r <= 57: return 3
|
||||
default: return -1
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
acc[3] = true
|
||||
fun[3] = func(r rune) int {
|
||||
acc[5] = true
|
||||
fun[5] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 46: return 4
|
||||
case 45: return -1
|
||||
|
@ -716,8 +676,8 @@ fun[3] = func(r rune) int {
|
|||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
acc[6] = true
|
||||
fun[6] = func(r rune) int {
|
||||
acc[7] = true
|
||||
fun[7] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 46: return -1
|
||||
case 45: return -1
|
||||
|
@ -743,8 +703,8 @@ fun[0] = func(r rune) int {
|
|||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
acc[7] = true
|
||||
fun[7] = func(r rune) int {
|
||||
acc[6] = true
|
||||
fun[6] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 46: return -1
|
||||
case 45: return -1
|
||||
|
@ -757,8 +717,8 @@ fun[7] = func(r rune) int {
|
|||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
acc[5] = true
|
||||
fun[5] = func(r rune) int {
|
||||
acc[3] = true
|
||||
fun[3] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 46: return 4
|
||||
case 45: return -1
|
||||
|
@ -771,6 +731,46 @@ fun[5] = func(r rune) int {
|
|||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[1] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 46: return -1
|
||||
case 45: return -1
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 48: return 2
|
||||
case 49 <= r && r <= 57: return 3
|
||||
default: return -1
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[4] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 46: return -1
|
||||
case 45: return -1
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 48: return 6
|
||||
case 49 <= r && r <= 57: return 6
|
||||
default: return -1
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
acc[2] = true
|
||||
fun[2] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 46: return 4
|
||||
case 45: return -1
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 48: return -1
|
||||
case 49 <= r && r <= 57: return -1
|
||||
default: return -1
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
a0[10].acc = acc[:]
|
||||
a0[10].f = fun[:]
|
||||
a0[10].id = 10
|
||||
|
@ -793,9 +793,9 @@ fun[0] = func(r rune) int {
|
|||
acc[1] = true
|
||||
fun[1] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 32: return 1
|
||||
case 10: return 1
|
||||
case 9: return 1
|
||||
case 32: return 1
|
||||
default:
|
||||
switch {
|
||||
default: return -1
|
||||
|
@ -810,21 +810,20 @@ a0[11].id = 11
|
|||
{
|
||||
var acc [2]bool
|
||||
var fun [2]func(rune) int
|
||||
acc[1] = true
|
||||
fun[1] = func(r rune) int {
|
||||
fun[0] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 9: return -1
|
||||
case 45: return -1
|
||||
case 12: return -1
|
||||
case 60: return -1
|
||||
case 13: return -1
|
||||
case 12: return -1
|
||||
case 32: return -1
|
||||
case 94: return -1
|
||||
case 43: return -1
|
||||
case 9: return -1
|
||||
case 58: return -1
|
||||
case 10: return -1
|
||||
case 45: return -1
|
||||
case 61: return -1
|
||||
case 58: return -1
|
||||
case 62: return -1
|
||||
case 32: return -1
|
||||
case 43: return -1
|
||||
case 10: return -1
|
||||
case 94: return -1
|
||||
default:
|
||||
switch {
|
||||
default: return 1
|
||||
|
@ -832,20 +831,21 @@ fun[1] = func(r rune) int {
|
|||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[0] = func(r rune) int {
|
||||
acc[1] = true
|
||||
fun[1] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 13: return -1
|
||||
case 12: return -1
|
||||
case 32: return -1
|
||||
case 94: return -1
|
||||
case 43: return -1
|
||||
case 9: return -1
|
||||
case 58: return -1
|
||||
case 10: return -1
|
||||
case 45: return -1
|
||||
case 61: return -1
|
||||
case 62: return -1
|
||||
case 32: return -1
|
||||
case 43: return -1
|
||||
case 10: return -1
|
||||
case 94: return -1
|
||||
case 9: return -1
|
||||
case 45: return -1
|
||||
case 12: return -1
|
||||
case 60: return -1
|
||||
case 13: return -1
|
||||
case 61: return -1
|
||||
default:
|
||||
switch {
|
||||
default: return 1
|
||||
|
|
|
@ -130,12 +130,7 @@ searchBoost:
|
|||
tBOOST tNUMBER {
|
||||
boost := $2.f
|
||||
if parsingLastQuery != nil {
|
||||
switch parsingLastQuery := parsingLastQuery.(type) {
|
||||
case *MatchQuery:
|
||||
parsingLastQuery.SetBoost(boost)
|
||||
case *MatchPhraseQuery:
|
||||
parsingLastQuery.SetBoost(boost)
|
||||
}
|
||||
parsingLastQuery.SetBoost(boost)
|
||||
}
|
||||
logDebugGrammar("BOOST %f", boost)
|
||||
};
|
||||
|
|
|
@ -13,38 +13,38 @@ import (
|
|||
"github.com/blevesearch/bleve/search"
|
||||
)
|
||||
|
||||
type TermQuery struct {
|
||||
type termQuery struct {
|
||||
Term string `json:"term"`
|
||||
FieldVal string `json:"field,omitempty"`
|
||||
BoostVal float64 `json:"boost,omitempty"`
|
||||
}
|
||||
|
||||
func NewTermQuery(term string) *TermQuery {
|
||||
return &TermQuery{
|
||||
func NewTermQuery(term string) *termQuery {
|
||||
return &termQuery{
|
||||
Term: term,
|
||||
BoostVal: 1.0,
|
||||
}
|
||||
}
|
||||
|
||||
func (q *TermQuery) Boost() float64 {
|
||||
func (q *termQuery) Boost() float64 {
|
||||
return q.BoostVal
|
||||
}
|
||||
|
||||
func (q *TermQuery) SetBoost(b float64) *TermQuery {
|
||||
func (q *termQuery) SetBoost(b float64) Query {
|
||||
q.BoostVal = b
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *TermQuery) Field() string {
|
||||
func (q *termQuery) Field() string {
|
||||
return q.FieldVal
|
||||
}
|
||||
|
||||
func (q *TermQuery) SetField(f string) *TermQuery {
|
||||
func (q *termQuery) SetField(f string) Query {
|
||||
q.FieldVal = f
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *TermQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) {
|
||||
func (q *termQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error) {
|
||||
field := q.FieldVal
|
||||
if q.FieldVal == "" {
|
||||
field = i.m.DefaultField
|
||||
|
@ -52,6 +52,6 @@ func (q *TermQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, error
|
|||
return search.NewTermSearcher(i.i, q.Term, field, q.BoostVal, explain)
|
||||
}
|
||||
|
||||
func (q *TermQuery) Validate() error {
|
||||
func (q *termQuery) Validate() error {
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -38,17 +38,15 @@ func TestParseQuery(t *testing.T) {
|
|||
output: NewMatchPhraseQuery("light beer").SetField("desc"),
|
||||
},
|
||||
{
|
||||
input: []byte(`{"must":{"terms": [{"match":"beer","field":"desc"}]},"should":{"terms": [{"match":"water","field":"desc"}],"min":1.0},"must_not":{"terms": [{"match":"devon","field":"desc"}]}}`),
|
||||
input: []byte(`{"must":{"conjuncts": [{"match":"beer","field":"desc"}]},"should":{"disjuncts": [{"match":"water","field":"desc"}],"min":1.0},"must_not":{"disjuncts": [{"match":"devon","field":"desc"}]}}`),
|
||||
output: NewBooleanQuery(
|
||||
[]Query{NewMatchQuery("beer").SetField("desc")},
|
||||
[]Query{NewMatchQuery("water").SetField("desc")},
|
||||
[]Query{NewMatchQuery("devon").SetField("desc")}),
|
||||
},
|
||||
{
|
||||
input: []byte(`{"terms":[{"term":"watered","field":"desc"},{"term":"down","field":"desc"}]}`),
|
||||
output: NewPhraseQuery([]*TermQuery{
|
||||
NewTermQuery("watered").SetField("desc"),
|
||||
NewTermQuery("down").SetField("desc")}),
|
||||
input: []byte(`{"terms":[{"term":"watered","field":"desc"},{"term":"down","field":"desc"}]}`),
|
||||
output: NewPhraseQuery([]string{"watered", "down"}, "desc"),
|
||||
},
|
||||
{
|
||||
input: []byte(`{"query":"+beer \"light beer\" -devon"}`),
|
||||
|
@ -73,10 +71,10 @@ func TestParseQuery(t *testing.T) {
|
|||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
for i, test := range tests {
|
||||
actual, err := ParseQuery(test.input)
|
||||
if err != nil && test.err == nil {
|
||||
t.Error(err)
|
||||
t.Errorf("error %v for %d", err, i)
|
||||
} else if test.err != nil {
|
||||
if !reflect.DeepEqual(err, test.err) {
|
||||
t.Errorf("expected error: %#v, got: %#v", test.err, err)
|
||||
|
@ -122,31 +120,9 @@ func TestSetGetField(t *testing.T) {
|
|||
}
|
||||
|
||||
for _, test := range tests {
|
||||
switch query := test.query.(type) {
|
||||
case *TermQuery:
|
||||
if query.Field() != test.field {
|
||||
t.Errorf("expected field '%s', got '%s'", test.field, query.Field())
|
||||
}
|
||||
case *MatchQuery:
|
||||
if query.Field() != test.field {
|
||||
t.Errorf("expected field '%s', got '%s'", test.field, query.Field())
|
||||
}
|
||||
case *MatchPhraseQuery:
|
||||
if query.Field() != test.field {
|
||||
t.Errorf("expected field '%s', got '%s'", test.field, query.Field())
|
||||
}
|
||||
case *NumericRangeQuery:
|
||||
if query.Field() != test.field {
|
||||
t.Errorf("expected field '%s', got '%s'", test.field, query.Field())
|
||||
}
|
||||
case *DateRangeQuery:
|
||||
if query.Field() != test.field {
|
||||
t.Errorf("expected field '%s', got '%s'", test.field, query.Field())
|
||||
}
|
||||
case *PrefixQuery:
|
||||
if query.Field() != test.field {
|
||||
t.Errorf("expected field '%s', got '%s'", test.field, query.Field())
|
||||
}
|
||||
query := test.query
|
||||
if query.Field() != test.field {
|
||||
t.Errorf("expected field '%s', got '%s'", test.field, query.Field())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -189,13 +165,11 @@ func TestQueryValidate(t *testing.T) {
|
|||
err: nil,
|
||||
},
|
||||
{
|
||||
query: NewPhraseQuery([]*TermQuery{
|
||||
NewTermQuery("watered").SetField("desc"),
|
||||
NewTermQuery("down").SetField("desc")}),
|
||||
err: nil,
|
||||
query: NewPhraseQuery([]string{"watered", "down"}, "desc"),
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
query: NewPhraseQuery([]*TermQuery{}),
|
||||
query: NewPhraseQuery([]string{}, "field"),
|
||||
err: ERROR_PHRASE_QUERY_NO_TERMS,
|
||||
},
|
||||
{
|
||||
|
|
|
@ -59,4 +59,5 @@ type Searcher interface {
|
|||
Weight() float64
|
||||
SetQueryNorm(float64)
|
||||
Count() uint64
|
||||
Min() int
|
||||
}
|
||||
|
|
|
@ -17,9 +17,9 @@ import (
|
|||
type BooleanSearcher struct {
|
||||
initialized bool
|
||||
index index.Index
|
||||
mustSearcher *ConjunctionSearcher
|
||||
shouldSearcher *DisjunctionSearcher
|
||||
mustNotSearcher *DisjunctionSearcher
|
||||
mustSearcher Searcher
|
||||
shouldSearcher Searcher
|
||||
mustNotSearcher Searcher
|
||||
queryNorm float64
|
||||
currMust *DocumentMatch
|
||||
currShould *DocumentMatch
|
||||
|
@ -29,7 +29,7 @@ type BooleanSearcher struct {
|
|||
scorer *ConjunctionQueryScorer
|
||||
}
|
||||
|
||||
func NewBooleanSearcher(index index.Index, mustSearcher *ConjunctionSearcher, shouldSearcher *DisjunctionSearcher, mustNotSearcher *DisjunctionSearcher, explain bool) (*BooleanSearcher, error) {
|
||||
func NewBooleanSearcher(index index.Index, mustSearcher Searcher, shouldSearcher Searcher, mustNotSearcher Searcher, explain bool) (*BooleanSearcher, error) {
|
||||
// build our searcher
|
||||
rv := BooleanSearcher{
|
||||
index: index,
|
||||
|
@ -191,7 +191,7 @@ func (s *BooleanSearcher) Next() (*DocumentMatch, error) {
|
|||
rv = s.scorer.Score(cons)
|
||||
s.advanceNextMust()
|
||||
break
|
||||
} else if s.shouldSearcher.min == 0 {
|
||||
} else if s.shouldSearcher.Min() == 0 {
|
||||
// match is OK anyway
|
||||
rv = s.scorer.Score([]*DocumentMatch{s.currMust})
|
||||
s.advanceNextMust()
|
||||
|
@ -207,7 +207,7 @@ func (s *BooleanSearcher) Next() (*DocumentMatch, error) {
|
|||
rv = s.scorer.Score(cons)
|
||||
s.advanceNextMust()
|
||||
break
|
||||
} else if s.shouldSearcher == nil || s.shouldSearcher.min == 0 {
|
||||
} else if s.shouldSearcher == nil || s.shouldSearcher.Min() == 0 {
|
||||
// match is OK anyway
|
||||
rv = s.scorer.Score([]*DocumentMatch{s.currMust})
|
||||
s.advanceNextMust()
|
||||
|
@ -283,3 +283,7 @@ func (s *BooleanSearcher) Close() {
|
|||
s.mustNotSearcher.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *BooleanSearcher) Min() int {
|
||||
return 0
|
||||
}
|
||||
|
|
|
@ -180,3 +180,7 @@ func (s *ConjunctionSearcher) Close() {
|
|||
searcher.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ConjunctionSearcher) Min() int {
|
||||
return 0
|
||||
}
|
||||
|
|
|
@ -176,3 +176,7 @@ func (s *DisjunctionSearcher) Close() {
|
|||
searcher.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *DisjunctionSearcher) Min() int {
|
||||
return int(s.min) // FIXME just make this an int
|
||||
}
|
||||
|
|
|
@ -80,3 +80,7 @@ func (s *MatchAllSearcher) Advance(ID string) (*DocumentMatch, error) {
|
|||
func (s *MatchAllSearcher) Close() {
|
||||
s.reader.Close()
|
||||
}
|
||||
|
||||
func (s *MatchAllSearcher) Min() int {
|
||||
return 0
|
||||
}
|
||||
|
|
|
@ -44,3 +44,7 @@ func (s *MatchNoneSearcher) Advance(ID string) (*DocumentMatch, error) {
|
|||
|
||||
func (s *MatchNoneSearcher) Close() {
|
||||
}
|
||||
|
||||
func (s *MatchNoneSearcher) Min() int {
|
||||
return 0
|
||||
}
|
||||
|
|
|
@ -206,3 +206,7 @@ func newRangeBytes(minBytes, maxBytes []byte) *termRange {
|
|||
endTerm: maxBytes,
|
||||
}
|
||||
}
|
||||
|
||||
func (s *NumericRangeSearcher) Min() int {
|
||||
return 0
|
||||
}
|
||||
|
|
|
@ -176,3 +176,7 @@ func (s *PhraseSearcher) Close() {
|
|||
s.mustSearcher.Close()
|
||||
}
|
||||
}
|
||||
|
||||
func (s *PhraseSearcher) Min() int {
|
||||
return 0
|
||||
}
|
||||
|
|
|
@ -86,3 +86,7 @@ func (s *TermSearcher) Advance(ID string) (*DocumentMatch, error) {
|
|||
func (s *TermSearcher) Close() {
|
||||
s.reader.Close()
|
||||
}
|
||||
|
||||
func (s *TermSearcher) Min() int {
|
||||
return 0
|
||||
}
|
||||
|
|
|
@ -73,3 +73,7 @@ func (s *TermPrefixSearcher) Advance(ID string) (*DocumentMatch, error) {
|
|||
func (s *TermPrefixSearcher) Close() {
|
||||
s.searcher.Close()
|
||||
}
|
||||
|
||||
func (s *TermPrefixSearcher) Min() int {
|
||||
return 0
|
||||
}
|
||||
|
|
11
y.go
11
y.go
|
@ -466,22 +466,17 @@ yydefault:
|
|||
{
|
||||
boost := yyS[yypt-0].f
|
||||
if parsingLastQuery != nil {
|
||||
switch parsingLastQuery := parsingLastQuery.(type) {
|
||||
case *MatchQuery:
|
||||
parsingLastQuery.SetBoost(boost)
|
||||
case *MatchPhraseQuery:
|
||||
parsingLastQuery.SetBoost(boost)
|
||||
}
|
||||
parsingLastQuery.SetBoost(boost)
|
||||
}
|
||||
logDebugGrammar("BOOST %f", boost)
|
||||
}
|
||||
case 18:
|
||||
//line query_string.y:144
|
||||
//line query_string.y:139
|
||||
{
|
||||
|
||||
}
|
||||
case 19:
|
||||
//line query_string.y:148
|
||||
//line query_string.y:143
|
||||
{
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue