query vs document_query
-
RavenDB Queries can be executed using
query
ordocument_query
, or by passing RQL directly to the server viaraw_query
.
Learn more in Query Overview. -
In the Python client API,
query
methods and their equivalentdocument_query
methods provide the same functionality. (This is different from the C# client implementation, which often provides different functionality forQuery
methods and theirDocumentQuery
counterparts.)
Therefore the Python documentation often providesquery
usage samples without addingdocument_query
examples as well. -
In this page:
API support
Mutability
-
All Python queries (
query
anddocument_query
) are mutable.
You may get different results if you try to reuse a query. -
The usage of the
Query
method in the following example:query = session.query(object_type=User).where_starts_with("name", "A") age_query = query.where_greater_than_or_equal("age", 21) eye_query = query.where_equals("eye_color", "blue")
will result with the following Lucene-syntax queries:
query: from Users where startsWith(name, 'A')
ageQuery: from Users where startsWith(name, 'A') and age > 21
eyeQuery: from Users where startsWith(name, 'A') and eye_color = 'blue'
-
A similar usage with
document_query
:document_query = session.advanced.document_query(object_type=User).where_starts_with("name", "A") age_document_query = document_query.where_greater_than_or_equal("age", 21) eye_document_query = document_query.where_equals("eye_color", "blue") # Here all of the DocumentQuery variables have the same reference
will result with the following Lucene queries:
documentQuery: from Users where startsWith(name, 'A')
(before creatingageDocumentQuery
)ageDocumentQuery: from Users where startsWith(name, 'A') and age > 21
(before creatingeyeDocumentQuery
)eyeDocumentuery: from Users where startsWith(name, 'A') and age > 21 and eye_color = 'blue'
All created Lucene queries are the same query (actually the same instance).
This is an important hint to be aware of if you are going to reusedocument_query
.
Default Query Operator
-
Queries use
AND
as the default operator. -
The operator can be replaced by calling
using_default_operator
:
session.advanced.document_query(object_type=User).using_default_operator(QueryOperator.OR)