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

Create string search operator #148

Closed
wants to merge 3 commits into from
Closed
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
8 changes: 8 additions & 0 deletions plone/app/querystring/profiles.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,12 @@
directory="profiles/upgrades/to_14"
/>

<genericsetup:registerProfile
name="upgrade_to_15"
title="Querystring Upgrade profile to v15"
description=""
provides="Products.GenericSetup.interfaces.EXTENSION"
directory="profiles/upgrades/to_15"
/>

</configure>
2 changes: 1 addition & 1 deletion plone/app/querystring/profiles/default/metadata.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<metadata>
<version>14</version>
<version>15</version>
<dependencies>
<dependency>profile-plone.app.registry:default</dependency>
</dependencies>
Expand Down
9 changes: 9 additions & 0 deletions plone/app/querystring/profiles/default/registry.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,14 @@
<value key="operation">plone.app.querystring.queryparser._contains</value>
<value key="widget">StringWidget</value>
</records>

<records interface="plone.app.querystring.interfaces.IQueryOperation"
prefix="plone.app.querystring.operation.string.search">
<value key="title" i18n:translate="">Search</value>
<value key="description"></value>
<value key="operation">plone.app.querystring.queryparser._search</value>
<value key="widget">StringWidget</value>
</records>

<records interface="plone.app.querystring.interfaces.IQueryOperation"
prefix="plone.app.querystring.operation.string.currentUser"
Expand Down Expand Up @@ -795,6 +803,7 @@
<value key="sortable">False</value>
<value key="operations">
<element>plone.app.querystring.operation.string.contains</element>
<element>plone.app.querystring.operation.string.search</element>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So if an editor is configuring a search block and adds a criterion with the SearchableText index, they'll have to pick between "Contains" or "Search" as the operation. That seems like bad UX since it's not clear why to choose one or the other.

If you need this for integration with elasticsearch, wouldn't it make more sense for your elasticsearch integration package or your policy package to add this operation (and probably remove the other one)?

</value>
<value key="group"
i18n:translate=""
Expand Down
23 changes: 23 additions & 0 deletions plone/app/querystring/profiles/upgrades/to_15/registry.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<registry xmlns:i18n="http://xml.zope.org/namespaces/i18n"
i18n:domain="plone"
>
<records interface="plone.app.querystring.interfaces.IQueryOperation"
prefix="plone.app.querystring.operation.string.search">
<value key="title" i18n:translate="">Search</value>
<value key="description"></value>
<value key="operation">plone.app.querystring.queryparser._search</value>
<value key="widget">StringWidget</value>
</records>

<records interface="plone.app.querystring.interfaces.IQueryField"
prefix="plone.app.querystring.field.SearchableText"
purge="False"
>
<value key="operations"
purge="False"
>
<element>plone.app.querystring.operation.string.search</element>
</value>
</records>
</registry>
7 changes: 6 additions & 1 deletion plone/app/querystring/querybuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,14 @@ def number_of_results(self, query):

def filter_query(self, query):
text = query.get("SearchableText", None)
munge = True
if isinstance(text, dict):
if text.get("operator", "") == "search":
munge = False
# catalog searches don't accept the operator key so remove it
del text["operator"]
text = text.get("query", "")
if text:
if text and munge:
query["SearchableText"] = self.munge_search_term(text)
return query

Expand Down
3 changes: 3 additions & 0 deletions plone/app/querystring/queryparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ def parseAndModifyFormquery(context, query, sort_on=None, sort_order=None):
def _contains(context, row):
return _equal(context, row)

def _search(context, row):
return {row.index: {'query': row.values, 'operator': 'search' }}


def _excludes(context, row):
return {row.index: {"not": row.values}}
Expand Down
10 changes: 10 additions & 0 deletions plone/app/querystring/upgrades.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,16 @@
title="Add new 'string.isNot' and 'selection.none' query operators."
import_profile="plone.app.querystring:upgrade_to_14"
/>
</genericsetup:upgradeSteps>
<genericsetup:upgradeSteps
profile="plone.app.querystring:default"
source="14"
destination="15"
>
<genericsetup:upgradeDepends
title="Add new 'string.search' query operator."
import_profile="plone.app.querystring:upgrade_to_15"
/>
</genericsetup:upgradeSteps>

</configure>
Loading