Skip to content

Commit

Permalink
Next steps
Browse files Browse the repository at this point in the history
  • Loading branch information
psrok1 committed Feb 1, 2024
1 parent 79803d5 commit 3d63ff1
Show file tree
Hide file tree
Showing 9 changed files with 161 additions and 432 deletions.
8 changes: 4 additions & 4 deletions mwdb/core/search/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .exceptions import SQLQueryBuilderBaseException
from .search import SQLQueryBuilder
from .exceptions import QueryBaseException
from .query_builder import build_query

__all__ = [
"SQLQueryBuilderBaseException",
"SQLQueryBuilder",
"QueryBaseException",
"build_query",
]
43 changes: 34 additions & 9 deletions mwdb/core/search/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,54 @@
class SQLQueryBuilderBaseException(Exception):
from typing import Optional, Tuple, Type

from luqum.tree import Item


class QueryBaseException(Exception):
"""
Base exception for SQLQueryBuilder
"""


class UnsupportedGrammarException(SQLQueryBuilderBaseException):
class QueryParseException(QueryBaseException):
"""
Raised when SQLQueryBuilder does not support given Lucene grammar
Raised when Lucene parser is unable to parse a query
"""


class FieldNotQueryableException(SQLQueryBuilderBaseException):
class UnsupportedNodeException(QueryBaseException):
def __init__(self, message: str, node: Item):
super().__init__(f"{message} ({node.pos}:{node.pos + node.size - 1})")


class UnsupportedNodeTypeException(UnsupportedNodeException):
"""
Raised when field does not exists, so it can't be queried, eg. file.unexistent_field
Raised when query visitor does not support given Lucene grammar
"""

def __init__(self, node: Item, expected: Optional[Tuple[Type, ...]] = None):
message = f"{node.__class__.__name__} is not supported here"
if expected:
message += f", expected {', '.join(typ.__name__ for typ in expected)}"
super().__init__(message, node)

class MultipleObjectsQueryException(SQLQueryBuilderBaseException):

class UnsupportedLikeStatement(UnsupportedNodeException):
def __init__(self, node: Item):
super().__init__("Like statements are not supported here", node)


class InvalidValueException(QueryBaseException):
def __init__(self, value: str, expected: str):
super().__init__(f"Invalid value format: {value}, expected {expected}")


class FieldNotQueryableException(QueryBaseException):
"""
Raised when multiple object types are queried,
e.g. file.file_name:something AND static.cfg:something2
Raised when field does not exists, so it can't be queried, eg. file.unexistent_field
"""


class ObjectNotFoundException(SQLQueryBuilderBaseException):
class ObjectNotFoundException(QueryBaseException):
"""
Raised when object referenced in query condition can't be found
"""
Loading

0 comments on commit 3d63ff1

Please sign in to comment.