Back out changeset 93f4e62465fd (bug 1091675) for oranges. a=me
authorMagnus Melin <mkmelin+mozilla@iki.fi>
Tue, 18 Nov 2014 21:30:12 +0200
changeset 21318 d22eeb1a685aff1d5e09f9b36d3b35572b395f94
parent 21317 3071390b0e4dfc2d79e6131b9e81ed4de837d301
child 21319 a46ff2122bc83538d00c113e2a5c0dd5c6c99e9b
push id1274
push usermbanner@mozilla.com
push dateMon, 12 Jan 2015 19:54:49 +0000
treeherdercomm-beta@baea280adc1c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersme
bugs1091675
backs out93f4e62465fdaff4ab6192e98694d89557e040af
Back out changeset 93f4e62465fd (bug 1091675) for oranges. a=me
mail/components/addrbook/content/abCommon.js
mail/components/addrbook/content/abContactsPanel.js
mail/components/addrbook/content/addressbook.js
mailnews/addrbook/src/nsAbAutoCompleteSearch.js
mailnews/addrbook/test/unit/test_nsAbAutoCompleteSearch6.js
--- a/mail/components/addrbook/content/abCommon.js
+++ b/mail/components/addrbook/content/abCommon.js
@@ -602,84 +602,16 @@ function GetSelectedDirectory()
     return abList.value;
   else {
     if (gDirTree.currentIndex < 0)
       return null;
     return gDirectoryTreeView.getDirectoryAtIndex(gDirTree.currentIndex).URI;
   }
 }
 
-/**
- * There is an exact replica of this method in mailnews/.
- * We need to remove this duplication with the help of a jsm in mailnews/
- *
- * Parse the multiword search string to extract individual search terms
- * (separated on the basis of spaces) or quoted exact phrases to search
- * against multiple fields of the addressbook cards.
- *
- * @param aSearchString The full search string entered by the user.
- *
- * @return an array of separated search terms from the full search string.
- */
-function getSearchTokens(aSearchString)
-{
-  let searchString = aSearchString.trim();
-  if (searchString == "")
-    return searchString;
-
-  let quotedTerms = [];
-
-  // Split up multiple search words to create a *foo* and *bar* search against
-  // search fields, using the OR-search template from modelQuery for each word.
-  // If the search query has quoted terms as "foo bar", extract them as is.
-  let startIndex;
-  while ((startIndex = searchString.indexOf('"')) != -1) {
-    let endIndex = searchString.indexOf('"', startIndex + 1);
-    if (endIndex == -1)
-      endIndex = searchString.length;
-
-    quotedTerms.push(searchString.substring(startIndex + 1, endIndex));
-    let query = searchString.substring(0, startIndex);
-    if (endIndex < searchString.length)
-      query += searchString.substr(endIndex + 1);
-
-    searchString = query.trim();
-  }
-
-  let searchWords = [];
-  if (searchString.length != 0) {
-    searchWords = quotedTerms.concat(searchString.split(/\s+/));
-  } else {
-    searchWords = quotedTerms;
-  }
-
-  return searchWords;
-}
-
-/*
- * Given a database model query and a list of search tokens,
- * return query URI.
- *
- * @param aModelQuery database model query
- * @param aSearchWords an array of search tokens.
- *
- * @return query URI.
- */
-function generateQueryURI(aModelQuery, aSearchWords)
-{
-  let queryURI = "";
-  aSearchWords.forEach(searchWord =>
-    queryURI += aModelQuery.replace(/@V/g, encodeABTermValue(searchWord)));
-
-  // queryURI has all the (or(...)) searches, link them up with (and(...)).
-  queryURI = "?(and" + queryURI + ")";
-
-  return queryURI;
-}
-
 function onAbClearSearch()
 {
   var searchInput = document.getElementById("peopleSearchInput");
   if (searchInput)
     searchInput.value = "";
   onEnterInSearchBar();
 }
 
--- a/mail/components/addrbook/content/abContactsPanel.js
+++ b/mail/components/addrbook/content/abContactsPanel.js
@@ -149,17 +149,22 @@ function onEnterInSearchBar()
 
     // Remove the preceeding '?' as we have to prefix "?and" to this format.
     gQueryURIFormat = gQueryURIFormat.slice(1);
   }
 
   var searchURI = GetSelectedDirectory();
   var searchInput = document.getElementById("peopleSearchInput");
 
-  // Use helper method to split up search query to multi-word search
-  // query against multiple fields.
-  if (searchInput) {
-    let searchWords = getSearchTokens(searchInput.value);
-    searchURI += generateQueryURI(gQueryURIFormat, searchWords);
+  // Split up multiple search words to create a *foo* and *bar* search against
+  // search fields, using the OR-search template from gQueryURIFormat for each word.
+  if (searchInput.value != "") {
+    let searchWords = searchInput.value.trim().split(/\s+/);
+    let queryURI = "";
+    searchWords.forEach(searchWord =>
+      queryURI += gQueryURIFormat.replace(/@V/g, encodeABTermValue(searchWord)));
+
+   // queryURI has all the (or(...)) searches, link them up with (and(...)).
+    searchURI += "?(and" + queryURI + ")";
   }
 
   SetAbView(searchURI);
 }
--- a/mail/components/addrbook/content/addressbook.js
+++ b/mail/components/addrbook/content/addressbook.js
@@ -514,21 +514,26 @@ function onEnterInSearchBar()
   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))
   */
   var searchInput = document.getElementById("peopleSearchInput");
-  // Use helper method to split up search query to multi-word search
-  // query against multiple fields.
-  if (searchInput) {
-    let searchWords = getSearchTokens(searchInput.value);
-    searchURI += generateQueryURI(gQueryURIFormat, searchWords);
+  if (searchInput && searchInput.value != "") {
+    // Split up multiple search words to create a *foo* and *bar* search against
+    // search fields, using the OR-search template from gQueryURIFormat for each word.
+    let searchWords = searchInput.value.trim().split(/\s+/);
+    let queryURI = "";
+    searchWords.forEach(searchWord =>
+      queryURI += gQueryURIFormat.replace(/@V/g, encodeABTermValue(searchWord)));
+
+    // queryURI has all the (or(...)) searches, link them up with (and(...)).
+    searchURI += "?(and" + queryURI + ")";
   }
 
   SetAbView(searchURI);
 
   // XXX todo
   // this works for synchronous searches of local addressbooks,
   // but not for LDAP searches
   SelectFirstCard();
--- a/mailnews/addrbook/src/nsAbAutoCompleteSearch.js
+++ b/mailnews/addrbook/src/nsAbAutoCompleteSearch.js
@@ -329,19 +329,18 @@ nsAbAutoCompleteSearch.prototype = {
     // entering multiple addresses.
     if (!fullString || aSearchString.contains(",")) {
       result.searchResult = ACR.RESULT_IGNORED;
       aListener.onSearchResult(this, result);
       return;
     }
 
     // Array of all the terms from the fullString search query
-    // (separated on the basis of spaces or exact terms on the
-    // basis of quotes).
-    let searchWords = getSearchTokens(fullString);
+    // (separated on the basis of spaces).
+    let searchWords = fullString.split(/\s+/);
 
     // Find out about the comment column
     try {
       this._commentColumn = Services.prefs.getIntPref("mail.autoComplete.commentColumn");
     } catch(e) { }
 
     if (aPreviousResult instanceof nsIAbAutoCompleteResult &&
         aSearchString.startsWith(aPreviousResult.searchString) &&
@@ -367,24 +366,24 @@ nsAbAutoCompleteSearch.prototype = {
     {
       // Construct the search query; using a query means we can optimise
       // on running the search through c++ which is better for string
       // comparisons (_checkEntry is relatively slow).
       // When user's fullstring search expression is a multiword query, search
       // for each word separately so that each result contains all the words
       // from the fullstring in the fields of the addressbook card
       // (see bug 558931 for explanations).
+      let searchQuery = "";
       let modelQuery = "(or(DisplayName,c,@V)(FirstName,c,@V)(LastName,c,@V)" +
                        "(NickName,c,@V)(PrimaryEmail,c,@V)(SecondEmail,c,@V)" +
                        "(and(IsMailList,=,TRUE)(Notes,c,@V)))";
-      // Use helper method to split up search query to multi-word search
-      // query against multiple fields.
-      let searchWords = getSearchTokens(fullString);
-      let searchQuery = generateQueryURI(modelQuery, searchWords);
-
+      for (let searchWord of searchWords) {
+        searchQuery += modelQuery.replace(/@V/g, encodeABTermValue(searchWord));
+      }
+      searchQuery = "?(and" + searchQuery + ")";
       // Now do the searching
       let allABs = this._abManager.directories;
 
       // We're not going to bother searching sub-directories, currently the
       // architecture forces all cards that are in mailing lists to be in ABs as
       // well, therefore by searching sub-directories (aka mailing lists) we're
       // just going to find duplicates.
       while (allABs.hasMoreElements()) {
@@ -430,81 +429,12 @@ nsAbAutoCompleteSearch.prototype = {
  * The '(' and ')' characters are special for the addressbook
  * search query language, but are not escaped in encodeURIComponent()
  * so it must be done manually on top of it.
  */
 function encodeABTermValue(aString) {
   return encodeURIComponent(aString).replace(/\(/g, "%28").replace(/\)/g, "%29");
 }
 
-/**
- * This is an exact replica of the method in abCommon.js and needs to
- * be merged to remove this duplication.
- *
- * Parse the multiword search string to extract individual search terms
- * (separated on the basis of spaces) or quoted exact phrases to search
- * against multiple fields of the addressbook cards.
- *
- * @param aSearchString The full search string entered by the user.
- *
- * @return  an array of separated search terms from the full search string.
- */
-function getSearchTokens(aSearchString)
-{
-  let searchString = aSearchString.trim();
-
-  if (searchString == "")
-    return searchString;
-
-  let quotedTerms = [];
-
-  // Split up multiple search words to create a *foo* and *bar* search against
-  // search fields, using the OR-search template from modelQuery for each word.
-  // If the search query has quoted terms as "foo bar", extract them as is.
-  let startIndex;
-  while ((startIndex = searchString.indexOf('"')) != -1) {
-    let endIndex = searchString.indexOf('"', startIndex + 1);
-    if (endIndex == -1)
-      endIndex = searchString.length;
-
-    quotedTerms.push(searchString.substring(startIndex + 1, endIndex));
-    let query = searchString.substring(0, startIndex);
-    if (endIndex < searchString.length)
-      query += searchString.substr(endIndex + 1);
-
-    searchString = query.trim();
-  }
-
-  let searchWords = [];
-  if (searchString.length != 0) {
-    searchWords = quotedTerms.concat(searchString.split(/\s+/));
-  } else {
-    searchWords = quotedTerms;
-  }
-
-  return searchWords;
-}
-
-/*
- * Given a database model query and a list of search tokens,
- * return query URI.
- *
- * @param aModelQuery database model query
- * @param aSearchWords an array of search tokens.
- *
- * @return query URI.
- */
-function generateQueryURI(aModelQuery, aSearchWords)
-{
-  let queryURI = "";
-  aSearchWords.forEach(searchWord =>
-    queryURI += aModelQuery.replace(/@V/g, encodeABTermValue(searchWord)));
-
-  // queryURI has all the (or(...)) searches, link them up with (and(...)).
-  queryURI = "?(and" + queryURI + ")";
-
-  return queryURI;
-}
-
 // Module
 
 var components = [nsAbAutoCompleteSearch];
 const NSGetFactory = XPCOMUtils.generateNSGetFactory(components);
--- a/mailnews/addrbook/test/unit/test_nsAbAutoCompleteSearch6.js
+++ b/mailnews/addrbook/test/unit/test_nsAbAutoCompleteSearch6.js
@@ -54,49 +54,28 @@ const cards = [
   { // 9
     email: "9@example.com", displayName: "anyjohn",
     popularityIndex: 0, value: "anyjohn <9@example.com>"
   },
 
   { // 10
     email: "10@example.com", displayName: "däsh l18n",
     popularityIndex: 0, value: "däsh l18n <10@example.com>"
-  },
-
-  { // 11
-    email: "11@example.com", displayName: "paul mary",
-    popularityIndex: 0, firstName: "paul", lastName: "mary meyer",
-    value: "paul mary <11@example.com>"
-  },
-
-  { // 12
-    email: "12@example.com", displayName: "paul meyer",
-    popularityIndex: 0, firstName: "paul", lastName: "mary meyer",
-    value: "paul meyer <12@example.com>"
-  },
-
-  { // 13
-    email: "13@example.com", displayName: "mr robert downey (exp dev)",
-    popularityIndex: 0, firstName: "robert", lastName: "downey",
-    value: "mr robert downey (exp dev) <13@example.com>"
   }
 ];
 
 const inputs = [
   { search: "john", expected: [0, 9] },
   { search: "doe", expected: [1, 0] },
   { search: "jd", expected: [0, 4] },
   { search: "who", expected: [1, 0, 6] },
   { search: "xx", expected: [0, 5] },
   { search: "jan", expected: [1, 3] },
   { search: "sh", expected: [2, 10, 7] },
-  { search: "st", expected: [3,8] },
-  { search: "paul mary", expected: [11, 12] },
-  { search: "\"paul mary\"", expected: [11] },
-  { search: "\"robert downey\" mr \"exp dev\"", expected: [13] }
+  { search: "st", expected: [3,8] }
 ];
 
 function acObserver() {}
 
 acObserver.prototype = {
   _search: null,
   _result: null,
 
@@ -119,17 +98,16 @@ function run_test()
   function createAndAddCard(element) {
     var card = Cc["@mozilla.org/addressbook/cardproperty;1"]
                  .createInstance(Ci.nsIAbCard);
 
     card.primaryEmail = element.email;
     card.displayName = element.displayName;
     card.setProperty("PopularityIndex", element.popularityIndex);
     card.firstName = element.firstName;
-    card.lastName = element.lastName;
 
     ab.addCard(card);
   }
 
   cards.forEach(createAndAddCard);
 
   // Test - duplicate elements