Skip to content

Commit

Permalink
Merge pull request #35 from butonic/handle-terms-as-keywords
Browse files Browse the repository at this point in the history
handle terms as keywords, remove quotes
  • Loading branch information
butonic authored Jun 17, 2020
2 parents 5441647 + a828b82 commit 02e759f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/provider/bleve.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ func recursiveBuildQuery(n *godata.ParseNode) (query.Query, error) {
if n.Children[1].Token.Type != godata.FilterTokenString {
return nil, errors.New("equality expected a string on the rhs")
}
q := bleve.NewTermQuery(n.Children[1].Token.Value)
// string tokens are enclosed with 'some string'
// ' is escaped as ''
// TODO unescape '' as '
// http://docs.oasis-open.org/odata/odata/v4.01/cs01/part2-url-conventions/odata-v4.01-cs01-part2-url-conventions.html#sec_URLComponents
q := bleve.NewTermQuery(n.Children[1].Token.Value[1 : len(n.Children[1].Token.Value)-1])
q.SetField(n.Children[0].Token.Value)
return q, nil
case "and":
Expand Down
3 changes: 3 additions & 0 deletions pkg/service/v0/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/CiscoM31/godata"
"github.com/blevesearch/bleve"
"github.com/blevesearch/bleve/analysis/analyzer/keyword"
"github.com/blevesearch/bleve/search/query"
"github.com/gofrs/uuid"
"github.com/golang/protobuf/ptypes/empty"
Expand Down Expand Up @@ -41,6 +42,8 @@ func New(cfg *config.Config) Service {
os.MkdirAll(filepath.Join(cfg.Server.AccountsDataPath, "accounts"), 0700)

mapping := bleve.NewIndexMapping()
mapping.DefaultAnalyzer = keyword.Name

// TODO don't bother to store fields as we will load the account from disk
index, err := bleve.New(filepath.Join(cfg.Server.AccountsDataPath, "index.bleve"), mapping)
if err != nil {
Expand Down

0 comments on commit 02e759f

Please sign in to comment.