Search¶
Search¶
Note
Requires guillotina.contrib.catalog.pg application activated with PostgreSQL.
The @search endpoint accepts GET requests. It is available for container and resources. The default search parser and query syntax is flat and does not support nested queries.
- GET /(db)/(container)/@search¶
Make search request
Permission: guillotina.SearchContent
Context: guillotina.interfaces.content.IResource
http
GET /db/container/@search HTTP/1.1 Accept: application/json Authorization: Basic cm9vdDpyb290
curl
curl -i -X GET http://nohost/db/container/@search -H "Accept: application/json" --user root:root
httpie
http http://nohost/db/container/@search Accept:application/json -a root:root
response
HTTP/1.1 503 OK Content-Type: application/json {}
- Query Parameters:
term (string) -- Generic search term support. See modifier list below for usage.
_from (string) -- Start with search result _from.
_size (string) -- Size of result set. Max to 50 (app_settings.catalog_max_results).
_sort_asc (string) -- Sort ascending by index _sort_asc.
_sort_des (string) -- Sort descending by index _sort_des.
_metadata (string) -- List of metadata fields to include
_metadata_not (string) -- List of metadata fields to exclude
__eq (string)
__not (string)
__gt (string)
__gte (string)
__lte (string)
__lt (string)
__in (string)
- Status Codes:
200 OK -- Search results
401 Unauthorized -- You are not authorized to perform the operation
404 Not Found -- The resource does not exist
- GET /(db)/(container)/(id)/@search¶
Make search request
Permission: guillotina.SearchContent
Context: guillotina.interfaces.content.IResource
http
GET /db/container/foobar/@search HTTP/1.1 Accept: application/json Authorization: Basic cm9vdDpyb290
curl
curl -i -X GET http://nohost/db/container/foobar/@search -H "Accept: application/json" --user root:root
httpie
http http://nohost/db/container/foobar/@search Accept:application/json -a root:root
response
HTTP/1.1 503 OK Content-Type: application/json {}
- Query Parameters:
term (string) -- Generic search term support. See modifier list below for usage.
_from (string) -- Start with search result _from.
_size (string) -- Size of result set. Max to 50 (app_settings.catalog_max_results).
_sort_asc (string) -- Sort ascending by index _sort_asc.
_sort_des (string) -- Sort descending by index _sort_des.
_metadata (string) -- List of metadata fields to include
_metadata_not (string) -- List of metadata fields to exclude
__eq (string)
__not (string)
__gt (string)
__gte (string)
__lte (string)
__lt (string)
__in (string)
- Status Codes:
200 OK -- Search results
401 Unauthorized -- You are not authorized to perform the operation
404 Not Found -- The resource does not exist
Warning
The POST request to @search endpoint is not implemented.
- POST /(db)/(container)/@search¶
Make a complex search query
Permission: guillotina.RawSearchContent
Context: guillotina.interfaces.content.IResource
http
POST /db/container/@search HTTP/1.1 Accept: application/json Authorization: Basic cm9vdDpyb290 { "type_name": "Item", "_from": 10, "_size": 5, "modification_date__gt": "2019-06-15T18:37:31.008359+00:00", "_sort_asc": "modification_date", "_metadata": "title,description" }
curl
curl -i -X POST http://nohost/db/container/@search -H "Accept: application/json" --data-raw '{ "type_name": "Item", "_from": 10, "_size": 5, "modification_date__gt": "2019-06-15T18:37:31.008359+00:00", "_sort_asc": "modification_date", "_metadata": "title,description" }' --user root:root
httpie
echo '{ "type_name": "Item", "_from": 10, "_size": 5, "modification_date__gt": "2019-06-15T18:37:31.008359+00:00", "_sort_asc": "modification_date", "_metadata": "title,description" }' | http POST http://nohost/db/container/@search Accept:application/json -a root:root
response
HTTP/1.1 503 OK Content-Type: application/json {}
- Status Codes:
200 OK -- Search results
401 Unauthorized -- You are not authorized to perform the operation
404 Not Found -- The resource does not exist
Use cases¶
Search for specific sentence on text field
Search for words on text field
Search for not having a value on a field
Search for wildcard on text field
Search for keyword on filter
Search for number and comparisons on numeric field
Search for paths
Define from which element you want to search
Define the search size return
Define metadata included and excluded on the result
Return full objects
Implementation details¶
A list:
query : term=first+second+third
result : term = first, second, third
Text field search specific text/sentence:
query : title__eq=my+sentence
Text field search words text:
query : title__in=my+sentence
Text field search not words text:
query : title__not=not+willing+words
Text field search wildcard text:
query : title__wildcard=will*
Keyword on filter:
query : subject=guillotina
Number on field:
query : age=39
query : age__gte=39
query : age__lte=39
Date on field:
query : creation=10-09-2018
query : creation__gte=10-09-2018
query : creation__lte=10-09-2018
Which metadata to return:
query : _metadata=title+description
query : _metadata_not=language+description
Sort:
query : _sort_asc=age
Search size:
query : _size=30
From which element to return:
query : _from=30
Search for paths:
query : path__starts=plone+folder
result : elements on /plone/folder
Escape +:
query : term=hola++adeu
result : term=hola+adeu
Return full object:
query : _fullobject=true
Examples¶
Plone call:
GET /plone/@search?path.query=%2Ffolder&path.depth=2
Guillotina call:
GET @search?path_starts=folder&depth_gte=2
Plone call:
GET /plone/@search?Title=lorem&portal_type=Document
Guillotina call:
GET @search?title_in=lorem&portal_type=Document
Aggregation¶
- GET /(db)/(container)/(id)/@aggregation¶
Make aggregation request
Permission: guillotina.AccessContent
Context: guillotina.interfaces.content.IResource
http
GET /db/container/foobar/@aggregation HTTP/1.1 Accept: application/json Authorization: Basic cm9vdDpyb290
curl
curl -i -X GET http://nohost/db/container/foobar/@aggregation -H "Accept: application/json" --user root:root
httpie
http http://nohost/db/container/foobar/@aggregation Accept:application/json -a root:root
response
HTTP/1.1 503 OK Content-Type: application/json {}
- Status Codes:
200 OK -- aggregation results
401 Unauthorized -- You are not authorized to perform the operation
404 Not Found -- The resource does not exist
Example:
@aggregation?title__eq=my+title&metadata=title,creators
{
"title": {
"items": {
"Item2": 1
},
"total": 1
},
"creators": {
"items": {
"root": 1
},
"total": 1
}
}