Skip to content

Commit

Permalink
test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
CascadingRadium committed Nov 14, 2024
1 parent 6be002b commit 0a5d3bf
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 157 deletions.
51 changes: 15 additions & 36 deletions doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,31 +177,10 @@ func (s *stubField) Compose(field string, length int, freq index.TokenFrequencie

}

// -----------------------------------------------------------------------------
type stubSynonymDefinition struct {
term string
synonyms []string
}

func (s *stubSynonymDefinition) Term() string {
return s.term
}

func (s *stubSynonymDefinition) Synonyms() []string {
return s.synonyms
}

func newStubSynonymDefinition(term string, synonyms []string) index.SynonymDefinition {
return &stubSynonymDefinition{
term: term,
synonyms: synonyms,
}
}

// -----------------------------------------------------------------------------
type stubSynonymField struct {
name string
synonymDefs []index.SynonymDefinition
name string
synonymMap map[string][]string
}

func (s *stubSynonymField) Name() string {
Expand Down Expand Up @@ -240,9 +219,9 @@ func (s *stubSynonymField) NumPlainTextBytes() uint64 {
return 0
}

func (sf *stubSynonymField) VisitSynonymDefinitions(visitor func(index.SynonymDefinition)) {
for _, def := range sf.synonymDefs {
visitor(def)
func (sf *stubSynonymField) VisitSynonymDefinitions(visitor func(term string, synonyms []string)) {
for term, synonyms := range sf.synonymMap {
visitor(term, synonyms)
}
}

Expand All @@ -251,19 +230,19 @@ func analyzeStubTerm(term string) string {
return lowerCaseTerm
}

func newStubSynonymField(name, analyzer string, defs []index.SynonymDefinition) index.SynonymField {
analyzedSynonymDefs := make([]index.SynonymDefinition, 0, len(defs))
for _, def := range defs {
analyzedTerm := analyzeStubTerm(def.Term())
analyzedSynonyms := make([]string, 0, len(def.Synonyms()))
for _, syn := range def.Synonyms() {
func newStubSynonymField(name, analyzer string, synonymMap map[string][]string) index.SynonymField {
analyzedSynonymDefs := make(map[string][]string, len(synonymMap))
for term, synonyms := range synonymMap {
analyzedTerm := analyzeStubTerm(term)
analyzedSynonyms := make([]string, 0, len(synonyms))
for _, syn := range synonyms {
analyzedSynonyms = append(analyzedSynonyms, analyzeStubTerm(syn))
}
analyzedSynonymDefs = append(analyzedSynonymDefs, newStubSynonymDefinition(analyzedTerm, analyzedSynonyms))
analyzedSynonymDefs[analyzedTerm] = analyzedSynonyms
}
return &stubSynonymField{
name: name,
synonymDefs: analyzedSynonymDefs,
name: name,
synonymMap: analyzedSynonymDefs,
}
}

Expand Down Expand Up @@ -305,7 +284,7 @@ func (s *stubSynonymDocument) AddIDField() {
s.fields = append(s.fields, newStubFieldSplitString("_id", nil, s.id, true, false, false))
}

func (s *stubSynonymDocument) VisitSynonymField(visitor index.SynonymFieldVisitor) {
func (s *stubSynonymDocument) VisitSynonymFields(visitor index.SynonymFieldVisitor) {
for _, f := range s.fields {
if sf, ok := f.(index.SynonymField); ok {
visitor(sf)
Expand Down
16 changes: 7 additions & 9 deletions section_synonym.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,12 @@ func (so *synonymIndexOpaque) process(field index.SynonymField, fieldID uint16,

termSynMap := so.SynonymTermToID[tid]

field.VisitSynonymDefinitions(func(def index.SynonymDefinition) {
pid := thesaurus[def.Term()] - 1
field.VisitSynonymDefinitions(func(term string, synonyms []string) {
pid := thesaurus[term] - 1

bs := so.Synonyms[pid]

for _, syn := range def.Synonyms() {
for _, syn := range synonyms {
code := encodeSynonym(termSynMap[syn], docNum)
bs.Add(code)
}
Expand All @@ -163,7 +163,7 @@ func (so *synonymIndexOpaque) realloc() {

for _, result := range so.results {
if synDoc, ok := result.(index.SynonymDocument); ok {

Check failure on line 165 in section_synonym.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, ubuntu-latest)

undefined: index.SynonymDocument

Check failure on line 165 in section_synonym.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, macos-latest)

undefined: index.SynonymDocument

Check failure on line 165 in section_synonym.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, macos-latest)

undefined: index.SynonymDocument

Check failure on line 165 in section_synonym.go

View workflow job for this annotation

GitHub Actions / test (1.20.x, ubuntu-latest)

undefined: index.SynonymDocument

Check failure on line 165 in section_synonym.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, ubuntu-latest)

undefined: index.SynonymDocument

Check failure on line 165 in section_synonym.go

View workflow job for this annotation

GitHub Actions / test (1.20.x, macos-latest)

undefined: index.SynonymDocument
synDoc.VisitSynonymField(func(synField index.SynonymField) {
synDoc.VisitSynonymFields(func(synField index.SynonymField) {

Check failure on line 166 in section_synonym.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, ubuntu-latest)

undefined: index.SynonymField

Check failure on line 166 in section_synonym.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, macos-latest)

undefined: index.SynonymField

Check failure on line 166 in section_synonym.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, macos-latest)

undefined: index.SynonymField

Check failure on line 166 in section_synonym.go

View workflow job for this annotation

GitHub Actions / test (1.20.x, ubuntu-latest)

undefined: index.SynonymField

Check failure on line 166 in section_synonym.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, ubuntu-latest)

undefined: index.SynonymField

Check failure on line 166 in section_synonym.go

View workflow job for this annotation

GitHub Actions / test (1.20.x, macos-latest)

undefined: index.SynonymField
fieldIDPlus1 := so.FieldsMap[synField.Name()]
so.getOrDefineThesaurus(fieldIDPlus1-1, synField.Name())
})
Expand All @@ -172,7 +172,7 @@ func (so *synonymIndexOpaque) realloc() {

for _, result := range so.results {
if synDoc, ok := result.(index.SynonymDocument); ok {

Check failure on line 174 in section_synonym.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, ubuntu-latest)

undefined: index.SynonymDocument

Check failure on line 174 in section_synonym.go

View workflow job for this annotation

GitHub Actions / test (1.21.x, macos-latest)

undefined: index.SynonymDocument

Check failure on line 174 in section_synonym.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, macos-latest)

undefined: index.SynonymDocument

Check failure on line 174 in section_synonym.go

View workflow job for this annotation

GitHub Actions / test (1.20.x, ubuntu-latest)

undefined: index.SynonymDocument

Check failure on line 174 in section_synonym.go

View workflow job for this annotation

GitHub Actions / test (1.22.x, ubuntu-latest)

undefined: index.SynonymDocument

Check failure on line 174 in section_synonym.go

View workflow job for this annotation

GitHub Actions / test (1.20.x, macos-latest)

undefined: index.SynonymDocument
synDoc.VisitSynonymField(func(synField index.SynonymField) {
synDoc.VisitSynonymFields(func(synField index.SynonymField) {
fieldIDPlus1 := so.FieldsMap[synField.Name()]
thesaurusID := uint16(so.getOrDefineThesaurus(fieldIDPlus1-1, synField.Name()))

Expand All @@ -183,8 +183,7 @@ func (so *synonymIndexOpaque) realloc() {

termSynMap := so.SynonymTermToID[thesaurusID]

synField.VisitSynonymDefinitions(func(synDef index.SynonymDefinition) {
term := synDef.Term()
synField.VisitSynonymDefinitions(func(term string, synonyms []string) {
_, exists := thesaurus[term]
if !exists {
pidNext++
Expand All @@ -193,8 +192,7 @@ func (so *synonymIndexOpaque) realloc() {
thesaurus[term] = pidPlus1
thesaurusKeys = append(thesaurusKeys, term)
}
syns := synDef.Synonyms()
for _, syn := range syns {
for _, syn := range synonyms {
_, exists := termSynMap[syn]
if !exists {
sidNext++
Expand Down
Loading

0 comments on commit 0a5d3bf

Please sign in to comment.