Skip to content
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

Search broken with Plone 5.2rc4 because of operator #174

Closed
pbauer opened this issue Jun 24, 2019 · 7 comments
Closed

Search broken with Plone 5.2rc4 because of operator #174

pbauer opened this issue Jun 24, 2019 · 7 comments

Comments

@pbauer
Copy link
Contributor

pbauer commented Jun 24, 2019

Not all catalog-indexes support the operator option (i.e. providing the option to query using 'and' or 'or'). But when you use the Checkbox- or Multiselect-Widgets you always get that configuration-option even though the selected index may not provide this option.

Since 5.0 of Products.ZCatalog querying fails with a ValueError when a a invalid option is used. See zopefoundation/Products.ZCatalog#67 for the change by @andbag. I guess before 5.0 the option would simply have been ignored in the query.

In Plone 5.2rc4 this leads to a broken search:

2019-06-24 10:29:12,722 ERROR   [eea.facetednavigation:38][waitress] index 'portal_type': option 'operator' is not valid
Traceback (most recent call last):
  File "/Users/pbauer/workspace/step-buildout/src-mrd/eea.facetednavigation/eea/facetednavigation/browser/app/query.py", line 178, in query
    brains = catalog(self.context, **query)
  File "/Users/pbauer/workspace/step-buildout/src-mrd/eea.facetednavigation/eea/facetednavigation/search/catalog.py", line 119, in __call__
    return search(**newquery)
  File "/Users/pbauer/.cache/buildout/eggs/Products.CMFPlone-5.2rc4-py3.7.egg/Products/CMFPlone/CatalogTool.py", line 457, in searchResults
    return ZCatalog.searchResults(self, query, **kw)
  File "/Users/pbauer/.cache/buildout/eggs/Products.ZCatalog-5.0.1-py3.7.egg/Products/ZCatalog/ZCatalog.py", line 611, in searchResults
    return self._catalog.searchResults(query, **kw)
  File "/Users/pbauer/.cache/buildout/eggs/Products.ZCatalog-5.0.1-py3.7.egg/Products/ZCatalog/Catalog.py", line 1091, in searchResults
    return self.search(query, sort_indexes, reverse, sort_limit, _merge)
  File "/Users/pbauer/.cache/buildout/eggs/Products.ZCatalog-5.0.1-py3.7.egg/Products/ZCatalog/Catalog.py", line 634, in search
    rs = self._search_index(cr, index_id, query, rs)
  File "/Users/pbauer/.cache/buildout/eggs/Products.ZCatalog-5.0.1-py3.7.egg/Products/ZCatalog/Catalog.py", line 562, in _search_index
    index.operators, index.useOperator)
  File "/Users/pbauer/.cache/buildout/eggs/Products.ZCatalog-5.0.1-py3.7.egg/Products/ZCatalog/query.py", line 80, in __init__
    self.set(op, param[op])
  File "/Users/pbauer/.cache/buildout/eggs/Products.ZCatalog-5.0.1-py3.7.egg/Products/ZCatalog/query.py", line 126, in set
    ' is not valid').format(self.id, key))
ValueError: index 'portal_type': option 'operator' is not valid

I tried a workaround for that like this in eea.facetednavigation.browser.app.query.FacetedQueryHandler.criteria:

if widget_index:
    ctool = getToolByName(self.context, 'portal_faceted', None)
    if not ctool:
        ctool = getToolByName(self.context, 'portal_catalog')
    index = ctool._catalog.indexes.get(widget_index, None)
    for index_option in list(query.get(widget_index, [])):
        if index_option not in index.query_options:
            del query[widget_index][index_option]

That seemed to do the trick and worked with my updated instance but it would be much better to only offer this option if the index actually supports such a query.

@pbauer
Copy link
Contributor Author

pbauer commented Jun 24, 2019

In collective#54 I added a slightly simpler implementation of my fix.

@jensens
Copy link
Contributor

jensens commented Jun 24, 2019

I have the same issue, and will check your fix now.

@jensens
Copy link
Contributor

jensens commented Jun 24, 2019

collective#54 fixes it for me too.

@jensens
Copy link
Contributor

jensens commented Jun 24, 2019

well no, fulltext search is broken.

@jensens
Copy link
Contributor

jensens commented Jun 25, 2019

collective@2c01dcb fixes this for Text Widget.

I fear we need to check all other widgets too.

jensens pushed a commit to collective/eea.facetednavigation that referenced this issue Jun 25, 2019
jensens pushed a commit to collective/eea.facetednavigation that referenced this issue Jun 25, 2019
jensens pushed a commit to collective/eea.facetednavigation that referenced this issue Jun 25, 2019
jensens pushed a commit to collective/eea.facetednavigation that referenced this issue Jun 25, 2019
jensens pushed a commit to collective/eea.facetednavigation that referenced this issue Jun 25, 2019
jensens pushed a commit to collective/eea.facetednavigation that referenced this issue Jun 25, 2019
jensens pushed a commit to collective/eea.facetednavigation that referenced this issue Jun 26, 2019
@thet
Copy link
Contributor

thet commented Jun 29, 2019

@pbauer @jensens this could be a fix for this problem: zopefoundation/Products.ZCatalog#79

@jensens
Copy link
Contributor

jensens commented Jul 1, 2019

@thet thanks for pointing us to the issue, but no, I dont think it is related.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants