Bug 1635923 - Implement multiword search for address book sidebar / select addresses dialog. r=frg
authorIan Neal <iann_cvs@blueyonder.co.uk>
Wed, 06 May 2020 17:50:17 +0100
changeset 39223 f349036e7311c828d5602a6791b15098a01537a2
parent 39222 1bf6acb1b68d7be1abf704192a83f96759362f36
child 39224 4bf4b3ce8d53355b8d02452c9d1b99da0fac95d0
push id402
push userclokep@gmail.com
push dateMon, 29 Jun 2020 20:48:04 +0000
reviewersfrg
bugs1635923, 1000775, 1091675
Bug 1635923 - Implement multiword search for address book sidebar / select addresses dialog. r=frg Port the relevant parts of the following bugs to SeaMonkey: * Bug 1000775 - For AB Quicksearch / contacts side bar, implement split multiword search pattern * Bug 1091675 - Implement quoting to disable multi-word search in addressbook
suite/mailnews/components/addrbook/content/abSelectAddressesDialog.js
suite/mailnews/components/addrbook/content/addressbook.js
--- a/suite/mailnews/components/addrbook/content/abSelectAddressesDialog.js
+++ b/suite/mailnews/components/addrbook/content/abSelectAddressesDialog.js
@@ -355,25 +355,27 @@ function OnReturnHit(event)
 function onEnterInSearchBar()
 {
   var selectedNode = abList.selectedItem;
 
   if (!selectedNode)
     return;
 
   if (!gQueryURIFormat) {
-    // Get model query from pref, without preceding "?", so we need to add it again
-    gQueryURIFormat = "?" + getModelQuery("mail.addr_book.quicksearchquery.format");
+    // Get model query from pref. We don't want the query starting with "?"
+    // as we have to prefix "?and" to this format.
+    gQueryURIFormat = getModelQuery("mail.addr_book.quicksearchquery.format");
   }
 
   var searchURI = selectedNode.value;
 
-  if (gSearchInput.value != "") {
-    searchURI += gQueryURIFormat.replace(/@V/g, encodeABTermValue(gSearchInput.value));
-  }
+  // Use helper method to split up search query to multi-word search
+  // query against multiple fields.
+  let searchWords = getSearchTokens(gSearchInput.value);
+  searchURI += generateQueryURI(gQueryURIFormat, searchWords);
 
   SetAbView(searchURI);
 
   SelectFirstCard();
 }
 
 function DirPaneSelectionChangeMenulist()
 {
--- a/suite/mailnews/components/addrbook/content/addressbook.js
+++ b/suite/mailnews/components/addrbook/content/addressbook.js
@@ -382,32 +382,33 @@ function onAdvancedAbSearch()
                       {directory: selectedDirURI});
 }
 
 function onEnterInSearchBar()
 {
   ClearCardViewPane();
 
   if (!gQueryURIFormat) {
-    // Get model query from pref, without preceding "?", so we need to add it again
-    gQueryURIFormat = "?" + getModelQuery("mail.addr_book.quicksearchquery.format");
+    // Get model query from pref. We don't want the query starting with "?"
+    // as we have to prefix "?and" to this format.
+    gQueryURIFormat = getModelQuery("mail.addr_book.quicksearchquery.format");
   }
+
   let searchURI = getSelectedDirectoryURI();
   if (!searchURI) return;
 
   /*
    XXX todo, handle the case where the LDAP url
    already has a query, like
    moz-abldapdirectory://nsdirectory.netscape.com:389/ou=People,dc=netscape,dc=com?(or(Department,=,Applications))
   */
-  if (gSearchInput.value != "") {
-    // replace all instances of @V with the escaped version
-    // of what the user typed in the quick search text input
-    searchURI += gQueryURIFormat.replace(/@V/g, encodeABTermValue(gSearchInput.value));
-  }
+  // Use helper method to split up search query to multi-word search
+  // query against multiple fields.
+  let searchWords = getSearchTokens(gSearchInput.value);
+  searchURI += generateQueryURI(gQueryURIFormat, searchWords);
 
   SetAbView(searchURI);
 
   // XXX todo
   // this works for synchronous searches of local addressbooks,
   // but not for LDAP searches
   SelectFirstCard();
 }