[ckan-changes] [ckan/ckan] 607182: [#1815] Add "distinct" param to datastore_search
GitHub
noreply at github.com
Thu Jul 3 14:36:11 UTC 2014
Branch: refs/heads/1815-distinct-datastore-search
Home: https://github.com/ckan/ckan
Commit: 6071824b9ed90d96d45a4564d041c5c228a33622
https://github.com/ckan/ckan/commit/6071824b9ed90d96d45a4564d041c5c228a33622
Author: Vitor Baptista <vitor at vitorbaptista.com>
Date: 2014-07-03 (Thu, 03 Jul 2014)
Changed paths:
M ckanext/datastore/db.py
M ckanext/datastore/logic/action.py
M ckanext/datastore/logic/schema.py
M ckanext/datastore/plugin.py
M ckanext/datastore/tests/test_search.py
Log Message:
-----------
[#1815] Add "distinct" param to datastore_search
This allows the users to get only the distinct values of the query. The "total"
field on the returned data is related to all fields, not only the distincts.
For example, in our test we have the data:
```json
[
{"author": "tolstoy", "title": "Anna Karenina"},
{"author": "tolstoy", "title": "War and Peace"}
]
```
We want to get a list with all authors on the datastore resource. Then we query
the "datastore_search" with:
```json
{
"resource_id": "the_resource_id",
"fields": ["author"],
"distinct": True
}
```
The result is;
```json
{
"success": True,
"total": 2,
"records": [{"author": "tolstoy"}]
}
```
Note that even though there's only one returned record, the "total" field is 2. This is because "total" doesn't take into account the distinct values, but all rows that match our query.
More information about the ckan-changes
mailing list