-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Search refactoring to better utilize index and improve capabilities (#…
…906)
- Loading branch information
Showing
16 changed files
with
1,057 additions
and
819 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 .search import build_query | ||
|
||
__all__ = [ | ||
"SQLQueryBuilderBaseException", | ||
"SQLQueryBuilder", | ||
"QueryBaseException", | ||
"build_query", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
Base exception for search engine | ||
""" | ||
|
||
|
||
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) -> None: | ||
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) -> 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 UnsupportedPatternValue(UnsupportedNodeException): | ||
def __init__(self, node: Item) -> None: | ||
super().__init__("Pattern values are not supported here", node) | ||
|
||
|
||
class InvalidValueException(QueryBaseException): | ||
def __init__(self, value: str, expected: str) -> None: | ||
super().__init__(f"Invalid value format: {value}, expected {expected}") | ||
|
||
|
||
class MultipleObjectsQueryException(SQLQueryBuilderBaseException): | ||
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 exist, 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 | ||
""" |
Oops, something went wrong.