diff --git a/systest/plugin_test.go b/systest/plugin_test.go index 3f1edebae99..256c9709fa9 100644 --- a/systest/plugin_test.go +++ b/systest/plugin_test.go @@ -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) .", `[ diff --git a/worker/stringfilter.go b/worker/stringfilter.go index 7ff0a5b3058..eccc900c068 100644 --- a/worker/stringfilter.go +++ b/worker/stringfilter.go @@ -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 { @@ -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) diff --git a/worker/task.go b/worker/task.go index 0adb18661ea..19a46464021 100644 --- a/worker/task.go +++ b/worker/task.go @@ -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 { @@ -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