Skip to content

Commit

Permalink
Merge pull request #58 from VianneyMI/47-bugfixes-in-search
Browse files Browse the repository at this point in the history
47-bugfixes-in-search
  • Loading branch information
VianneyMI committed Aug 9, 2023
2 parents 41f828c + ddb6b70 commit aa9634b
Show file tree
Hide file tree
Showing 10 changed files with 343 additions and 24 deletions.
11 changes: 10 additions & 1 deletion changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Release Notes

## 0.15.0

### Fixes

* Fixed bug in `Search.from_operator()` classmethod due to recent change in operator type in `Search` class
* Fixed misspelled operators in constructors map in `Search` class
* Fixed missing aliases and missing kwargs reduction in some `Search` operators


## 0.14.1

### Fixes
Expand All @@ -8,7 +17,7 @@

### Refactoring

* Import pydantic into base.py and using abse.py to access pydantic features
* Import pydantic into base.py and using base.py to access pydantic features


## 0.14.0
Expand Down
2 changes: 1 addition & 1 deletion monggregate/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from monggregate.pipeline import Pipeline
from monggregate.expressions.expressions import Expression

__version__ = "0.14.1"
__version__ = "0.15.0"
__author__ = "Vianney Mixtur"
__contact__ = "prenom.nom@outlook.fr"
__copyright__ = "Copyright © 2022 Vianney Mixtur"
Expand Down
2 changes: 1 addition & 1 deletion monggregate/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class Config(pyd.BaseConfig):
allow_population_by_field_name = True
underscore_attrs_are_private = True
smart_union = True
alias_generator = camelize
#alias_generator = camelize


def isbasemodel(instance:Any)->bool:
Expand Down
6 changes: 4 additions & 2 deletions monggregate/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,8 @@ def unset(self, field:str=None, fields:list[str]|None=None)->"Pipeline":

return self

if __name__ == "__main__":
if __name__ =="__main__":

pipeline = Pipeline()
pipeline = Pipeline()
pipeline.search(operator_name="text", query="test", path=["details", "id_epd", "id_serial", "name"] )

2 changes: 0 additions & 2 deletions monggregate/search/operators/compound.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,6 @@ def equals(

return self



def exists(self, type:ClauseType, path:str)->"Compound":
"""Adds an exists clause to the current compound instance."""

Expand Down
5 changes: 3 additions & 2 deletions monggregate/search/operators/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"""

from monggregate.search.operators.operator import SearchOperator
from monggregate.search.commons.fuzzy import FuzzyOptions

class Text(SearchOperator):
"""
Expand Down Expand Up @@ -66,14 +67,14 @@ class Text(SearchOperator):

query : str|list[str]
path : str | list[str]
fuzzy : dict | None = None
fuzzy : FuzzyOptions | None = None
score : dict | None = None
synonyms : str | None = None

@property
def statement(self) -> dict:

return self.resolve({
"text" : self.dict(exclude_none=True)
"text" : self.dict(exclude_none=True, by_alias=True)
})

28 changes: 16 additions & 12 deletions monggregate/stages/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def __get_constructors_map__(cls, operator_name:str)->Callable:
"""Returns appropriate constructor from operator name"""

_constructors_map = {
"autcomplete":cls.autocomplete,
"autocomplete":cls.autocomplete,
"compound":cls.compound,
"equals":cls.equals,
"exists":cls.exists,
Expand All @@ -232,7 +232,7 @@ def __get_constructors_map__(cls, operator_name:str)->Callable:
"range":cls.range,
"regex":cls.regex,
"text":cls.text,
"wilcard":cls.wildcard
"wildcard":cls.wildcard
}

return _constructors_map[operator_name]
Expand Down Expand Up @@ -289,7 +289,7 @@ def autocomplete(
fuzzy=fuzzy,
score=score,
**kwargs
).statement
)

return cls(**base_params, operator=autocomplete_statement)

Expand All @@ -316,7 +316,7 @@ def compound(
filter=filter,
minimum_should_clause=minimum_should_clause,
**kwargs
).statement
)

return cls(**base_params, operator=compound_statement)

Expand Down Expand Up @@ -344,7 +344,7 @@ def equals(
path=path,
value=value,
score=score
).statement
)

return cls(**base_params, operator=equals_statement)

Expand All @@ -362,7 +362,7 @@ def exists(cls, path:str, **kwargs:Any)->Self:
"""

base_params = SearchBase(**kwargs).dict()
exists_statement = Exists(path=path).statement
exists_statement = Exists(path=path)

return cls(**base_params, operator=exists_statement)

Expand Down Expand Up @@ -398,7 +398,7 @@ def more_like_this(cls, like:dict|list[dict], **kwargs:Any)->Self:
"""

base_params = SearchBase(**kwargs).dict()
more_like_this_stasement = MoreLikeThis(like=like).statement
more_like_this_stasement = MoreLikeThis(like=like)

return cls(**base_params, operator=more_like_this_stasement)

Expand Down Expand Up @@ -433,7 +433,7 @@ def range(
lt=lt,
lte=lte,
score=score
).statement
)

return cls(**base_params, operator=range_statement)

Expand Down Expand Up @@ -461,7 +461,7 @@ def regex(
path=path,
allow_analyzed_field=allow_analyzed_field,
score=score
).statement
)

return cls(**base_params, operator=regex_statement)

Expand All @@ -488,15 +488,17 @@ def text(
"""

base_params = SearchBase(**kwargs).dict()
cls.__reduce_kwargs(kwargs)

text_statement = Text(
query=query,
path=path,
score=score,
fuzzy=fuzzy,
synonyms=synonyms
).statement
)

return Search(**base_params, operator=text_statement)
return cls(**base_params, operator=text_statement)

@classmethod
def wildcard(
Expand All @@ -517,12 +519,14 @@ def wildcard(
"""

base_params = SearchBase(**kwargs).dict()
cls.__reduce_kwargs(kwargs)

wilcard_statement = Wilcard(
query=query,
path=path,
allow_analyzed_field=allow_analyzed_field,
score=score
).statement
)

return cls(**base_params, operator=wilcard_statement)

Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "monggregate"
version = "0.14.1"
version = "0.15.0"
description = "MongoDB aggregation pipelines made easy. Joins, grouping, counting and much more..."
readme = "README.md"
authors = [{ name = "Vianney Mixtur", email = "vianney.mixtur@outlook.fr" }]
Expand Down Expand Up @@ -35,7 +35,7 @@ dev = ["bumpver", "pytest", "mypy", "pylint"]
Homepage = "https://github.com/VianneyMI/monggregate"

[tool.bumpver]
current_version = "0.14.1"
current_version = "0.15.0"
version_pattern = "MAJOR.MINOR.PATCH"
commit_message = "bump version {old_version} -> {new_version}"
commit = true
Expand Down
8 changes: 7 additions & 1 deletion test/test_search_operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from monggregate.base import pyd
from monggregate.search.operators import(
Autocomplete,
Compound,
Equals,
Exists,
MoreLikeThis,
Expand All @@ -22,7 +23,7 @@ class TestSearchOperators:
"""This class only aims at reusing the markers"""

def test_autocomplete(self)->None:
"""Test the autocomplete operator"""
"""Tests the autocomplete operator"""

# generate test
# --------------
Expand Down Expand Up @@ -57,6 +58,11 @@ def test_autocomplete(self)->None:
}
}

# def test_compound(self)->None:
# """Tests the compound operator"""

# autocomplete = Autocomplete()

def test_equals(self)->None:
"""Tests the equals operator"""

Expand Down
Loading

0 comments on commit aa9634b

Please sign in to comment.