Skip to content

Commit

Permalink
somewhat working ES query
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Jul 17, 2023
1 parent 8c38e2e commit 2cb80ca
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
11 changes: 9 additions & 2 deletions indexer.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class Indexer {
this.running = false;
log.info('Indexer', 'Stopping indexer');
try {
if (this.changeStream && !this.changeStream.isClosed()) {
if (this.changeStream && !this.changeStream.closed) {
await this.changeStream.close();
}
} catch (err) {
Expand Down Expand Up @@ -188,7 +188,14 @@ class Indexer {
return;
}

if (this.changeStream.isClosed()) {
if (error.errorLabels && error.errorLabels.includes('NonResumableChangeStreamError')) {
// can't resume previous cursor
await db.redis.del('indexer:last');
log.info('Indexer', 'Can not resume existing cursor');
return;
}

if (this.changeStream && this.changeStream.closed) {
log.info('Indexer', 'The change stream is closed. Will not wait on any more changes.');
return;
} else {
Expand Down
14 changes: 12 additions & 2 deletions lib/api/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -592,11 +592,21 @@ module.exports = (db, server, messageHandler, userHandler, storageHandler, setti
let searchQuery = await getElasticSearchQuery(db, user, result.value.q);

const esclient = getClient();
console.log(
util.inspect(
{
index: config.elasticsearch.index,
body: { query: searchQuery, sort: { uid: 'desc' } }
},
false,
22,
true
)
);

let searchResult = await esclient.search({
index: config.elasticsearch.index,
query: searchQuery,
sort: { uid: 'desc' }
body: { query: searchQuery, sort: { uid: 'desc' } }
});

console.log('ES RESULTS');
Expand Down
2 changes: 2 additions & 0 deletions lib/api/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,8 @@ module.exports = (db, server, userHandler, settingsHandler) => {

fromWhitelist: userData.fromWhitelist || [],

featureFlags: userData.featureFlags || {},

disabledScopes: userData.disabledScopes || [],

hasPasswordSet: !!userData.password || !!userData.tempPassword,
Expand Down
12 changes: 10 additions & 2 deletions lib/search-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,15 +368,23 @@ const getElasticSearchQuery = async (db, user, queryStr) => {
should: [
{
match: {
'text.plain': {
subject: {
query: node.text.value,
operator: 'and'
}
}
},
{
match: {
'text.html': {
text: {
query: node.text.value,
operator: 'and'
}
}
},
{
match: {
html: {
query: node.text.value,
operator: 'and'
}
Expand Down

0 comments on commit 2cb80ca

Please sign in to comment.