Skip to content

Commit

Permalink
Apply filterStringFunction when calling customIndexFn (#3992)
Browse files Browse the repository at this point in the history
Fixes #3991
  • Loading branch information
sjhewitt authored and pawanrawal committed Sep 18, 2019
1 parent 1519590 commit 76a5e66
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 11 deletions.
18 changes: 18 additions & 0 deletions systest/plugin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,24 @@ func TestPlugins(t *testing.T) {
},
)

suite(
"word: string @index(anagram) @lang .",
`[
{ "word@en": "airmen", "word@fr": "no match" },
{ "word@en": "no match", "word@fr": "marine" }
]`,
[]testCase{
{`
{ q(func: allof(word@en, anagram, "remain")) {
word: word@en
}}`, `
{ "q": [
{ "word": "airmen" }
]}`,
},
},
)

suite(
"ip: string @index(cidr) .",
`[
Expand Down
11 changes: 2 additions & 9 deletions worker/stringfilter.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type stringFilter struct {
match matchFunc
ineqValue types.Val
eqVals []types.Val
tokName string
}

func matchStrings(uids *pb.List, values [][]types.Val, filter stringFilter) *pb.List {
Expand Down Expand Up @@ -92,15 +93,7 @@ func ineqMatch(value types.Val, filter stringFilter) bool {
}

func tokenizeValue(value types.Val, filter stringFilter) []string {
var tokName string
switch filter.funcType {
case standardFn:
tokName = "term"
case fullTextSearchFn:
tokName = "fulltext"
}

tokenizer, found := tok.GetTokenizer(tokName)
tokenizer, found := tok.GetTokenizer(filter.tokName)
// tokenizer was used in previous stages of query processing, it has to be available
x.AssertTrue(found)

Expand Down
16 changes: 14 additions & 2 deletions worker/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,8 @@ func needsStringFiltering(srcFn *functionContext, langs []string, attr string) b

return langForFunc(langs) != "." &&
(srcFn.fnType == standardFn || srcFn.fnType == hasFn ||
srcFn.fnType == fullTextSearchFn || srcFn.fnType == compareAttrFn)
srcFn.fnType == fullTextSearchFn || srcFn.fnType == compareAttrFn ||
srcFn.fnType == customIndexFn)
}

func (qs *queryState) handleCompareScalarFunction(arg funcArgs) error {
Expand Down Expand Up @@ -1388,9 +1389,20 @@ func (qs *queryState) filterStringFunction(arg funcArgs) error {
case hasFn:
// Dont do anything, as filtering based on lang is already
// done above.
case fullTextSearchFn, standardFn:
case fullTextSearchFn:
filter.tokens = arg.srcFn.tokens
filter.match = defaultMatch
filter.tokName = "fulltext"
filtered = matchStrings(filtered, values, filter)
case standardFn:
filter.tokens = arg.srcFn.tokens
filter.match = defaultMatch
filter.tokName = "term"
filtered = matchStrings(filtered, values, filter)
case customIndexFn:
filter.tokens = arg.srcFn.tokens
filter.match = defaultMatch
filter.tokName = arg.q.SrcFunc.Args[0]
filtered = matchStrings(filtered, values, filter)
case compareAttrFn:
filter.ineqValue = arg.srcFn.ineqValue
Expand Down

0 comments on commit 76a5e66

Please sign in to comment.