Skip to content

Commit

Permalink
search in topic titles as well
Browse files Browse the repository at this point in the history
  • Loading branch information
barisusakli committed Jan 12, 2024
1 parent 34a8069 commit 4ee9873
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/search.js
Expand Up @@ -130,13 +130,17 @@ async function searchInBookmarks(data, searchCids, searchUids) {
}
if (query) {
const tokens = String(query).split(' ');
const postData = await db.getObjectsFields(pids.map(pid => `post:${pid}`), ['content']);
const postData = await db.getObjectsFields(pids.map(pid => `post:${pid}`), ['content', 'tid']);
const tids = _.uniq(postData.map(p => p.tid));
const topicData = await db.getObjectsFields(tids.map(tid => `topic:${tid}`), ['title']);
const tidToTopic = _.zipObject(tids, topicData);
pids = pids.filter((pid, i) => {
const content = String(postData[i].content);
if (matchWords === 'any') {
return tokens.some(t => content.includes(t));
}
return tokens.every(t => content.includes(t));
const title = String(tidToTopic[postData[i].tid].title);
const method = (matchWords === 'any' ? 'some' : 'every');
return tokens[method](
token => content.includes(token) || title.includes(token)
);
});
}
allPids.push(...pids);
Expand Down

0 comments on commit 4ee9873

Please sign in to comment.