[
https://issues.apache.org/jira/browse/SOLR-3191?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13832384#comment-13832384
]
Andrea Gazzarini commented on SOLR-3191:
----------------------------------------
Hi all, I attached a patch for the fl exclusion feature.
Sorry for the very long post and for delay. I will try to be as short as
possible, there are a lot of things that need to be considered but in general I
would say that the whole stuff is easier to try than to explain.
h4. Token types
Lets start with token types. The following tokens are supported (just a short
list, each type is subsequently explained):
\\
\\
- literal inclusion: name, id, title, subject (can be aliased like
alias:fieldname);
- inclusion glob: na*, n?m\*, \*me (cannot be aliased because the expression
could match more than one fields);
- \*: as before, that means "all real fields": internally is managed as a
special case of inclusion glob;
- literal exclusion: -name, -id, -title (cannot be aliased, doesn't make sense)
- exclusion glob: -na\*, -n?m\*, -\*me (cannot be aliased, doesn't make sense);
as special case -\* is ignored.
- transformers: \[explain\], \[docid\], \[shard\] (can be aliased like
alias:\[docid\])
- functions: sum(1,1), "literal value" (can be aliased like alias:sum(1,1),
myalias:"literal value")
h5. Literal inclusion
A literal inclusion declares a (real) field that must be returned in response.
Supports aliasing (myalias:fieldname)
Examples:
- name
- this.is.a.valid.field (see ReturnFieldsTest.testDotInFieldName)
- this-is-a-valid-field (see ReturnFieldsTest.testHyphenInFieldName)
- this$is$a$valid$field (see ReturnFieldsTest.testDollarInFieldName)
- #foo_s,fl (see ReturnFieldsTest.testFunkyFieldNames)
h5. Inclusion glob
An inclusion glob declares an expression using \* and / or ?. Fields matching
that expression will be returned in response.
Examples (see ReturnFieldsTest.testWildCards / testReturnAllFields /
testReturnOnlyName)
- na\*
- n?m?
- n\*
- \*me
- \*m?
{panel:bgColor=#FFFFCE}
Aliases cannot be applied to inclusion globs because an expression could match
more than one fields. The expression wont' be discarded, just the alias part.
So for example
_fl=alias:na\*_ will collect the _na\*_ inclusion glob
{panel}
h5. Literal exclusion
A literal exclusion declares a field that will be excluded in response.
Basically it is a literal inclusion prefixed by -
Examples (see ReturnFieldsTest.testReturnOnlyName / testReturnOnlyNameAndTitle
/ testReturnAllRealFieldsExceptName):
- -name
- -this.is.a.valid.field (see ReturnFieldsTest.testDotInFieldName)
- -this-is-a-valid-field (see ReturnFieldsTest.testHyphenInFieldName)
- -this$is$a$valid$field (see ReturnFieldsTest.testDollarInFieldName)
- -#foo_s,-fl (see ReturnFieldsTest.testFunkyFieldNames)
{panel:bgColor=#FFFFCE}
Aliasing is not supported so
_fl=-alias:fieldname_
is silently discarded. Note that in this case or in this one:
_fl=-a1:a -a2:b -a3:c_
all tokens are invalid so the expressions will be resolved in
_fl=_
and therefore standard procedure applies (see last testcase on
ReturnFieldsTest.testReturnAllRealFields)
{panel}
h5. exclusion glob
An exclusion glob is an expression that uses \* and / or ?. Fields matching
that expression will be excluded from response.
Examples (see ReturnFieldsTest.testReturnOnlyName / testReturnOnlyNameAndTitle
/ testReturnAllRealFieldsExceptName):
- -na\*
- -n?m?
- -n\*
- -\*me
- -\*m?
{panel:bgColor=#FFFFCE}
As literal exclusions, you cannot use aliases in these expressions, they will
be silently discarded (see last testcase on
ReturnFieldsTest.testReturnAllRealFields)
{panel}
h5. transformers
Just one important thing: invalid transformers are ignored.
Examples (you can see all the assertions below in
ReturnsFieldsTest.testTransformers):
\\
\\
- fl=\[explain\] (one transformer)
- fl=\[docid\] \[explain\] (two transformers)
- fl=\[shard\] id (a transformer and a real field)
- fl=\[xxxxxx\] (an invalid transformer. That will have the same effect of
having an empty fl)
- fl=\[xxxxxx\] \[yyyyy\] (two invalid transformers. That will have the same
effect of having an empty fl)
- fl=\[docid\] \[shard\] \[xxxx\] (the invalid transformer will be ignored so
only \[docid\] and \[shard\] will be evaluated
- fl=myalias:\[docid\] (aliased transformer)
- fl=alias:\[yyyyyy\] (invalid aliased transformer - will be ignored, see last
test on ReturnFieldsTest.testReturnAllRealFields)
h5. Functions (and literals)
All functions described here
http://wiki.apache.org/solr/FunctionQuery#Available_Functions
can be declared in "fl" parameter. They can be aliased too.
Examples (see ReturnFieldsTest.testFunctions)
\\
\\
- fl=sum(1,1)
- fl="this is a literal", 'this is another literal", 1.2
- fl=pippo:"this is an aliased literal", pluto:'this is another aliased
literal", paperino:1.2
- fl={!func}add($v1,$v2)&v1=10&v2=13.0
- fl=alias:{!func}add($v1,$v2)&v1=10&v2=13.0
{panel:bgColor=#FFFFCE}
WARNING: differently from transformers, in case of invalid function an
exception will be thrown.
{panel}
h4. Aliases
Aliases are supported on
\\
\\
- literal field names (e.g. alias:fieldname)
- transformers (e.g. alias:\[docid\])
- functions (e.g. alias:max(1,2))
and are not supported on
\\
\\
- inclusion globs (because expression could match multiple fields and alias in
response must be uniquely associated to a field. The alias part of the token
expression will be ignored, the glob expression collected)
- literal exclusion (doesn't make sense, will be silently ignored)
- exclusion globs (doesn't make sense, will be silently ignored)
h4. General rules
- an inclusion (literal or glob) is ignored if in case of \*.
** fl=\* name na\* (return all fields, name and na\* fields are already
included)
** fl=name \* (same as before)
** any exclusion token will be ignored if an inclusion has been defined before
** fl=name -id (returns all fields except id so "name", with other real
fields, is implicitly included)
- an inclusion token will clear all exclusion
** fl=-id name (means "returns only name", no matter what exclusions are
defined before)
** fl=-id \*
** the \* expression is ignored in case of an exclusion (literal or glob)
** \* -name (the \* doesn't make sense, or in other words is implicit: returns
all fields except name)
** -name \* (same as before)
- score, transformers and functions doesn't change the behaviour described
above, they are just added to response
** fl=score, \*, name
** fl=\*, \[docid\], name, sum(1,1), myfunctionalias:"literal value"
** fl=name -id \[shard\], exchange:1.34
- an empty or null fl will execute as "\*" (all real fields). Note that we can
be in this situation if we pass an empty fl, no fl or if all tokens in fl are
discarded because invalid.
- some other rules like multiplicity on fl parameter (see
ReturnFieldsTest.testManyParameters), token separator (comma or whitespaces -
see ReturnFieldsTest.testWhitespace and ReturnFieldsTest.testSeparators) remain
the same.
h4. Some (technical) consideration
1. I'm not sure about the test methods granularity level: some test methods,
although grouping the same concept, contain a lot of sub-cases / scenarios and
sometimes is hard to capture the functional behaviour (see for example
ReturnFieldsTest.testTransformers or ReturnFieldsTest.testAliases). Maybe doing
a test method for each sub-case should be better? I modified the
ReturnFieldsTest for adding additional test cases but I followed the existing
approach...let me know what you think about a much fine level of
granularity..in case I can try to make some refactoring in that direction
2. There are two (at least it seems to me) classes that are testing
ReturnFields behaviour : ReturnFieldsTest and TestPseudoReturnFields...maybe
all those test methods could be part of one test case? I don't know the reason
behind the choice of having two classes so I'm just asking, the
TestPseudoReturnFields is still there and all tests are green
Any feedback is warmly welcome.
Andrea
> field exclusion from fl
> -----------------------
>
> Key: SOLR-3191
> URL: https://issues.apache.org/jira/browse/SOLR-3191
> Project: Solr
> Issue Type: Improvement
> Reporter: Luca Cavanna
> Priority: Minor
>
> I think it would be useful to add a way to exclude field from the Solr
> response. If I have for example 100 stored fields and I want to return all of
> them but one, it would be handy to list just the field I want to exclude
> instead of the 99 fields for inclusion through fl.
--
This message was sent by Atlassian JIRA
(v6.1#6144)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]