Commit a784d89e authored by Jérome Perrin's avatar Jérome Perrin

mysql_innodb_catalog: new subject_set scriptable key

Allows searching the catalog for documents having an exact set of
subjects, not just one subject.
In other words, `portal_catalog(subject=["a", "b"])` finds documents
with subject a or subject b and `portal_catalog(subject_set=["a, "b"])`
finds documents with subject a and subject b.
parent 505f14c9
Pipeline #31330 failed with stage
in 0 seconds
......@@ -2561,6 +2561,37 @@ return 1
self.assertEqual(len(subject_result), 1)
self.assertEqual(subject_result[0].getPath(), document.getPath())
def test_subject_set(self):
subject_none = self.portal.document_module.newContent(
id='none', portal_type='Presentation')
subject_1 = self.portal.document_module.newContent(
id='subject_1',
portal_type='Presentation',
subject_list=('subject1', ))
subject_12 = self.portal.document_module.newContent(
id='subject_12',
portal_type='Presentation',
subject_list=('subject1', 'subject2'))
subject_123 = self.portal.document_module.newContent(
id='subject_123',
portal_type='Presentation',
subject_list=('subject1', 'subject2', 'subject3'))
self.tic()
def search(subject_set):
return sorted(
[b.getObject() for b in self.portal.portal_catalog(subject_set=subject_set)],
key=lambda o: o.getId())
self.assertEqual(search(('subject1', 'subject2', 'subject3')), [subject_123])
self.assertEqual(search(('subject2', 'subject3', 'subject1')), [subject_123])
self.assertEqual(search(('subject1', 'subject2')), [subject_12, subject_123])
self.assertEqual(search(('subject2', )), [subject_12, subject_123])
self.assertEqual(search(('nothing match',)), [])
self.assertEqual(search(None), [])
# keyword search does not work with this key
self.assertEqual(search(('subject%',)), [])
def test_base_convertable_uses_pdata_for_base_data(self):
document = self.portal.document_module.newContent(
portal_type='Spreadsheet',
......
sql_catalog = context.getPortalObject().portal_catalog.getSQLCatalog()
if value:
subject_uid_list = [
b.subject_set_uid for b in
sql_catalog.SQLCatalog_zGetSubjectSetUid(subject_list=value)
]
if subject_uid_list:
return sql_catalog.buildQuery({
"versioning.subject_set_uid": subject_uid_list,
})
# query matching nothing
return sql_catalog.buildQuery({
"uid": -1,
})
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Python Script" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="_reconstructor" module="copy_reg"/>
</klass>
<tuple>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
<global name="object" module="__builtin__"/>
<none/>
</tuple>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_local_properties</string> </key>
<value>
<tuple>
<dictionary>
<item>
<key> <string>id</string> </key>
<value> <string>reference</string> </value>
</item>
<item>
<key> <string>type</string> </key>
<value> <string>string</string> </value>
</item>
</dictionary>
</tuple>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>value</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SQLCatalog_makeSubjectSetQuery</string> </value>
</item>
<item>
<key> <string>reference</string> </key>
<value> <string>7</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value>
<none/>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
SELECT subject_set_uid
FROM subject
WHERE <dtml-sqltest subject_list column="subject" type="string" multiple>
GROUP BY subject_set_uid
HAVING COUNT(DISTINCT subject) = <dtml-var expr="_.len(subject_list)">
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="SQL Method" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>allow_simple_one_argument_traversal</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>arguments_src</string> </key>
<value> <string>subject_list</string> </value>
</item>
<item>
<key> <string>class_file_</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>class_name_</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>connection_id</string> </key>
<value> <string>erp5_sql_connection</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>SQLCatalog_zGetSubjectSetUid</string> </value>
</item>
<item>
<key> <string>max_cache_</string> </key>
<value> <int>100</int> </value>
</item>
<item>
<key> <string>max_rows_</string> </key>
<value> <int>1000</int> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>SQLCatalog_zGetSubjectSetUid</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -3,6 +3,7 @@
<key>full_text | SQLCatalog_makeFullTextQuery</key>
<key>quick_search_text | SQLCatalog_makeQuickSearchQuery</key>
<key>search_text | SQLCatalog_makeSearchTextQuery</key>
<key>subject_set | SQLCatalog_makeSubjectSetQuery</key>
<key>translated_causality_state | SQLCatalog_makeTranslatedCausalityStateQuery</key>
<key>translated_causality_state_title | SQLCatalog_makeTranslatedCausalityStateTitleQuery</key>
<key>translated_opportunity_state | SQLCatalog_makeTranslatedOpportunityStateQuery</key>
......
......@@ -3,6 +3,7 @@ erp5_mysql_innodb/SQLCatalog_catalogTransformationList
erp5_mysql_innodb/SQLCatalog_getDocumentValueList
erp5_mysql_innodb/SQLCatalog_makeQuickSearchQuery
erp5_mysql_innodb/SQLCatalog_makeSearchTextQuery
erp5_mysql_innodb/SQLCatalog_makeSubjectSetQuery
erp5_mysql_innodb/SQLCatalog_makeTranslatedCausalityStateQuery
erp5_mysql_innodb/SQLCatalog_makeTranslatedCausalityStateTitleQuery
erp5_mysql_innodb/SQLCatalog_makeTranslatedOpportunityStateQuery
......@@ -15,6 +16,7 @@ erp5_mysql_innodb/SQLCatalog_makeTranslatedValidationStateQuery
erp5_mysql_innodb/SQLCatalog_makeTranslatedValidationStateTitleQuery
erp5_mysql_innodb/SQLCatalog_makeTranslationQuery
erp5_mysql_innodb/SQLCatalog_zGetDocumentValueList
erp5_mysql_innodb/SQLCatalog_zGetSubjectSetUid
erp5_mysql_innodb/SQLCatalog_zSearchTranslation
erp5_mysql_innodb/z0_drop_alarm
erp5_mysql_innodb/z0_drop_catalog
......
subject_set | SQLCatalog_makeSubjectSetQuery
quick_search_text | SQLCatalog_makeQuickSearchQuery
advanced_search_text | SQLCatalog_makeQuickSearchQuery
full_text | SQLCatalog_makeFullTextQuery
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment