Add communities to search results
This commit is contained in:
parent
3b06e741bd
commit
d24b7aa956
|
@ -507,13 +507,17 @@ router.get("/search", async (req, res) => {
|
||||||
|
|
||||||
const query = req.query.query;
|
const query = req.query.query;
|
||||||
|
|
||||||
let people = [];
|
let results = {
|
||||||
|
people: [],
|
||||||
|
communities: [],
|
||||||
|
};
|
||||||
if (query.length >= 3) {
|
if (query.length >= 3) {
|
||||||
people = await queries.searchPeople(ssbServer, query);
|
results = await queries.search(ssbServer, query);
|
||||||
metrics.searchResults.observe(people.length);
|
metrics.searchResultsPeople.observe(results.people.length);
|
||||||
|
metrics.searchResultsCommunities.observe(results.communities.length);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.render("search", { people, query });
|
res.render("search", { ...results, query });
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get("/blob/*", (req, res) => {
|
router.get("/blob/*", (req, res) => {
|
||||||
|
|
|
@ -33,8 +33,12 @@ module.exports = {
|
||||||
name: "social_ssb_progress_total",
|
name: "social_ssb_progress_total",
|
||||||
help: "Tracks ssb syncing progress total",
|
help: "Tracks ssb syncing progress total",
|
||||||
}),
|
}),
|
||||||
searchResults: new Summary({
|
searchResultsPeople: new Summary({
|
||||||
name: "social_search_results",
|
name: "social_search_results_people",
|
||||||
help: "Amount of results returned from search",
|
help: "Amount of people results returned from search",
|
||||||
|
}),
|
||||||
|
searchResultsCommunities: new Summary({
|
||||||
|
name: "social_search_results_communities",
|
||||||
|
help: "Amount of communities results returned from search",
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
|
|
@ -188,7 +188,7 @@ const getSecretMessages = async (ssbServer, profile) => {
|
||||||
return chatList;
|
return chatList;
|
||||||
};
|
};
|
||||||
|
|
||||||
const searchPeople = async (ssbServer, search) => {
|
const search = async (ssbServer, search) => {
|
||||||
debugPeople("Fetching");
|
debugPeople("Fetching");
|
||||||
|
|
||||||
// https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex
|
// https://stackoverflow.com/questions/3446170/escape-string-for-use-in-javascript-regex
|
||||||
|
@ -219,16 +219,47 @@ const searchPeople = async (ssbServer, search) => {
|
||||||
],
|
],
|
||||||
}),
|
}),
|
||||||
pull.filter((msg) => {
|
pull.filter((msg) => {
|
||||||
|
if (!msg.value.content) return;
|
||||||
|
|
||||||
const normalizedName = msg.value.content.name
|
const normalizedName = msg.value.content.name
|
||||||
.normalize("NFD")
|
.normalize("NFD")
|
||||||
.replace(/[\u0300-\u036f]/g, "");
|
.replace(/[\u0300-\u036f]/g, "");
|
||||||
return msg.value.content && searchRegex.exec(normalizedName);
|
return searchRegex.exec(normalizedName);
|
||||||
}),
|
}),
|
||||||
paramap(mapProfiles(ssbServer))
|
paramap(mapProfiles(ssbServer))
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const communitiesPosts = await promisePull(
|
||||||
|
ssbServer.query.read({
|
||||||
|
reverse: true,
|
||||||
|
query: [
|
||||||
|
{
|
||||||
|
$filter: {
|
||||||
|
value: {
|
||||||
|
private: { $not: true },
|
||||||
|
content: {
|
||||||
|
type: "post",
|
||||||
|
channel: { $truthy: true },
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
limit: 3000,
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
const communities = Array.from(
|
||||||
|
new Set(communitiesPosts.map((p) => p.value.content.channel))
|
||||||
|
).filter((name) => {
|
||||||
|
const normalizedName = name
|
||||||
|
.normalize("NFD")
|
||||||
|
.replace(/[\u0300-\u036f]/g, "");
|
||||||
|
return searchRegex.exec(normalizedName);
|
||||||
|
});
|
||||||
|
|
||||||
debugPeople("Done");
|
debugPeople("Done");
|
||||||
return Object.values(mapValues(people));
|
return { people: Object.values(mapValues(people)), communities };
|
||||||
};
|
};
|
||||||
|
|
||||||
const getFriends = async (ssbServer, profile) => {
|
const getFriends = async (ssbServer, profile) => {
|
||||||
|
@ -498,7 +529,7 @@ setInterval(() => {
|
||||||
module.exports = {
|
module.exports = {
|
||||||
mapProfiles,
|
mapProfiles,
|
||||||
getPosts,
|
getPosts,
|
||||||
searchPeople,
|
search,
|
||||||
getFriends,
|
getFriends,
|
||||||
getAllEntries,
|
getAllEntries,
|
||||||
getProfile,
|
getProfile,
|
||||||
|
|
|
@ -5,12 +5,28 @@
|
||||||
<% } else { %>
|
<% } else { %>
|
||||||
<h2>Results for "<%= query %>"</h2>
|
<h2>Results for "<%= query %>"</h2>
|
||||||
|
|
||||||
|
<h3>People</h3>
|
||||||
|
|
||||||
|
<% if (people.length == 0) { %>
|
||||||
|
<p>No results found</p>
|
||||||
|
<% } %>
|
||||||
<% people.map(person => { %>
|
<% people.map(person => { %>
|
||||||
<a class="link-block" href="<%= profileUrl(person.author) %>">
|
<a class="link-block" href="<%= profileUrl(person.author) %>">
|
||||||
<img class="link-profile-pic" src="<%= profileImageUrl(person.authorProfile) %>" />
|
<img class="link-profile-pic" src="<%= profileImageUrl(person.authorProfile) %>" />
|
||||||
<div><%= person.content.name %></div>
|
<div><%= person.content.name %></div>
|
||||||
</a>
|
</a>
|
||||||
<% }) %>
|
<% }) %>
|
||||||
|
|
||||||
|
<h3 style="padding-top: 20px">Communities</h3>
|
||||||
|
|
||||||
|
<% if (communities.length == 0) { %>
|
||||||
|
<p>No results found</p>
|
||||||
|
<% } %>
|
||||||
|
<% communities.map(community => { %>
|
||||||
|
<a href="/communities/<%= community %>" class="link-block" style="display: inline-block">
|
||||||
|
#<%= community %>
|
||||||
|
</a>
|
||||||
|
<% }) %>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
<%- include('_footer') %>
|
<%- include('_footer') %>
|
Loading…
Reference in New Issue