Skip to content

Commit

Permalink
ok reports_by_freetext, excluding _attachments
Browse files Browse the repository at this point in the history
  • Loading branch information
m5r committed Nov 27, 2024
1 parent bd86d50 commit c866871
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions ddocs/medic-db/medic-nouveau/nouveau/reports_by_freetext/index.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
function (doc) {
var skip = ['_id', '_rev', 'type', 'refid', 'content'];
let toIndex = '';
var skip = ['_id', '_rev', 'type', 'refid', 'content', '_attachments'];
var toIndex = '';

var emitField = function (key, value) {
if (!key || !value) {
return;
}
key = key.toLowerCase();

key = key.toLowerCase().trim();
if (skip.indexOf(key) !== -1 || /_date$/.test(key)) {
return;
}

var fieldNameRegex = /^\$?[a-zA-Z][a-zA-Z0-9_]*$/g
if (!fieldNameRegex.test(key)) {
log(`key "${key}" doesn't pass regex - "${doc._id}"`);
}

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

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

Expand Down

0 comments on commit c866871

Please sign in to comment.