0
0
Fork 0

support match_all, match_none and docid queries via JSON

also fixed bug in docIDQuery execution which would cause not
matching the highest docID passed in if it was in fact a
valid ID
This commit is contained in:
Marty Schoch 2015-12-16 14:53:14 -05:00
parent 849b69c318
commit f7698f1f15
4 changed files with 112 additions and 1 deletions

View File

@ -203,6 +203,42 @@ func ParseQuery(input []byte) (Query, error) {
}
return &rv, nil
}
_, hasMatchAll := tmp["match_all"]
if hasMatchAll {
var rv matchAllQuery
err := json.Unmarshal(input, &rv)
if err != nil {
return nil, err
}
if rv.Boost() == 0 {
rv.SetBoost(1)
}
return &rv, nil
}
_, hasMatchNone := tmp["match_none"]
if hasMatchNone {
var rv matchNoneQuery
err := json.Unmarshal(input, &rv)
if err != nil {
return nil, err
}
if rv.Boost() == 0 {
rv.SetBoost(1)
}
return &rv, nil
}
_, hasDocIds := tmp["ids"]
if hasDocIds {
var rv docIDQuery
err := json.Unmarshal(input, &rv)
if err != nil {
return nil, err
}
if rv.Boost() == 0 {
rv.SetBoost(1)
}
return &rv, nil
}
return nil, ErrorUnknownQueryType
}

View File

@ -65,6 +65,18 @@ func TestParseQuery(t *testing.T) {
input: []byte(`{"prefix":"budwei","field":"desc"}`),
output: NewPrefixQuery("budwei").SetField("desc"),
},
{
input: []byte(`{"match_all":{}}`),
output: NewMatchAllQuery(),
},
{
input: []byte(`{"match_none":{}}`),
output: NewMatchNoneQuery(),
},
{
input: []byte(`{"ids":["a","b","c"]}`),
output: NewDocIDQuery([]string{"a", "b", "c"}),
},
{
input: []byte(`{"madeitup":"queryhere"}`),
output: nil,

View File

@ -33,7 +33,8 @@ func NewDocIDSearcher(indexReader index.IndexReader, ids []string, boost float64
if len(ids) > 0 {
var idReader index.DocIDReader
idReader, err = indexReader.DocIDReader(kept[0], kept[len(kept)-1])
endTerm := string(incrementBytes([]byte(kept[len(kept)-1])))
idReader, err = indexReader.DocIDReader(kept[0], endTerm)
if err != nil {
return nil, err
}

View File

@ -496,5 +496,67 @@
}
]
}
},
{
"comment": "test match none",
"search": {
"from": 0,
"size": 10,
"query": {
"match_none": {}
}
},
"result": {
"total_hits": 0,
"hits": []
}
},
{
"comment": "test match all",
"search": {
"from": 0,
"size": 10,
"query": {
"match_all": {}
}
},
"result": {
"total_hits": 4,
"hits": [
{
"id": "d"
},
{
"id": "c"
},
{
"id": "b"
},
{
"id": "a"
}
]
}
},
{
"comment": "test doc id query",
"search": {
"from": 0,
"size": 10,
"query": {
"ids": ["b", "c"]
}
},
"result": {
"total_hits": 2,
"hits": [
{
"id": "c"
},
{
"id": "b"
}
]
}
}
]