Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions index.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"context"
"fmt"

"github.com/blevesearch/bleve/v2/index/upsidedown"
// "github.com/blevesearch/bleve/v2/index/upsidedown"

"github.com/blevesearch/bleve/v2/document"
"github.com/blevesearch/bleve/v2/mapping"
Expand Down Expand Up @@ -298,7 +298,7 @@ func New(path string, mapping mapping.IndexMapping) (Index, error) {
// The provided mapping will be used for all
// Index/Search operations.
func NewMemOnly(mapping mapping.IndexMapping) (Index, error) {
return newIndexUsing("", mapping, upsidedown.Name, Config.DefaultMemKVStore, nil)
return newIndexUsing("", mapping, Config.DefaultIndexType, Config.DefaultMemKVStore, nil)
}

// NewUsing creates index at the specified path,
Expand Down
64 changes: 64 additions & 0 deletions synonym_mem_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package bleve

import (
"testing"
)

func TestSynonymInMem(t *testing.T) {
doc := struct {
Text string `json:"text"`
}{
Text: "hardworking employee",
}

synDef := &SynonymDefinition{
Synonyms: []string{"hardworking", "industrious", "conscientious", "persistent"},
}

bleveMapping := NewIndexMapping()
err := bleveMapping.AddSynonymSource("english", map[string]interface{}{
"collection": "collection1",
"analyzer": "en",
})
if err != nil {
t.Fatal(err)
}

textFieldMapping := NewTextFieldMapping()
textFieldMapping.Analyzer = "en"
textFieldMapping.SynonymSource = "english"
bleveMapping.DefaultMapping.AddFieldMappingsAt("text", textFieldMapping)

// HERE IS THE FAILURE: Using NewMemOnly instead of New()
index, err := NewMemOnly(bleveMapping)
if err != nil {
t.Fatal(err)
}
defer index.Close()

err = index.Index("doc1", doc)
if err != nil {
t.Fatal(err)
}

if synIndex, ok := index.(SynonymIndex); ok {
err = synIndex.IndexSynonym("synDoc1", "collection1", synDef)
if err != nil {
t.Fatal(err)
}
} else {
t.Fatal("expected synonym index support")
}

query := NewMatchQuery("persistent")
query.SetField("text")
searchRequest := NewSearchRequest(query)
searchResult, err := index.Search(searchRequest)
if err != nil {
t.Fatal(err)
}

if searchResult.Total != 1 {
t.Errorf("Expected 1 match, got %d", searchResult.Total)
}
}