Skip to content

Commit

Permalink
feat: added text index to text_message (searches both subject and err…
Browse files Browse the repository at this point in the history
…or message now)
  • Loading branch information
titanism committed Jul 17, 2023
1 parent fa8b697 commit ee1e4f9
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
45 changes: 36 additions & 9 deletions app/controllers/web/my-account/list-logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,18 @@ async function listLogs(ctx) {
}
},
{
subject: {
$regex: new RegExp(regexParser(_.escapeRegExp(subject)), 'i')
}
$or: [
{
subject: {
$regex: new RegExp(regexParser(_.escapeRegExp(subject)), 'i')
}
},
{
text_message: {
$regex: new RegExp(regexParser(_.escapeRegExp(subject)), 'i')
}
}
]
}
]
};
Expand All @@ -266,9 +275,18 @@ async function listLogs(ctx) {
}
},
{
subject: {
$regex: new RegExp(regexParser(_.escapeRegExp(subject)), 'i')
}
$or: [
{
subject: {
$regex: new RegExp(regexParser(_.escapeRegExp(subject)), 'i')
}
},
{
text_message: {
$regex: new RegExp(regexParser(_.escapeRegExp(subject)), 'i')
}
}
]
}
);
} else {
Expand All @@ -281,9 +299,18 @@ async function listLogs(ctx) {
}
},
{
subject: {
$regex: new RegExp(regexParser(_.escapeRegExp(subject)), 'i')
}
$or: [
{
subject: {
$regex: new RegExp(regexParser(_.escapeRegExp(subject)), 'i')
}
},
{
text_message: {
$regex: new RegExp(regexParser(_.escapeRegExp(subject)), 'i')
}
}
]
}
]
};
Expand Down
7 changes: 5 additions & 2 deletions app/models/logs.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,11 @@ Logs.index({ keywords: 1 });
// (note that we'd have to feed the search query the search parsed tokens from ctx.query)
// (but at that point we might want to simply do another hash query lookup by tokens parsed)
//
// subject is a text index combined with regex query for accuracy in my account > logs
Logs.index({ subject: 'text' }, { default_language: 'english' });
// multiple text index combined with regex query for accuracy in my account > logs
Logs.index(
{ subject: 'text', text_message: 'text' },
{ default_language: 'english' }
);

//
// create sparse (now known as "partial" indices) on common log queries
Expand Down

0 comments on commit ee1e4f9

Please sign in to comment.