-
Notifications
You must be signed in to change notification settings - Fork 687
Commit
- Loading branch information
There are no files selected for viewing
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 | ||
Check failure on line 34 in index/scorch/snapshot_index_str.go GitHub Actions / test (1.20.x, ubuntu-latest)
Check failure on line 34 in index/scorch/snapshot_index_str.go GitHub Actions / test (1.22.x, macos-latest)
Check failure on line 34 in index/scorch/snapshot_index_str.go GitHub Actions / test (1.21.x, ubuntu-latest)
Check failure on line 34 in index/scorch/snapshot_index_str.go GitHub Actions / test (1.22.x, ubuntu-latest)
Check failure on line 34 in index/scorch/snapshot_index_str.go GitHub Actions / test (1.20.x, macos-latest)
|
||
postings []segment.SynonymsList | ||
Check failure on line 35 in index/scorch/snapshot_index_str.go GitHub Actions / test (1.20.x, ubuntu-latest)
Check failure on line 35 in index/scorch/snapshot_index_str.go GitHub Actions / test (1.22.x, macos-latest)
Check failure on line 35 in index/scorch/snapshot_index_str.go GitHub Actions / test (1.21.x, ubuntu-latest)
Check failure on line 35 in index/scorch/snapshot_index_str.go GitHub Actions / test (1.22.x, ubuntu-latest)
Check failure on line 35 in index/scorch/snapshot_index_str.go GitHub Actions / test (1.20.x, macos-latest)
|
||
iterators []segment.SynonymsIterator | ||
Check failure on line 36 in index/scorch/snapshot_index_str.go GitHub Actions / test (1.20.x, ubuntu-latest)
Check failure on line 36 in index/scorch/snapshot_index_str.go GitHub Actions / test (1.22.x, macos-latest)
Check failure on line 36 in index/scorch/snapshot_index_str.go GitHub Actions / test (1.21.x, ubuntu-latest)
Check failure on line 36 in index/scorch/snapshot_index_str.go GitHub Actions / test (1.22.x, ubuntu-latest)
Check failure on line 36 in index/scorch/snapshot_index_str.go GitHub Actions / test (1.20.x, macos-latest)
|
||
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 | ||
} |
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 | ||
} |