-
Notifications
You must be signed in to change notification settings - Fork 689
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
25d6851
commit 02e5403
Showing
7 changed files
with
467 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright (c) 2024 Couchbase, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package scorch | ||
|
||
import ( | ||
"reflect" | ||
|
||
"github.com/blevesearch/bleve/v2/size" | ||
segment "github.com/blevesearch/scorch_segment_api/v2" | ||
) | ||
|
||
var reflectStaticSizeIndexSnapshotSynonymTermReader int | ||
|
||
func init() { | ||
var istr IndexSnapshotSynonymTermReader | ||
reflectStaticSizeIndexSnapshotSynonymTermReader = int(reflect.TypeOf(istr).Size()) | ||
} | ||
|
||
type IndexSnapshotSynonymTermReader struct { | ||
name string | ||
snapshot *IndexSnapshot | ||
thesauri []segment.Thesaurus | ||
postings []segment.SynonymsList | ||
iterators []segment.SynonymsIterator | ||
segmentOffset int | ||
} | ||
|
||
func (i *IndexSnapshotSynonymTermReader) Size() int { | ||
sizeInBytes := reflectStaticSizeIndexSnapshotSynonymTermReader + size.SizeOfPtr + | ||
len(i.name) | ||
|
||
for _, thesaurus := range i.thesauri { | ||
sizeInBytes += thesaurus.Size() | ||
} | ||
|
||
for _, postings := range i.postings { | ||
sizeInBytes += postings.Size() | ||
} | ||
|
||
for _, iterator := range i.iterators { | ||
sizeInBytes += iterator.Size() | ||
} | ||
|
||
return sizeInBytes | ||
} | ||
|
||
func (i *IndexSnapshotSynonymTermReader) Next() (string, error) { | ||
// find the next hit | ||
for i.segmentOffset < len(i.iterators) { | ||
if i.iterators[i.segmentOffset] != nil { | ||
next, err := i.iterators[i.segmentOffset].Next() | ||
if err != nil { | ||
return "", err | ||
} | ||
if next != nil { | ||
synTerm := next.Term() | ||
return synTerm, nil | ||
} | ||
i.segmentOffset++ | ||
} | ||
} | ||
return "", nil | ||
} | ||
|
||
func (i *IndexSnapshotSynonymTermReader) Close() error { | ||
if i.snapshot != nil { | ||
i.snapshot.recycleSynonymTermReader(i) | ||
} | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// Copyright (c) 2024 Couchbase, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package mapping | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/blevesearch/bleve/v2/registry" | ||
) | ||
|
||
type SynonymSource struct { | ||
CollectionName string `json:"collection"` | ||
AnalyzerName string `json:"analyzer"` | ||
} | ||
|
||
func (s *SynonymSource) Collection() string { | ||
return s.CollectionName | ||
} | ||
|
||
func (s *SynonymSource) Analyzer() string { | ||
return s.AnalyzerName | ||
} | ||
|
||
func (s *SynonymSource) SetCollection(c string) { | ||
s.CollectionName = c | ||
} | ||
|
||
func (s *SynonymSource) SetAnalyzer(a string) { | ||
s.AnalyzerName = a | ||
} | ||
|
||
func (s *SynonymSource) Validate(c *registry.Cache) error { | ||
if s.CollectionName == "" { | ||
return fmt.Errorf("collection name is required") | ||
} | ||
if s.AnalyzerName == "" { | ||
return fmt.Errorf("analyzer name is required") | ||
} | ||
_, err := c.AnalyzerNamed(s.AnalyzerName) | ||
if err != nil { | ||
return fmt.Errorf("analyzer named '%s' not found", s.AnalyzerName) | ||
} | ||
return nil | ||
} |
Oops, something went wrong.