Skip to content

Commit

Permalink
Search refactoring to better utilize index and improve capabilities (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
psrok1 committed Feb 22, 2024
1 parent 49b6ae5 commit 2c1cf9c
Show file tree
Hide file tree
Showing 16 changed files with 1,057 additions and 819 deletions.
4 changes: 2 additions & 2 deletions docs/user-guide/7-Lucene-search.rst
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ This syntax is still not very convenient, so we have introduced shorter syntax i
.. code-block::
size:>=500000
size:">=500000"
size:>="500000"
MWDB-Core supports human-readable file size so instead of specifying the number of bytes, we can refer to larger units like kB, MB and GB.

Expand Down Expand Up @@ -141,7 +141,7 @@ If you want to search for objects uploaded after certain hour:

.. code-block::
upload_time:">=2020-09-28 08:00"
upload_time:>="2020-09-28 08:00"
If you want to search for objects uploaded at certain minute:

Expand Down
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 .search import build_query

__all__ = [
"SQLQueryBuilderBaseException",
"SQLQueryBuilder",
"QueryBaseException",
"build_query",
]
45 changes: 35 additions & 10 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
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
"""

0 comments on commit 2c1cf9c

Please sign in to comment.