0
0
Fork 0

add more test cases of index

tests fields, highlighting, document field loading
This commit is contained in:
Marty Schoch 2014-11-26 15:36:58 -05:00
parent 453d4cf770
commit a2c3fa262a
4 changed files with 99 additions and 0 deletions

View File

@ -148,6 +148,27 @@ func TestCrud(t *testing.T) {
if !foundNameField {
t.Errorf("expected to find field named 'name' with value 'marty'")
}
fields, err := index.Fields()
if err != nil {
t.Fatal(err)
}
expectedFields := map[string]bool{
"_all": false,
"name": false,
"desc": false,
}
if len(fields) != len(expectedFields) {
t.Fatalf("expected %d fields got %d", len(expectedFields), len(fields))
}
for _, f := range fields {
expectedFields[f] = true
}
for ef, efp := range expectedFields {
if !efp {
t.Errorf("field %s is missing", ef)
}
}
}
func TestIndexCreateNewOverExisting(t *testing.T) {

View File

@ -138,6 +138,11 @@ func runTestDir(t *testing.T, dir string) {
t.Errorf("expected hit %d to have fields %#v got %#v", hi, hit.Fields, res.Hits[hi].Fields)
}
}
if hit.Fragments != nil {
if !reflect.DeepEqual(hit.Fragments, res.Hits[hi].Fragments) {
t.Errorf("expected hit %d to have fragments %#v got %#v", hi, hit.Fragments, res.Hits[hi].Fragments)
}
}
}
if search.Result.Facets != nil {
if !reflect.DeepEqual(search.Result.Facets, res.Facets) {

View File

@ -5,6 +5,7 @@
"name": {
"fields": [
{
"include_term_vectors": true,
"include_in_all": true,
"index": true,
"store": true,

View File

@ -330,5 +330,77 @@
}
]
}
},
{
"comment": "highlight results",
"search": {
"from": 0,
"size": 10,
"query": {
"field": "name",
"match": "long"
},
"highlight": {
"fields": ["name"]
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "b",
"fragments": {
"name": ["steve has a <span class=\"highlight\">long</span> name"]
}
}
]
}
},
{
"comment": "highlight results without specifying fields",
"search": {
"from": 0,
"size": 10,
"query": {
"field": "name",
"match": "long"
},
"highlight": {}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "b",
"fragments": {
"name": ["steve has a <span class=\"highlight\">long</span> name"]
}
}
]
}
},
{
"comment": "request fields",
"search": {
"from": 0,
"size": 10,
"fields": ["age","birthday"],
"query": {
"field": "name",
"match": "long"
}
},
"result": {
"total_hits": 1,
"hits": [
{
"id": "b",
"fields": {
"age": 27,
"birthday": "2001-09-09T01:46:40Z"
}
}
]
}
}
]