0
0
Fork 0

added unit test for bug #207

This commit is contained in:
Marty Schoch 2015-05-21 07:49:41 -04:00
parent 9a09689e61
commit 5b8c9f2d73
1 changed files with 73 additions and 0 deletions

View File

@ -864,3 +864,76 @@ func TestDocumentFieldArrayPositions(t *testing.T) {
t.Fatal(err)
}
}
func TestKeywordSearchBug207(t *testing.T) {
defer func() {
err := os.RemoveAll("testidx")
if err != nil {
t.Fatal(err)
}
}()
f := NewTextFieldMapping()
f.Analyzer = "keyword"
m := NewIndexMapping()
m.DefaultMapping = NewDocumentMapping()
m.DefaultMapping.AddFieldMappingsAt("Body", f)
index, err := New("testidx", m)
if err != nil {
t.Fatal(err)
}
doc1 := struct {
Body string
}{
Body: "a555c3bb06f7a127cda000005",
}
err = index.Index("a", doc1)
if err != nil {
t.Fatal(err)
}
doc2 := struct {
Body string
}{
Body: "555c3bb06f7a127cda000005",
}
err = index.Index("b", doc2)
if err != nil {
t.Fatal(err)
}
// now search for these terms
sreq := NewSearchRequest(NewTermQuery("a555c3bb06f7a127cda000005"))
sres, err := index.Search(sreq)
if err != nil {
t.Fatal(err)
}
if sres.Total != 1 {
t.Errorf("expected 1 result, got %d", sres.Total)
}
if sres.Hits[0].ID != "a" {
t.Errorf("expecated id 'a', got '%s'", sres.Hits[0].ID)
}
sreq = NewSearchRequest(NewTermQuery("555c3bb06f7a127cda000005"))
sres, err = index.Search(sreq)
if err != nil {
t.Fatal(err)
}
if sres.Total != 1 {
t.Errorf("expected 1 result, got %d", sres.Total)
}
if sres.Hits[0].ID != "b" {
t.Errorf("expecated id 'b', got '%s'", sres.Hits[0].ID)
}
err = index.Close()
if err != nil {
t.Fatal(err)
}
}