renamed SyntaxQuery QueryStringQuery
also made IndexMeta private
This commit is contained in:
parent
635ae2b401
commit
7313e7247e
|
@ -81,7 +81,7 @@ func TestBeerSearchAll(t *testing.T) {
|
|||
}
|
||||
|
||||
// run a syntax query
|
||||
syntaxQuery := bleve.NewSyntaxQuery("+name:light +description:water -description:barley")
|
||||
syntaxQuery := bleve.NewQueryStringQuery("+name:light +description:water -description:barley")
|
||||
syntaxSearchRequest := bleve.NewSearchRequest(syntaxQuery)
|
||||
syntaxSearchResult, err := index.Search(syntaxSearchRequest)
|
||||
if err != nil {
|
||||
|
|
|
@ -45,7 +45,7 @@ func main() {
|
|||
|
||||
// build a search with the provided parameters
|
||||
queryString := strings.Join(flag.Args(), " ")
|
||||
query := bleve.NewSyntaxQuery(queryString)
|
||||
query := bleve.NewQueryStringQuery(queryString)
|
||||
searchRequest := bleve.NewSearchRequestOptions(query, *limit, *skip, *explain)
|
||||
|
||||
// enable highlights if requested
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
#! /bin/sh
|
||||
|
||||
echo Running nex...
|
||||
nex query_syntax.nex
|
||||
nex query_string.nex
|
||||
echo Running goyacc...
|
||||
go tool yacc query_syntax.y
|
||||
go tool yacc query_string.y
|
||||
# remove first line which pollutes godocs
|
||||
tail -n +2 y.go > y.go.new
|
||||
mv y.go.new y.go
|
||||
|
|
|
@ -46,7 +46,7 @@ func newMemIndex(mapping *IndexMapping) (*indexImpl, error) {
|
|||
rv := indexImpl{
|
||||
path: "",
|
||||
m: mapping,
|
||||
meta: NewIndexMeta("mem"),
|
||||
meta: newIndexMeta("mem"),
|
||||
}
|
||||
|
||||
storeConstructor := registry.KVStoreConstructorByName(rv.meta.Storage)
|
||||
|
@ -98,7 +98,7 @@ func newIndex(path string, mapping *IndexMapping) (*indexImpl, error) {
|
|||
rv := indexImpl{
|
||||
path: path,
|
||||
m: mapping,
|
||||
meta: NewIndexMeta(Config.DefaultKVStore),
|
||||
meta: newIndexMeta(Config.DefaultKVStore),
|
||||
}
|
||||
storeConstructor := registry.KVStoreConstructorByName(rv.meta.Storage)
|
||||
if storeConstructor == nil {
|
||||
|
@ -151,7 +151,7 @@ func openIndex(path string) (*indexImpl, error) {
|
|||
path: path,
|
||||
}
|
||||
var err error
|
||||
rv.meta, err = OpenIndexMeta(path)
|
||||
rv.meta, err = openIndexMeta(path)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -21,11 +21,11 @@ type indexMeta struct {
|
|||
Storage string `json:"storage"`
|
||||
}
|
||||
|
||||
func NewIndexMeta(storage string) *indexMeta {
|
||||
func newIndexMeta(storage string) *indexMeta {
|
||||
return &indexMeta{Storage: storage}
|
||||
}
|
||||
|
||||
func OpenIndexMeta(path string) (*indexMeta, error) {
|
||||
func openIndexMeta(path string) (*indexMeta, error) {
|
||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
||||
return nil, ERROR_INDEX_PATH_DOES_NOT_EXIST
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ func TestIndexMeta(t *testing.T) {
|
|||
defer os.RemoveAll(testIndexPath)
|
||||
|
||||
// open non-existant meta should error
|
||||
_, err := OpenIndexMeta(testIndexPath)
|
||||
_, err := openIndexMeta(testIndexPath)
|
||||
if err == nil {
|
||||
t.Errorf("expected error, got nil")
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ func TestIndexMeta(t *testing.T) {
|
|||
im = nil
|
||||
|
||||
// open a meta that exists
|
||||
im, err = OpenIndexMeta(testIndexPath)
|
||||
im, err = openIndexMeta(testIndexPath)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
}
|
||||
|
|
2
query.go
2
query.go
|
@ -96,7 +96,7 @@ func ParseQuery(input []byte) (Query, error) {
|
|||
}
|
||||
_, hasSyntaxQuery := tmp["query"]
|
||||
if hasSyntaxQuery {
|
||||
var rv SyntaxQuery
|
||||
var rv QueryStringQuery
|
||||
err := json.Unmarshal(input, &rv)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
|
@ -13,28 +13,28 @@ import (
|
|||
"github.com/blevesearch/bleve/search"
|
||||
)
|
||||
|
||||
type SyntaxQuery struct {
|
||||
type QueryStringQuery struct {
|
||||
Query string `json:"query"`
|
||||
BoostVal float64 `json:"boost,omitempty"`
|
||||
}
|
||||
|
||||
func NewSyntaxQuery(query string) *SyntaxQuery {
|
||||
return &SyntaxQuery{
|
||||
func NewQueryStringQuery(query string) *QueryStringQuery {
|
||||
return &QueryStringQuery{
|
||||
Query: query,
|
||||
BoostVal: 1.0,
|
||||
}
|
||||
}
|
||||
|
||||
func (q *SyntaxQuery) Boost() float64 {
|
||||
func (q *QueryStringQuery) Boost() float64 {
|
||||
return q.BoostVal
|
||||
}
|
||||
|
||||
func (q *SyntaxQuery) SetBoost(b float64) *SyntaxQuery {
|
||||
func (q *QueryStringQuery) SetBoost(b float64) *QueryStringQuery {
|
||||
q.BoostVal = b
|
||||
return q
|
||||
}
|
||||
|
||||
func (q *SyntaxQuery) 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,6 @@ func (q *SyntaxQuery) Searcher(i *indexImpl, explain bool) (search.Searcher, err
|
|||
return newQuery.Searcher(i, explain)
|
||||
}
|
||||
|
||||
func (q *SyntaxQuery) Validate() error {
|
||||
func (q *QueryStringQuery) Validate() error {
|
||||
return nil
|
||||
}
|
|
@ -25,15 +25,15 @@ var acc [18]bool
|
|||
var fun [18]func(rune) int
|
||||
fun[15] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 114: return 2
|
||||
case 98: return 16
|
||||
case 34: return 4
|
||||
case 117: return 2
|
||||
case 116: return 2
|
||||
case 114: return 2
|
||||
case 92: return 3
|
||||
case 116: return 2
|
||||
case 102: return 16
|
||||
case 110: return 2
|
||||
case 34: return 4
|
||||
case 47: return 2
|
||||
case 98: return 16
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return 16
|
||||
|
@ -44,205 +44,15 @@ fun[15] = func(r rune) int {
|
|||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[13] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 47: return 2
|
||||
case 114: return 2
|
||||
case 98: return 14
|
||||
case 34: return 4
|
||||
case 117: return 2
|
||||
case 116: return 2
|
||||
case 92: return 3
|
||||
case 102: return 14
|
||||
case 110: 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[17] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 116: return 2
|
||||
case 92: return 3
|
||||
case 102: return 2
|
||||
case 110: return 2
|
||||
case 47: return 2
|
||||
case 114: return 2
|
||||
case 98: return 2
|
||||
case 34: return 4
|
||||
case 117: 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 34: return 12
|
||||
case 117: return 13
|
||||
case 116: return 5
|
||||
case 92: return 6
|
||||
case 102: return 7
|
||||
case 110: return 8
|
||||
case 47: return 9
|
||||
case 114: return 10
|
||||
case 98: return 11
|
||||
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 116: return 2
|
||||
case 92: return 3
|
||||
case 102: return 2
|
||||
case 110: return 2
|
||||
case 47: return 2
|
||||
case 114: return 2
|
||||
case 98: return 2
|
||||
case 34: return 4
|
||||
case 117: 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 110: return 2
|
||||
case 47: return 2
|
||||
case 114: return 2
|
||||
case 98: return 2
|
||||
case 34: return 4
|
||||
case 117: return 2
|
||||
case 116: return 2
|
||||
case 92: return 3
|
||||
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[0] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 92: return -1
|
||||
case 102: return -1
|
||||
case 110: return -1
|
||||
case 47: return -1
|
||||
case 114: return -1
|
||||
case 98: return -1
|
||||
case 34: return 1
|
||||
case 117: 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[10] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 114: return 2
|
||||
case 98: return 2
|
||||
case 34: return 4
|
||||
case 117: return 2
|
||||
case 116: return 2
|
||||
case 92: return 3
|
||||
case 102: return 2
|
||||
case 110: return 2
|
||||
case 47: 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 116: return 5
|
||||
case 92: return 6
|
||||
case 102: return 7
|
||||
case 110: return 8
|
||||
case 47: return 9
|
||||
case 114: return 10
|
||||
case 98: return 11
|
||||
case 34: return 12
|
||||
case 117: 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")
|
||||
}
|
||||
acc[4] = true
|
||||
fun[4] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 110: return -1
|
||||
case 47: return -1
|
||||
case 114: return -1
|
||||
case 98: return -1
|
||||
case 34: return -1
|
||||
case 117: return -1
|
||||
case 116: return -1
|
||||
case 92: return -1
|
||||
case 102: 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[2] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 47: return 2
|
||||
case 114: return 2
|
||||
case 98: return 2
|
||||
case 34: return 4
|
||||
case 47: return 2
|
||||
case 98: return 2
|
||||
case 117: return 2
|
||||
case 116: return 2
|
||||
case 114: return 2
|
||||
case 92: return 3
|
||||
case 116: return 2
|
||||
case 102: return 2
|
||||
case 110: return 2
|
||||
default:
|
||||
|
@ -255,17 +65,59 @@ fun[2] = func(r rune) int {
|
|||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[7] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 117: return 5
|
||||
case 114: return 6
|
||||
case 92: return 7
|
||||
case 116: return 8
|
||||
case 102: return 9
|
||||
case 110: return 10
|
||||
case 34: return 11
|
||||
case 47: return 12
|
||||
case 98: 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[13] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 117: return 2
|
||||
case 114: return 2
|
||||
case 92: return 3
|
||||
case 116: return 2
|
||||
case 102: return 2
|
||||
case 110: return 2
|
||||
case 34: return 4
|
||||
case 47: 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[16] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 110: return 2
|
||||
case 47: return 2
|
||||
case 114: return 2
|
||||
case 98: return 17
|
||||
case 34: return 4
|
||||
case 117: return 2
|
||||
case 116: return 2
|
||||
case 114: return 2
|
||||
case 92: return 3
|
||||
case 116: return 2
|
||||
case 102: return 17
|
||||
case 110: return 2
|
||||
case 34: return 4
|
||||
case 47: return 2
|
||||
case 98: return 17
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return 17
|
||||
|
@ -276,36 +128,15 @@ fun[16] = func(r rune) int {
|
|||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[7] = func(r rune) int {
|
||||
fun[8] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 110: return 2
|
||||
case 47: return 2
|
||||
case 114: return 2
|
||||
case 98: return 2
|
||||
case 34: return 4
|
||||
case 117: return 2
|
||||
case 116: return 2
|
||||
case 92: return 3
|
||||
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 47: return 2
|
||||
case 114: return 2
|
||||
case 98: return 2
|
||||
case 34: return 4
|
||||
case 117: return 2
|
||||
case 116: return 2
|
||||
case 114: return 2
|
||||
case 92: return 3
|
||||
case 116: return 2
|
||||
case 102: return 2
|
||||
case 110: return 2
|
||||
default:
|
||||
|
@ -318,18 +149,38 @@ fun[11] = func(r rune) int {
|
|||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
acc[12] = true
|
||||
fun[12] = func(r rune) int {
|
||||
fun[0] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 110: return 2
|
||||
case 47: return 2
|
||||
case 114: return 2
|
||||
case 98: return 2
|
||||
case 34: return 4
|
||||
case 117: return 2
|
||||
case 116: return 2
|
||||
case 92: return 3
|
||||
case 102: return 2
|
||||
case 117: return -1
|
||||
case 114: return -1
|
||||
case 92: return -1
|
||||
case 116: return -1
|
||||
case 102: return -1
|
||||
case 110: return -1
|
||||
case 34: return 1
|
||||
case 47: 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")
|
||||
}
|
||||
fun[3] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 117: return 5
|
||||
case 114: return 6
|
||||
case 92: return 7
|
||||
case 116: return 8
|
||||
case 102: return 9
|
||||
case 110: return 10
|
||||
case 34: return 11
|
||||
case 47: return 12
|
||||
case 98: return 13
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return 2
|
||||
|
@ -342,15 +193,15 @@ fun[12] = func(r rune) int {
|
|||
}
|
||||
fun[14] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 110: return 2
|
||||
case 47: return 2
|
||||
case 114: return 2
|
||||
case 98: return 15
|
||||
case 34: return 4
|
||||
case 117: return 2
|
||||
case 116: return 2
|
||||
case 92: return 3
|
||||
case 102: return 15
|
||||
case 110: return 2
|
||||
case 34: return 4
|
||||
case 47: return 2
|
||||
case 98: return 15
|
||||
case 117: return 2
|
||||
case 114: return 2
|
||||
case 92: return 3
|
||||
case 116: return 2
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return 15
|
||||
|
@ -361,17 +212,60 @@ fun[14] = func(r rune) int {
|
|||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
acc[4] = true
|
||||
fun[4] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 102: return -1
|
||||
case 110: return -1
|
||||
case 34: return -1
|
||||
case 47: return -1
|
||||
case 98: return -1
|
||||
case 117: return -1
|
||||
case 114: return -1
|
||||
case 92: 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[5] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 102: return 14
|
||||
case 110: return 2
|
||||
case 47: return 2
|
||||
case 114: return 2
|
||||
case 98: return 2
|
||||
case 34: return 4
|
||||
case 47: return 2
|
||||
case 98: return 14
|
||||
case 117: return 2
|
||||
case 116: return 2
|
||||
case 114: return 2
|
||||
case 92: return 3
|
||||
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[10] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 116: return 2
|
||||
case 102: return 2
|
||||
case 110: return 2
|
||||
case 34: return 4
|
||||
case 47: return 2
|
||||
case 98: return 2
|
||||
case 117: return 2
|
||||
case 114: return 2
|
||||
case 92: return 3
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 57: return 2
|
||||
|
@ -382,16 +276,37 @@ fun[5] = func(r rune) int {
|
|||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[8] = func(r rune) int {
|
||||
fun[6] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 34: return 4
|
||||
case 47: return 2
|
||||
case 98: return 2
|
||||
case 117: return 2
|
||||
case 116: return 2
|
||||
case 114: return 2
|
||||
case 92: return 3
|
||||
case 116: return 2
|
||||
case 102: return 2
|
||||
case 110: return 2
|
||||
case 47: 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 114: return 2
|
||||
case 92: return 3
|
||||
case 116: return 2
|
||||
case 102: return 2
|
||||
case 110: return 2
|
||||
case 34: return 4
|
||||
case 47: return 2
|
||||
case 98: return 2
|
||||
default:
|
||||
switch {
|
||||
|
@ -403,6 +318,91 @@ fun[8] = func(r rune) int {
|
|||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[9] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 117: return 2
|
||||
case 114: return 2
|
||||
case 92: return 3
|
||||
case 116: return 2
|
||||
case 102: return 2
|
||||
case 110: return 2
|
||||
case 34: return 4
|
||||
case 47: 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")
|
||||
}
|
||||
acc[11] = true
|
||||
fun[11] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 34: return 4
|
||||
case 47: return 2
|
||||
case 98: return 2
|
||||
case 117: return 2
|
||||
case 114: return 2
|
||||
case 92: return 3
|
||||
case 116: return 2
|
||||
case 102: 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[17] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 117: return 2
|
||||
case 114: return 2
|
||||
case 92: return 3
|
||||
case 116: return 2
|
||||
case 102: return 2
|
||||
case 110: return 2
|
||||
case 34: return 4
|
||||
case 47: 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[12] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 116: return 2
|
||||
case 102: return 2
|
||||
case 110: return 2
|
||||
case 34: return 4
|
||||
case 47: return 2
|
||||
case 98: return 2
|
||||
case 117: return 2
|
||||
case 114: return 2
|
||||
case 92: return 3
|
||||
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")
|
||||
}
|
||||
a0[0].acc = acc[:]
|
||||
a0[0].f = fun[:]
|
||||
a0[0].id = 0
|
||||
|
@ -410,10 +410,9 @@ a0[0].id = 0
|
|||
{
|
||||
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 43: return -1
|
||||
case 43: return 1
|
||||
default:
|
||||
switch {
|
||||
default: return -1
|
||||
|
@ -421,9 +420,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 43: return 1
|
||||
case 43: return -1
|
||||
default:
|
||||
switch {
|
||||
default: return -1
|
||||
|
@ -522,9 +522,10 @@ a0[4].id = 4
|
|||
{
|
||||
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 40: return 1
|
||||
case 40: return -1
|
||||
default:
|
||||
switch {
|
||||
default: return -1
|
||||
|
@ -532,10 +533,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 40: return -1
|
||||
case 40: 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,9 +578,10 @@ a0[6].id = 6
|
|||
{
|
||||
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 62: return 1
|
||||
case 62: return -1
|
||||
default:
|
||||
switch {
|
||||
default: return -1
|
||||
|
@ -588,10 +589,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 62: return -1
|
||||
case 62: return 1
|
||||
default:
|
||||
switch {
|
||||
default: return -1
|
||||
|
@ -634,10 +634,9 @@ a0[8].id = 8
|
|||
{
|
||||
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 61: return -1
|
||||
case 61: return 1
|
||||
default:
|
||||
switch {
|
||||
default: return -1
|
||||
|
@ -645,9 +644,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 61: return 1
|
||||
case 61: return -1
|
||||
default:
|
||||
switch {
|
||||
default: return -1
|
||||
|
@ -662,6 +662,46 @@ a0[9].id = 9
|
|||
{
|
||||
var acc [8]bool
|
||||
var fun [8]func(rune) int
|
||||
fun[0] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 45: return 1
|
||||
case 46: 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 {
|
||||
switch(r) {
|
||||
case 45: return -1
|
||||
case 46: return 4
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 48: return 5
|
||||
case 49 <= r && r <= 57: return 5
|
||||
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) {
|
||||
|
@ -676,19 +716,6 @@ fun[2] = func(r rune) int {
|
|||
}
|
||||
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 45: return -1
|
||||
|
@ -702,19 +729,6 @@ fun[1] = func(r rune) int {
|
|||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
fun[0] = 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[5] = true
|
||||
fun[5] = func(r rune) int {
|
||||
switch(r) {
|
||||
|
@ -729,34 +743,6 @@ fun[5] = func(r rune) int {
|
|||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
acc[6] = true
|
||||
fun[6] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 46: return -1
|
||||
case 45: return -1
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 48: return 7
|
||||
case 49 <= r && r <= 57: return 7
|
||||
default: return -1
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
acc[3] = true
|
||||
fun[3] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 46: return 4
|
||||
case 45: return -1
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 48: return 5
|
||||
case 49 <= r && r <= 57: return 5
|
||||
default: return -1
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
acc[7] = true
|
||||
fun[7] = func(r rune) int {
|
||||
switch(r) {
|
||||
|
@ -771,6 +757,20 @@ fun[7] = func(r rune) int {
|
|||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
acc[6] = true
|
||||
fun[6] = func(r rune) int {
|
||||
switch(r) {
|
||||
case 45: return -1
|
||||
case 46: return -1
|
||||
default:
|
||||
switch {
|
||||
case 48 <= r && r <= 48: return 7
|
||||
case 49 <= r && r <= 57: return 7
|
||||
default: return -1
|
||||
}
|
||||
}
|
||||
panic("unreachable")
|
||||
}
|
||||
a0[10].acc = acc[:]
|
||||
a0[10].f = fun[:]
|
||||
a0[10].id = 10
|
||||
|
@ -778,11 +778,12 @@ a0[10].id = 10
|
|||
{
|
||||
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 10: return 1
|
||||
case 32: return 1
|
||||
case 9: return 1
|
||||
case 10: return 1
|
||||
default:
|
||||
switch {
|
||||
default: return -1
|
||||
|
@ -790,12 +791,11 @@ 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 9: return 1
|
||||
case 10: return 1
|
||||
case 32: return 1
|
||||
case 9: return 1
|
||||
default:
|
||||
switch {
|
||||
default: return -1
|
||||
|
@ -810,20 +810,21 @@ a0[11].id = 11
|
|||
{
|
||||
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 9: return -1
|
||||
case 62: return -1
|
||||
case 12: return -1
|
||||
case 60: return -1
|
||||
case 10: return -1
|
||||
case 13: return -1
|
||||
case 62: return -1
|
||||
case 45: return -1
|
||||
case 94: return -1
|
||||
case 58: return -1
|
||||
case 61: return -1
|
||||
case 32: return -1
|
||||
case 10: return -1
|
||||
case 9: return -1
|
||||
case 13: return -1
|
||||
case 58: return -1
|
||||
case 12: return -1
|
||||
case 43: return -1
|
||||
case 61: return -1
|
||||
default:
|
||||
switch {
|
||||
default: return 1
|
||||
|
@ -831,21 +832,20 @@ 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 13: return -1
|
||||
case 58: return -1
|
||||
case 12: return -1
|
||||
case 43: return -1
|
||||
case 61: return -1
|
||||
case 60: return -1
|
||||
case 62: return -1
|
||||
case 45: return -1
|
||||
case 94: return -1
|
||||
case 58: return -1
|
||||
case 61: return -1
|
||||
case 32: return -1
|
||||
case 43: return -1
|
||||
case 9: return -1
|
||||
case 62: return -1
|
||||
case 12: return -1
|
||||
case 60: return -1
|
||||
case 10: return -1
|
||||
case 9: return -1
|
||||
case 13: return -1
|
||||
default:
|
||||
switch {
|
||||
default: return 1
|
|
@ -52,7 +52,7 @@ func TestParseQuery(t *testing.T) {
|
|||
},
|
||||
{
|
||||
input: []byte(`{"query":"+beer \"light beer\" -devon"}`),
|
||||
output: NewSyntaxQuery(`+beer "light beer" -devon`),
|
||||
output: NewQueryStringQuery(`+beer "light beer" -devon`),
|
||||
},
|
||||
{
|
||||
input: []byte(`{"min":5.1,"max":7.1,"field":"desc"}`),
|
||||
|
@ -185,7 +185,7 @@ func TestQueryValidate(t *testing.T) {
|
|||
err: nil,
|
||||
},
|
||||
{
|
||||
query: NewSyntaxQuery(`+beer "light beer" -devon`),
|
||||
query: NewQueryStringQuery(`+beer "light beer" -devon`),
|
||||
err: nil,
|
||||
},
|
||||
{
|
||||
|
|
42
y.go
42
y.go
|
@ -2,7 +2,7 @@ package bleve
|
|||
|
||||
import __yyfmt__ "fmt"
|
||||
|
||||
//line query_syntax.y:2
|
||||
//line query_string.y:2
|
||||
import "log"
|
||||
|
||||
func logDebugGrammar(format string, v ...interface{}) {
|
||||
|
@ -11,7 +11,7 @@ func logDebugGrammar(format string, v ...interface{}) {
|
|||
}
|
||||
}
|
||||
|
||||
//line query_syntax.y:12
|
||||
//line query_string.y:12
|
||||
type yySymType struct {
|
||||
yys int
|
||||
s string
|
||||
|
@ -347,48 +347,48 @@ yydefault:
|
|||
switch yynt {
|
||||
|
||||
case 1:
|
||||
//line query_syntax.y:22
|
||||
//line query_string.y:22
|
||||
{
|
||||
logDebugGrammar("INPUT")
|
||||
}
|
||||
case 2:
|
||||
//line query_syntax.y:27
|
||||
//line query_string.y:27
|
||||
{
|
||||
logDebugGrammar("SEARCH PARTS")
|
||||
}
|
||||
case 3:
|
||||
//line query_syntax.y:31
|
||||
//line query_string.y:31
|
||||
{
|
||||
logDebugGrammar("SEARCH PART")
|
||||
}
|
||||
case 4:
|
||||
//line query_syntax.y:36
|
||||
//line query_string.y:36
|
||||
{
|
||||
|
||||
}
|
||||
case 5:
|
||||
//line query_syntax.y:42
|
||||
//line query_string.y:42
|
||||
{
|
||||
}
|
||||
case 6:
|
||||
//line query_syntax.y:45
|
||||
//line query_string.y:45
|
||||
{
|
||||
|
||||
}
|
||||
case 7:
|
||||
//line query_syntax.y:51
|
||||
//line query_string.y:51
|
||||
{
|
||||
logDebugGrammar("PLUS")
|
||||
parsingMust = true
|
||||
}
|
||||
case 8:
|
||||
//line query_syntax.y:56
|
||||
//line query_string.y:56
|
||||
{
|
||||
logDebugGrammar("MINUS")
|
||||
parsingMustNot = true
|
||||
}
|
||||
case 9:
|
||||
//line query_syntax.y:62
|
||||
//line query_string.y:62
|
||||
{
|
||||
str := yyS[yypt-0].s
|
||||
logDebugGrammar("STRING - %s", str)
|
||||
|
@ -405,7 +405,7 @@ yydefault:
|
|||
parsingLastQuery = q
|
||||
}
|
||||
case 10:
|
||||
//line query_syntax.y:78
|
||||
//line query_string.y:78
|
||||
{
|
||||
phrase := yyS[yypt-0].s
|
||||
logDebugGrammar("PHRASE - %s", phrase)
|
||||
|
@ -422,7 +422,7 @@ yydefault:
|
|||
parsingLastQuery = q
|
||||
}
|
||||
case 11:
|
||||
//line query_syntax.y:94
|
||||
//line query_string.y:94
|
||||
{
|
||||
field := yyS[yypt-2].s
|
||||
str := yyS[yypt-0].s
|
||||
|
@ -440,7 +440,7 @@ yydefault:
|
|||
parsingLastQuery = q
|
||||
}
|
||||
case 12:
|
||||
//line query_syntax.y:111
|
||||
//line query_string.y:111
|
||||
{
|
||||
field := yyS[yypt-2].s
|
||||
phrase := yyS[yypt-0].s
|
||||
|
@ -458,7 +458,7 @@ yydefault:
|
|||
parsingLastQuery = q
|
||||
}
|
||||
case 13:
|
||||
//line query_syntax.y:128
|
||||
//line query_string.y:128
|
||||
{
|
||||
field := yyS[yypt-3].s
|
||||
min := yyS[yypt-0].f
|
||||
|
@ -477,7 +477,7 @@ yydefault:
|
|||
parsingLastQuery = q
|
||||
}
|
||||
case 14:
|
||||
//line query_syntax.y:146
|
||||
//line query_string.y:146
|
||||
{
|
||||
field := yyS[yypt-4].s
|
||||
min := yyS[yypt-0].f
|
||||
|
@ -496,7 +496,7 @@ yydefault:
|
|||
parsingLastQuery = q
|
||||
}
|
||||
case 15:
|
||||
//line query_syntax.y:164
|
||||
//line query_string.y:164
|
||||
{
|
||||
field := yyS[yypt-3].s
|
||||
max := yyS[yypt-0].f
|
||||
|
@ -515,7 +515,7 @@ yydefault:
|
|||
parsingLastQuery = q
|
||||
}
|
||||
case 16:
|
||||
//line query_syntax.y:182
|
||||
//line query_string.y:182
|
||||
{
|
||||
field := yyS[yypt-4].s
|
||||
max := yyS[yypt-0].f
|
||||
|
@ -534,7 +534,7 @@ yydefault:
|
|||
parsingLastQuery = q
|
||||
}
|
||||
case 17:
|
||||
//line query_syntax.y:202
|
||||
//line query_string.y:202
|
||||
{
|
||||
boost := yyS[yypt-0].f
|
||||
if parsingLastQuery != nil {
|
||||
|
@ -548,12 +548,12 @@ yydefault:
|
|||
logDebugGrammar("BOOST %f", boost)
|
||||
}
|
||||
case 18:
|
||||
//line query_syntax.y:216
|
||||
//line query_string.y:216
|
||||
{
|
||||
|
||||
}
|
||||
case 19:
|
||||
//line query_syntax.y:220
|
||||
//line query_string.y:220
|
||||
{
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue