Hi,
On Apr 16, 2012, at 8:10 PM, Jean-Vincent Drean wrote:
Hi devs,
while replacing calls to xwiki#searchDocuments by calls to the query
manager script service I ran into the following query manager issue:
http://jira.xwiki.org/browse/XWIKI-7273 (XWQL short form queries
should distinct on document fullname.)
I think we could use the recent QueryFilter mechanism to handle the
addition of the "distinct" in the select statement.
https://github.com/xwiki/xwiki-platform/blob/master/xwiki-platform-core/xwi…
QueryFilters allow to:
- transform queries depending on a dynamic parameter (for example the
user preferences in HiddenDocumentFilter)
- transform the select part of a short query, without requiring
programming rights
Here's an example of what it could look like from a velocity script:
----------------------------------------------------8<----------------------------------------------------
#set($query =
$services.query.xwql("").addFilter("unique").addFilter("hidden"))
----------------------------------------------------8<----------------------------------------------------
Note that in the future we could decide that the Query wrapper we use
in the QueryManagerScriptService (ScriptQuery) have the "unique"
filter by default + a way to remove it from the script.
I wasn't expecting us to consider using multiple filters when I added
the new APIs in Query (4.0RC1).
If we agree that a QueryFilter would be a nice way to handle this, I'd
like to break those API before we release 4.0:
----------------------------------------------------8<----------------------------------------------------
- Query setFilter(QueryFilter filter);
+ Query addFilter(QueryFilter filter);
- QueryFilter getFilter();
+ List<QueryFilter> getFilters();
----------------------------------------------------8<----------------------------------------------------
It's a little bit more complex. We did consider several filters when we added
setFilter()!! :)
We said that if we need more than one filter we could have an AndFilter() that takes a
list of Filters. And allow more complex filters should we need them, like OrFilter, etc.
#set($query = $services.query.xwql("").setFilter(new
AndFilter("unique", "hidden"))
Written with a fluent API that would give:
#set($query = $services.query.xwql("").setFilter(and("unique",
"hidden"))
Or even:
#set($query =
$services.query.xwql("").setFilter("unique").and("hidden")
Anyway I'm just mentioning this to explain what we thought about and an alternative to
addFilter(). The only problem with addFilter() is if you need more complex Filters later
on. It's not extensible whereas using AndFilter() and OrFilter() is more extensible at
the expense of a little bit more text if not using a fluent api.
Anyway I'm fine with either addFilter or setFilter.
Also +1 to use a QueryFilter for adding a "distinct" in the query.
Thanks
-Vincent
WDYT ?
JV.