Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions public/language/en-GB/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"match-words": "Match words",
"match-all-words": "Match all words",
"match-any-word": "Match any word",
"match-contains": "Match contains",
"all": "All",
"any": "Any",
"posted-by": "Posted by",
Expand Down
1 change: 1 addition & 0 deletions public/language/en-US/search.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"match-words": "Match words",
"match-all-words": "Match all words",
"match-any-word": "Match any word",
"match-contains": "Match contains",
"all": "All",
"any": "Any",
"posted-by": "Posted by",
Expand Down
7 changes: 6 additions & 1 deletion src/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,19 @@ async function searchInBookmarks(data, searchCids, searchUids) {
pids = await posts.filterPidsByUid(pids, searchUids);
}
if (query) {
const tokens = String(query).split(' ');
const queryStr = String(query);
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);
const title = String(tidToTopic[postData[i].tid].title);
if (matchWords === 'contains') {
const needle = queryStr.toLowerCase();
return content.toLowerCase().includes(needle) || title.toLowerCase().includes(needle);
}
const tokens = queryStr.split(' ');
const method = (matchWords === 'any' ? 'some' : 'every');
return tokens[method](
token => content.includes(token) || title.includes(token)
Expand Down
1 change: 1 addition & 0 deletions vendor/nodebb-theme-harmony-2.1.35/templates/search.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<select id="match-words-filter" name="matchWords" class="post-search-item form-select text-sm py-2 ps-2 pe-3">
<option value="all">[[search:match-all-words]]</option>
<option value="any">[[search:match-any-word]]</option>
<option value="contains">[[search:match-contains]]</option>
</select>

<select id="show-results-as" name="showAs" class="post-search-item form-select text-sm py-2 ps-2 pe-3">
Expand Down
1 change: 1 addition & 0 deletions vendor/nodebb-theme-harmony-main/templates/search.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<select id="match-words-filter" name="matchWords" class="post-search-item form-select text-sm py-2 ps-2 pe-3">
<option value="all">[[search:match-all-words]]</option>
<option value="any">[[search:match-any-word]]</option>
<option value="contains">[[search:match-contains]]</option>
</select>

<select id="show-results-as" name="showAs" class="post-search-item form-select text-sm py-2 ps-2 pe-3">
Expand Down