Skip to content

Commit

Permalink
fix duplication in search view, fix search_by_name missing variable e…
Browse files Browse the repository at this point in the history
…rror (2600hz#4944)

Fixing duplication result issue in search_by_name_and_number view. Previously it set name to pvt_alphanum_name and emit, and also emits another one if the doc.name is defined.

Generalized name, first_name and last_name logic in both "search by name and number" and search by name view to do:

    If either first or last name is defined, sanitize and concatenate them, and store non sanitized one to set in the value part of the result (so UI can show this).
    If doc has pvt_alphanum_name key use that for name part of the result key.
    a. else if the name key defined sanitize it and use it for key, and use non sanitized for value
    b. if all failed and name (from concatenation of the first and last name is empty) is empty use the ID of document.
    set the value object of whatever found for name, first/last name (if any), or numbers (if any, in name_and_number view).
    search by name and number is emitting one result for name and for each numbers (if any).

4.2: 2600hz#4945
How To Test

Using UI, use search box in account manager, account switch at top bar, use search in advanced callflow. Check the search result using Web Developer tools, the result should not be duplicated.
  • Loading branch information
icehess authored and jamesaimonetti committed Jun 26, 2018
1 parent dd9b786 commit 4c34944
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 45 deletions.
88 changes: 44 additions & 44 deletions applications/crossbar/priv/couchdb/account/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,72 +5,72 @@
"search_by_name": {
"map": [
"function(doc) {",
" if (doc.pvt_deleted) return;",
" var name = \"\", first_name = \"\", last_name = \"\"; ",
" if (doc.hasOwnProperty(\"pvt_alphanum_name\")) {",
" if (doc.pvt_deleted || !doc.pvt_type) return;",
" var actual_name = '', name = '';",
" var obj = {};",
" if (doc.hasOwnProperty('first_name') || doc.hasOwnProperty('last_name')) {",
" obj.first_name = (doc.first_name || '').toLowerCase().replace(/[^a-z0-9]/g, '');",
" obj.last_name = (doc.last_name || '').toLowerCase().replace(/[^a-z0-9]/g, '');",
" name = obj.first_name + obj.last_name;",
" actual_name = (doc.first_name || '') + (doc.first_name && doc.last_name ? ' ' : '') + (doc.last_name || '');",
" }",
" if (doc.hasOwnProperty('pvt_alphanum_name')) {",
" name = doc.pvt_alphanum_name;",
" } if (doc.hasOwnProperty(\"name\")) {",
" } else if (doc.hasOwnProperty('name')) {",
" name = doc.name.toLowerCase().replace(/[^a-z0-9]/g, '');",
" } else if (doc.hasOwnProperty(\"first_name\") && doc.hasOwnProperty(\"last_name\")) {",
" fist_name = doc.first_name.toLowerCase().replace(/[^a-z0-9]/g, '');",
" last_name = doc.last_name.toLowerCase().replace(/[^a-z0-9]/g, '');",
" name = first_name + last_name;",
" } else {",
" name = doc._id.toLowerCase().replace(/[^a-z0-9]/g, '')",
" actual_name = doc.name;",
" } else if (name === '') {",
" name = doc._id.toLowerCase().replace(/[^a-z0-9]/g, '');",
" }",
" emit([doc.pvt_type, name], {",
" 'id': doc._id,",
" 'first_name': first_name,",
" 'last_name': last_name,",
" 'name': name",
" });",
" obj.id = doc._id;",
" obj.name = actual_name ? actual_name : doc.hasOwnProperty('name') ? doc.name : name;",
" emit([doc.pvt_type, name], obj);",
"}"
]
},
"search_by_name_and_number": {
"map": [
"function(doc) {",
" if (doc.pvt_deleted) return;",
" if (doc.hasOwnProperty(\"pvt_alphanum_name\")) {",
" emit([doc.pvt_type, doc.pvt_alphanum_name], {",
" 'id': doc._id,",
" 'name': doc.name,",
" 'numbers': doc.numbers",
" });",
" } if (doc.hasOwnProperty(\"name\")) {",
" emit([doc.pvt_type, doc.name.toLowerCase().replace(/[^a-z0-9]/g, '')], {",
" 'id': doc._id,",
" 'name': doc.name,",
" 'numbers': doc.numbers",
" });",
" } if (doc.hasOwnProperty(\"numbers\")) {",
" if (doc.pvt_deleted || !doc.pvt_type) return;",
" var actual_name = '', name = '';",
" var name_obj = {};",
" if (doc.hasOwnProperty('first_name') || doc.hasOwnProperty('last_name')) {",
" name_obj.first_name = (doc.first_name || '').toLowerCase().replace(/[^a-z0-9]/g, '');",
" name_obj.last_name = (doc.last_name || '').toLowerCase().replace(/[^a-z0-9]/g, '');",
" name = name_obj.first_name + name_obj.last_name;",
" actual_name = (doc.first_name || '') + (doc.first_name && doc.last_name ? ' ' : '') + (doc.last_name || '');",
" }",
" if (doc.hasOwnProperty('pvt_alphanum_name')) {",
" name = doc.pvt_alphanum_name;",
" } else if (doc.hasOwnProperty('name')) {",
" name = doc.name.toLowerCase().replace(/[^a-z0-9]/g, '');",
" actual_name = doc.name;",
" } else if (name === '') {",
" name = doc._id.toLowerCase().replace(/[^a-z0-9]/g, '');",
" }",
" name_obj.id = doc._id;",
" name_obj.name = actual_name ? actual_name : doc.hasOwnProperty('name') ? doc.name : name;",
" if (doc.hasOwnProperty('numbers')) name_obj.numbers = doc.numbers;",
" emit([doc.pvt_type, name], name_obj);",
" if (doc.hasOwnProperty('numbers')) {",
" for (var i in doc.numbers) {",
" emit([doc.pvt_type, doc.numbers[i].replace(/[^a-z0-9]/g, '')], {",
" emit([doc.pvt_type, doc.numbers[i].toLowerCase().replace(/[^a-z0-9]/g, '')], {",
" 'id': doc._id,",
" 'name': doc.name,",
" 'name': actual_name,",
" 'numbers': doc.numbers",
" });",
" }",
" } else if (doc.hasOwnProperty(\"first_name\") && doc.hasOwnProperty(\"last_name\")) {",
" fist_name = doc.first_name.toLowerCase().replace(/[^a-z0-9]/g, '');",
" last_name = doc.last_name.toLowerCase().replace(/[^a-z0-9]/g, '');",
" emit([doc.pvt_type, first_name + last_name], {",
" 'id': doc._id,",
" 'first_name': first_name,",
" 'last_name': last_name,",
" 'numbers': doc.numbers",
" });",
" }",
"}"
]
},
"search_by_number": {
"map": [
"function(doc) {",
" if (doc.pvt_deleted) return;",
" if (doc.hasOwnProperty(\"numbers\")) {",
" if (doc.pvt_deleted || !doc.pvt_type) return;",
" if (doc.hasOwnProperty('numbers')) {",
" for (var i in doc.numbers) {",
" emit([doc.pvt_type, doc.numbers[i].replace(/[^a-z0-9]/g, '')], {",
" emit([doc.pvt_type, doc.numbers[i].toLowerCase().replace(/[^a-z0-9]/g, '')], {",
" 'id': doc._id,",
" 'name': doc.name,",
" 'numbers': doc.numbers",
Expand Down
2 changes: 1 addition & 1 deletion core/kazoo_apps/priv/couchdb/views/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
" if (doc.pvt_deleted)",
" return;",
" for (i in doc.pvt_tree) {",
" var name;",
" var name = '';",
" if (doc.pvt_alphanum_name) {",
" name = doc.pvt_alphanum_name;",
" } if (doc.name) {",
Expand Down

0 comments on commit 4c34944

Please sign in to comment.