add more test cases of index
tests fields, highlighting, document field loading
This commit is contained in:
parent
453d4cf770
commit
a2c3fa262a
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
"name": {
|
||||
"fields": [
|
||||
{
|
||||
"include_term_vectors": true,
|
||||
"include_in_all": true,
|
||||
"index": true,
|
||||
"store": true,
|
||||
|
|
|
@ -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"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
Loading…
Reference in New Issue