-
-
Notifications
You must be signed in to change notification settings - Fork 219
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
contacts_by_type_freetext
& reports_by_freetext
nouveau-style
- Loading branch information
Showing
3 changed files
with
111 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
ddocs/medic-db/medic-nouveau/nouveau/contacts_by_type_freetext/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
function (doc) { | ||
var skip = ['_id', '_rev', 'type', 'refid', 'geolocation']; | ||
let toIndex = ''; | ||
|
||
var types = ['district_hospital', 'health_center', 'clinic', 'person']; | ||
var idx; | ||
var type; | ||
if (doc.type === 'contact') { | ||
type = doc.contact_type; | ||
idx = types.indexOf(type); | ||
if (idx === -1) { | ||
idx = type; | ||
} | ||
} else { | ||
type = doc.type; | ||
idx = types.indexOf(type); | ||
} | ||
if (idx !== -1) { | ||
Object.keys(doc).forEach(function (key) { | ||
var value = doc[key]; | ||
if (!key || !value) { | ||
return; | ||
} | ||
key = key.toLowerCase(); | ||
if (skip.indexOf(key) !== -1 || /_date$/.test(key)) { | ||
return; | ||
} | ||
|
||
if (typeof value === 'string') { | ||
toIndex += ' ' + value; | ||
// index('text', key, value, { store: true }); | ||
} | ||
|
||
if (typeof value === 'number') { | ||
// index('double', key, value, { store: true }); | ||
} | ||
|
||
/*const fieldNameRegex = /^\$?[a-zA-Z][a-zA-Z0-9_]*$/g | ||
if (fieldNameRegex.test(key)) { | ||
console.log(`key "${key}" doesn't pass regex`); | ||
}*/ | ||
}); | ||
} | ||
|
||
toIndex = toIndex.trim(); | ||
if (toIndex) { | ||
index('text', 'default', toIndex, { store: true }); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
ddocs/medic-db/medic-nouveau/nouveau/reports_by_freetext/index.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
function (doc) { | ||
var skip = ['_id', '_rev', 'type', 'refid', 'content']; | ||
let toIndex = ''; | ||
|
||
var emitField = function (key, value) { | ||
if (!key || !value) { | ||
return; | ||
} | ||
key = key.toLowerCase(); | ||
if (skip.indexOf(key) !== -1 || /_date$/.test(key)) { | ||
return; | ||
} | ||
|
||
if (typeof value === 'string') { | ||
toIndex += ' ' + value; | ||
// index('text', key, value, { store: true }); | ||
} | ||
|
||
if (typeof value === 'number') { | ||
// index('double', key, value, { store: true }); | ||
} | ||
|
||
const fieldNameRegex = /^\$?[a-zA-Z][a-zA-Z0-9_]*$/g | ||
if (fieldNameRegex.test(key)) { | ||
console.log(`key "${key}" doesn't pass regex`); | ||
} | ||
}; | ||
|
||
if (doc.type === 'data_record' && doc.form) { | ||
Object.keys(doc).forEach(function (key) { | ||
emitField(key, doc[key]); | ||
}); | ||
if (doc.fields) { | ||
Object.keys(doc.fields).forEach(function (key) { | ||
emitField(key, doc.fields[key]); | ||
}); | ||
} | ||
if (doc.contact && doc.contact._id) { | ||
// index('text', 'contact', doc.contact._id.toLowerCase(), { store: true }); | ||
/*const fieldNameRegex = /^\$?[a-zA-Z][a-zA-Z0-9_]*$/g | ||
if (fieldNameRegex.test('contact')) { | ||
console.log(`key "contact" doesn't pass regex`); | ||
}*/ | ||
} | ||
} | ||
|
||
toIndex = toIndex.trim(); | ||
if (toIndex) { | ||
index('text', 'default', toIndex, { store: true }); | ||
} | ||
} |