Query (Search)
The query
operation in Contendo Server allows you to search for objects based on specified criteria. You can customize
your query to include various filters, control the number of results, and manage versioning and relationships of the
objects.
Request Format
- Operation:
query
- HTTP method:
POST
- URL:
{REPOSITORY_URL}
- Content-Type:
application/json
,multipart/form-data
,application/x-www-form-urlencoded
Parameters
Name | Required | Description | Link |
---|---|---|---|
statement |
Yes | The query string that defines the search criteria. | |
searchAllVersions |
No | If set to true , will search across all versions of the objects. |
Versioning |
includeRelationships |
No | If set to true , includes related objects in the query results. |
Relationships |
maxItems |
No | The maximum number of results to return. Default is 100 . |
|
skipCount |
No | The number of results to skip for pagination. Default is 0 . |
Example Request - Searching for documents authored by "John":
curl -X 'POST' \
'{REPOSITORY_URL}' \
-H 'Content-Type: application/json' \
-d '{
"operation": "query",
"statement": "SELECT name, author FROM dog WHERE author = 'John'",
"maxItems": 10,
"skipCount": 0,
"searchAllVersions": true
}'
Response Format
- Content-Type:
application/json
- Response body: A list of objects that match the query criteria, with each object represented in JSON format.
Field Name | Condition | Description | Link |
---|---|---|---|
results[] |
Always present | Array of result objects. | |
├ properties / succinctProperties |
Always present | The properties of the result object. | Properties |
└ relationships[] |
if includeRelationships=true |
The relationships of the result object. | Relationships |
hasMoreItems |
Always present | true if more relationships exist beyond maxItems . |
|
numItems |
Always present | The total number of relationships returned. |
Example Response - List of documents by author "John":
{
"results": [
{
"succinctProperties": {
"name": "Rex",
"author": "John"
}
},
{
"succinctProperties": {
"name": "Fido",
"author": "John"
}
}
],
"hasMoreItems": false,
"numItems": 2
}
Full-text Search
To use fulltext search in your query, you must utilize
CONTAINS
function.
Contendo Server enables boolean-based full-text searches across object's:
- meta-data
SELECT *
FROM person
WHERE address CONTAINS('Mazuranic', meta)
- content
SELECT *
FROM person
WHERE address CONTAINS('Mazuranic', contendo)
- meta-data and content simultaneously
SELECT *
FROM person
WHERE address CONTAINS('Mazuranic')
Relevancy ranking
To get relevancy ranking, use score()
function in SELECT clause.
SELECT score(), name
FROM person
WHERE address CONTAINS('Mazuranic')
Boolean full-text search operators
The boolean full-text search capability supports the following operators:
+
A leading plus sign indicates that this word must be present in each row that is returned.
-
A leading minus sign indicates that this word must not be present in any of the rows that are returned.
Note: The - operator acts only to exclude rows that are otherwise matched by other search terms. Thus, a boolean-mode search that contains only terms preceded by - returns an empty result. It does not return "all rows except those containing any of the excluded terms."
(no operator)
By default, (when neither + nor - is specified), the word is optional, but the rows that contain it are rated higher.
@distance
It tests whether two or more words all start within a specified distance from each other, measured in words. Specify the search words within a double-quoted string immediately before the @distance operator, for example, CONTAINS('"word1 word2 word3" @8').
> <
These two operators are used to change a word's contribution to the relevance value that is assigned to a row. The > operator increases the contribution and the < operator decreases it. See the example following this list.
( )
Parentheses group words into subexpressions. Parenthesized groups can be nested.
~
A leading tilde acts as a negation operator, causing the word's contribution to the row's relevance to be negative. This is useful for marking "noise" words. A row containing such a word is rated lower than others, but is not excluded altogether, as it would be with the - operator.
*
The asterisk serves as the truncation (or wildcard) operator. Unlike the other operators, it is appended to the word to be affected. Words match if they begin with the word preceding the * operator.
If a word is specified with the truncation operator, it is not stripped from a boolean query, even if it is too short or a stop-word.
The wildcarded word is considered as a prefix that must be present at the start of one or more words. If the minimum
word length is 4, a search for '+word +the*' could return fewer rows than a search for '+word +the', because the second
query ignores the too-short search term the
.
The minimum word length is set to 3.
"
A phrase that is enclosed within double quote (") characters matches only rows that contain the phrase literally, as it was typed. The full-text engine splits the phrase into words and performs a search in the FULLTEXT index for the words. Nonword characters need not be matched exactly: Phrase searching requires only that matches contain exactly the same words as the phrase and in the same order. For example, "test phrase" matches "test, phrase".
If the phrase contains no words that are in the index, the result is empty. The words might not be in the index because of a combination of factors: if they do not exist in the text, are stopwords, or are shorter than the minimum length of indexed words.
Boolean full-text operators usage examples
-- Find rows that contain at least one of the two words
SELECT *
FROM person
WHERE address CONTAINS('apple banana')
-- Find rows that contain both words
SELECT *
FROM person
WHERE address CONTAINS('+apple +juice')
-- Find rows that contain the word "apple", but rank rows higher if they also contain "macintosh"
SELECT *
FROM person
WHERE address CONTAINS('+apple macintosh')
-- Find rows that contain the word "apple" but not "macintosh".
SELECT *
FROM person
WHERE address CONTAINS('+apple -macintosh')
-- Find rows that contain the word "apple", but if the row also contains the word "macintosh", rate it lower than if row
-- does not. This is "softer" than a search for '+apple -macintosh', for which the presence of "macintosh" causes the row
-- not to be returned at all.
SELECT *
FROM person
WHERE address CONTAINS('+apple ~macintosh')
-- Find rows that contain the words "apple" and "turnover", or "apple" and "strudel" (in any order), but rank "apple
-- turnover" higher than "apple strudel".
SELECT *
FROM person
WHERE address CONTAINS('+apple +(>turnover <strudel)')
-- Find rows that contain words such as "apple", "apples", "applesauce", or "applet"
SELECT *
FROM person
WHERE address CONTAINS('apple*')
-- Find rows that contain the exact phrase "some words" (for example, rows that contain "some words of wisdom" but not
-- "some noise words"). Note that the " characters that enclose the phrase are operator characters that delimit the phrase.
-- They are not the quotation marks that enclose the search string itself.
SELECT *
FROM person
WHERE address CONTAINS('"some words"')