Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

apply filterStringFunction when customIndexFn #3992

Merged
merged 1 commit into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would len(arg.q.SrcFunc.Args) be valuable here to guard against indexing this when nothing is present, or simply overkill?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I figured this has already been checked by the parseSrcFn and must be valid in order to reach this point

filtered = matchStrings(filtered, values, filter)
case compareAttrFn:
filter.ineqValue = arg.srcFn.ineqValue
Expand Down