Skip to content

Commit

Permalink
nouveau-backed fulltext search index
Browse files Browse the repository at this point in the history
  • Loading branch information
m5r committed Oct 14, 2024
1 parent 8058731 commit 101c40e
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
1 change: 1 addition & 0 deletions ddocs/medic-db/medic-nouveau/_id
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
_design/medic-nouveau
47 changes: 47 additions & 0 deletions ddocs/medic-db/medic-nouveau/nouveau/contacts_by_freetext/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
function(doc) {
const skip = [ '_id', '_rev', 'type', 'refid', 'geolocation' ];
let toIndex = '';

const types = [ 'district_hospital', 'health_center', 'clinic', 'person' ];
let idx;
if (doc.type === 'contact') {
idx = types.indexOf(doc.contact_type);
if (idx === -1) {
idx = doc.contact_type;
}
} else {
idx = types.indexOf(doc.type);
}

const isContactDoc = idx !== -1;
if (isContactDoc) {
Object.keys(doc).forEach(function(key) {
const 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;
}

/*if (typeof value === 'number') {
index('double', key, value, { store: true });
}*/

/*if (typeof value === 'string') {
index('text', key, value, { store: true });
}*/
});

toIndex = toIndex.trim();
if (toIndex) {
index('text', 'default', toIndex, { store: true });
}
}
}

0 comments on commit 101c40e

Please sign in to comment.