Skip to content

fix not search #138

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Changelog
5.8.1 (unreleased)
------------------

- Fix Searches with "not" in a KeywordIndex do not return records that do not contain a value for the index
[mamico]
- Fix issue with event search in @querystring-search override:
converting a timezone-aware DateTime to utcdatetime causes a problem when searching for
"today", as it shifts start=day x at 00:00 to start=day x-1 at 22:00 in GMT+2 timezone.
Expand Down
22 changes: 17 additions & 5 deletions src/redturtle/volto/monkey.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,9 @@ def search_for_similar(*args, **kwargs):

original_obj = args and args[0] or None

if (
os.environ.get("REDTURTLE_VOLTO_ENABLE_SEARCH_FOR_SIMILAR", default=None)
and original_obj # noqa
):
return original_obj._old_search_for_similar()
if os.environ.get("REDTURTLE_VOLTO_ENABLE_SEARCH_FOR_SIMILAR"):
if original_obj:
return original_obj._old_search_for_similar()

return []

Expand All @@ -217,3 +215,17 @@ def plone_restapi_blocks_linkintegrity_blocksretriever_retrieveLinks(self):
):
links |= set(handler(block))
return links


def _get_object_keywords(self, obj, attr):
"""Products.PluginIndexes.KeywordIndex.KeywordIndex.KeywordIndex._get_object_keywords patch

See: https://github.com/zopefoundation/Products.ZCatalog/issues/148
https://github.com/zopefoundation/Products.ZCatalog/pull/158
"""
# indexes that we want to use with not queries
keywords = self._old__get_object_keywords(obj, attr)
if attr in ("Subject",):
if not keywords and hasattr(obj, attr):
return ("__empty__",)
return keywords
10 changes: 9 additions & 1 deletion src/redturtle/volto/monkey.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,15 @@
original="search_for_similar"
replacement=".monkey.search_for_similar"
class="plone.app.redirector.browser.FourOhFourView"
description="Cancel the seach_for_similiar call when usin volto frontend"
description="Cancel the search_for_similiar call when using volto frontend"
preserveOriginal="True"
/>

<monkey:patch
original="_get_object_keywords"
replacement=".monkey._get_object_keywords"
class="Products.PluginIndexes.KeywordIndex.KeywordIndex.KeywordIndex"
description="Manage empty keywords for not queries"
preserveOriginal="True"
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def parse_event_dates(self, parsed_query):

def get_datetime_value(self, value):
if isinstance(value, DateTime):
# return value.utcdatetime()
# return value.utcdatetime()
# manteniamo il possibile timezone
return value.asdatetime()
return datetime.fromisoformat(value)
Expand Down
Loading