From 0d0bf21d7bf7eeb271de10d6f1f1d41bb7c92488 Mon Sep 17 00:00:00 2001
From: Ivan Tyagov <ivan@nexedi.com>
Date: Mon, 28 Feb 2011 11:40:16 +0000
Subject: [PATCH] Deprecate 'advanced_search_text' &'quick_search_text'
 scriptable key. Add 'search_text' scriptable key.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@43796 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../SQLCatalog_makeQuickSearchQuery.xml       |  19 +--
 ...talog_makeSearchTextQuery.catalog_keys.xml |   2 +
 .../SQLCatalog_makeSearchTextQuery.xml        | 124 ++++++++++++++++++
 .../scriptable_key_list.xml                   |   1 +
 .../erp5_mysql_innodb_catalog/bt/change_log   |   4 +
 .../erp5_mysql_innodb_catalog/bt/revision     |   2 +-
 .../bt/template_catalog_method_id_list        |   1 +
 .../bt/template_catalog_scriptable_key_list   |   3 +-
 8 files changed, 140 insertions(+), 16 deletions(-)
 create mode 100644 product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/SQLCatalog_makeSearchTextQuery.catalog_keys.xml
 create mode 100644 product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/SQLCatalog_makeSearchTextQuery.xml

diff --git a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/SQLCatalog_makeQuickSearchQuery.xml b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/SQLCatalog_makeQuickSearchQuery.xml
index f250b3f5ab..986e2c3baa 100644
--- a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/SQLCatalog_makeQuickSearchQuery.xml
+++ b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/SQLCatalog_makeQuickSearchQuery.xml
@@ -50,21 +50,12 @@
         </item>
         <item>
             <key> <string>_body</string> </key>
-            <value> <string>from Products.ZSQLCatalog.SQLCatalog import Query\n
-from Products.ZSQLCatalog.SQLCatalog import ComplexQuery\n
+            <value> <string>from Products.ERP5Type.Log import log\n
+from Products.ZSQLCatalog.SQLCatalog import Query\n
 \n
-if container.isAdvancedSearchText(value):\n
-  # the text which was provided is not a simple value\n
-  # and contains predicates such as portal_type:\n
-  query = Query(SearchableText=value)\n
-else:\n
-  query = ComplexQuery(Query(title=value),\n
-                       Query(reference=value),\n
-                       Query(source_reference=value),\n
-                       Query(destination_reference=value),\n
-                       Query(SearchableText=value),\n
-                       operator="OR")\n
-return query\n
+# warn by logging (not possible use python\'s warn module in restricted environment)\n
+log("\'quick_search_text\' and \'advanced_search_text\' scriptable keys are deprecated. Use \'search_text\' instead.")\n
+return Query(search_text=value)\n
 </string> </value>
         </item>
         <item>
diff --git a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/SQLCatalog_makeSearchTextQuery.catalog_keys.xml b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/SQLCatalog_makeSearchTextQuery.catalog_keys.xml
new file mode 100644
index 0000000000..a540f9431e
--- /dev/null
+++ b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/SQLCatalog_makeSearchTextQuery.catalog_keys.xml
@@ -0,0 +1,2 @@
+<catalog_method>
+</catalog_method>
diff --git a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/SQLCatalog_makeSearchTextQuery.xml b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/SQLCatalog_makeSearchTextQuery.xml
new file mode 100644
index 0000000000..ada90d95f5
--- /dev/null
+++ b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogMethodTemplateItem/portal_catalog/erp5_mysql_innodb/SQLCatalog_makeSearchTextQuery.xml
@@ -0,0 +1,124 @@
+<?xml version="1.0"?>
+<ZopeData>
+  <record id="1" aka="AAAAAAAAAAE=">
+    <pickle>
+      <global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
+    </pickle>
+    <pickle>
+      <dictionary>
+        <item>
+            <key> <string>Script_magic</string> </key>
+            <value> <int>3</int> </value>
+        </item>
+        <item>
+            <key> <string>_bind_names</string> </key>
+            <value>
+              <object>
+                <klass>
+                  <global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
+                </klass>
+                <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>_body</string> </key>
+            <value> <string encoding="cdata"><![CDATA[
+
+"""\n
+  Search text query generator. Accepts a string and returns a ComplexQuery.\n
+  For example:\n
+\n
+  search_text = DMS reference:bt5-dms version:001 language:bg mine:yes (portal_type:Presentation OR portal_type:File) created:12m contributor_title:%tyagov%\n
+  \n
+  will parse search_text and generate a complexQuery which will return all documents which:\n
+  - have full_text searchable text containing "DMS"\n
+  - have reference equal to bt5-dms\n
+  - have portal_type "Presentation" OR "File"\n
+  - are created within last 12 months\n
+  - are owned by current logged in user\n
+  - are contributed by given Person\'s title\n
+  - etc ..\n
+"""\n
+from Products.ZSQLCatalog.SQLCatalog import Query, ComplexQuery, SimpleQuery\n
+\n
+parsed_dict = context.Base_parseSearchString(value)\n
+full_text = parsed_dict.pop(\'searchabletext\')\n
+\n
+#context.log(parsed_dict)\n
+\n
+# use full_text scriptable key!\n
+query_list = [Query(**{\'full_text\': full_text})]\n
+\n
+# XXX: "newest" ?\n
+# XXX: get known columns rather than hard-code \n
+for key in (\'reference\', \'version\', \'language\', \'portal_type\', \'contributor_title\'):\n
+  value = parsed_dict.get(key, None)\n
+  if value is not None:\n
+    query_list.append(Query(**{key: value}))\n
+\n
+# user wants only his documents\n
+if parsed_dict.get(\'mine\', None) is not None:\n
+  query_list.append(Query(**{\'owner\': str(context.portal_membership.getAuthenticatedMember())}))\n
+\n
+creation_from = parsed_dict.get(\'creation_from\', None)\n
+creation_to = parsed_dict.get(\'creation_to\', None)\n
+modification_from = parsed_dict.get(\'modification_from\', None)\n
+modification_to = parsed_dict.get(\'modification_to\', None)\n
+\n
+if creation_from is not None:\n
+  query_list.append(SimpleQuery(**{\'catalog.creation_date\': creation_from, \n
+                                   \'comparison_operator\': \'>=\'}))\n
+if creation_to is not None:\n
+  query_list.append(SimpleQuery(**{\'catalog.creation_date\': creation_to, \n
+                                   \'comparison_operator\': \'=<\'}))\n
+if modification_from is not None:\n
+  query_list.append(SimpleQuery(**{\'catalog.modification_date\': modification_from, \n
+                                   \'comparison_operator\': \'>=\'}))\n
+if modification_to is not None:\n
+  query_list.append(SimpleQuery(**{\'catalog.modification_date\': modification_to, \n
+                                   \'comparison_operator\': \'<=\'}))\n
+return ComplexQuery(query_list, operator="AND")\n
+
+
+]]></string> </value>
+        </item>
+        <item>
+            <key> <string>_params</string> </key>
+            <value> <string>value</string> </value>
+        </item>
+        <item>
+            <key> <string>id</string> </key>
+            <value> <string>SQLCatalog_makeSearchTextQuery</string> </value>
+        </item>
+      </dictionary>
+    </pickle>
+  </record>
+</ZopeData>
diff --git a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogScriptableKeyTemplateItem/scriptable_key_list.xml b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogScriptableKeyTemplateItem/scriptable_key_list.xml
index 01f1277591..264b137653 100644
--- a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogScriptableKeyTemplateItem/scriptable_key_list.xml
+++ b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/CatalogScriptableKeyTemplateItem/scriptable_key_list.xml
@@ -2,4 +2,5 @@
  <key>advanced_search_text | SQLCatalog_makeQuickSearchQuery</key>
  <key>full_text | SQLCatalog_makeFullTextQuery</key>
  <key>quick_search_text | SQLCatalog_makeQuickSearchQuery</key>
+ <key>search_text | SQLCatalog_makeSearchTextQuery</key>
 </key_list>
\ No newline at end of file
diff --git a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/bt/change_log b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/bt/change_log
index 7474eacc5a..c8d618ee09 100644
--- a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/bt/change_log
+++ b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/bt/change_log
@@ -1,3 +1,7 @@
+2011-02-28 Ivan
+* Deprecate 'advanced_search_text' &'quick_search_text' scriptable key
+* Add 'search_text' scriptable key
+
 2011-02-04 Nicolas
 * add children_reference related column
 
diff --git a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/bt/revision b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/bt/revision
index aebfaa171d..0acdeb509d 100644
--- a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/bt/revision
+++ b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/bt/revision
@@ -1 +1 @@
-214
\ No newline at end of file
+216
\ No newline at end of file
diff --git a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/bt/template_catalog_method_id_list b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/bt/template_catalog_method_id_list
index 9271c04a01..d8032dddfa 100644
--- a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/bt/template_catalog_method_id_list
+++ b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/bt/template_catalog_method_id_list
@@ -2,6 +2,7 @@ erp5_mysql_innodb/SQLCatalog_catalogTransformation
 erp5_mysql_innodb/SQLCatalog_catalogTransformationList
 erp5_mysql_innodb/SQLCatalog_makeFullTextQuery
 erp5_mysql_innodb/SQLCatalog_makeQuickSearchQuery
+erp5_mysql_innodb/SQLCatalog_makeSearchTextQuery
 erp5_mysql_innodb/z0_drop_alarm
 erp5_mysql_innodb/z0_drop_catalog
 erp5_mysql_innodb/z0_drop_category
diff --git a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/bt/template_catalog_scriptable_key_list b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/bt/template_catalog_scriptable_key_list
index 5cb210d590..c8f1e5bd64 100644
--- a/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/bt/template_catalog_scriptable_key_list
+++ b/product/ERP5/bootstrap/erp5_mysql_innodb_catalog/bt/template_catalog_scriptable_key_list
@@ -1,3 +1,4 @@
 quick_search_text | SQLCatalog_makeQuickSearchQuery
 advanced_search_text | SQLCatalog_makeQuickSearchQuery
-full_text | SQLCatalog_makeFullTextQuery
\ No newline at end of file
+full_text | SQLCatalog_makeFullTextQuery
+search_text | SQLCatalog_makeSearchTextQuery
\ No newline at end of file
-- 
2.30.9