-
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
840fde5
commit 7191b83
Showing
42 changed files
with
2,107 additions
and
51 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright (c) 2014 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 synonym | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/blevesearch/bleve/v2/analysis" | ||
"github.com/blevesearch/bleve/v2/registry" | ||
index "github.com/blevesearch/bleve_index_api" | ||
) | ||
|
||
const Name = "textsynonym" | ||
|
||
type SynonymSource struct { | ||
collection string | ||
analyzer string | ||
} | ||
|
||
func New(collection string, analyzer string) *SynonymSource { | ||
return &SynonymSource{ | ||
collection: collection, | ||
analyzer: analyzer, | ||
} | ||
} | ||
|
||
func (p *SynonymSource) Collection() string { | ||
return p.collection | ||
} | ||
|
||
func (p *SynonymSource) Analyzer() string { | ||
return p.analyzer | ||
} | ||
|
||
func (q *SynonymSource) MetadataKey() string { | ||
return q.collection + string(index.SynonymKeySeparator) + q.analyzer | ||
} | ||
|
||
func SynonymSourceConstructor(config map[string]interface{}, cache *registry.Cache) (analysis.SynonymSource, error) { | ||
collection, ok := config["collection"].(string) | ||
if !ok { | ||
return nil, fmt.Errorf("must specify synonym collection") | ||
} | ||
analyzer, ok := config["analyzer"].(string) | ||
if !ok { | ||
return nil, fmt.Errorf("must specify synonym analyzer") | ||
} | ||
return New(collection, analyzer), nil | ||
} | ||
|
||
func init() { | ||
registry.RegisterSynonymSource(Name, SynonymSourceConstructor) | ||
} |
Oops, something went wrong.