Skip to content
Snippets Groups Projects
Verified Commit 66fe724b authored by Daniel Bessey's avatar Daniel Bessey
Browse files

Add documentation

parent 565e4c54
No related merge requests found
Pipeline #146160 passed with stage
in 5 minutes and 21 seconds
......@@ -27,6 +27,25 @@ class QueryError(PountError):
class Query:
def __init__(self, **kwargs):
"""
Initializes a new instance of the class.
Args:
**kwargs: Keyword arguments that can be used to initialize the instance.
- language (str): The language of the instance. Defaults to settings.DEFAULT_LANGUAGE
- user (User): If the user is provided, the query will return only items that can be accessed by the
user, otherwise it returns only public items.
- project_ids (str): Limit the search to the given project IDs.
- set_ids (str): Limit the search to the given set IDs.
- page (int): The page number.
- page_size (int): The page size. Defaults to 10.
Raises:
QueryError: If the page number is greater than MAX_PAGES.
Returns:
None
"""
self.language = kwargs.pop("language", DEFAULT_LANGUAGE)
self.aggregation_fields = {}
self.excluded_fields = []
......@@ -61,6 +80,17 @@ class Query:
return f"{self.__class__.__name__}(**{kwargs})"
def execute(self, query: str, exclude_private_fields: bool = False) -> Response:
"""
Executes a search query using Elasticsearch.
Args:
query (str): The search query.
exclude_private_fields (bool, optional): Whether to exclude private fields from the search results.
Defaults to False.
Returns:
Response: The search response from Elasticsearch.
"""
self.exclude_private_fields = exclude_private_fields
s = Search()
......@@ -98,6 +128,7 @@ class Query:
return response
def exclude(self, fields: list[str]) -> None:
"""Excludes the given fields from the search results."""
self.excluded_fields = fields
def add_filters(self) -> list[Q]:
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment