searchHashtags added

This commit is contained in:
Moriz Wahl 2020-04-08 17:59:49 +02:00
parent 1adc2b6962
commit 269c2d78dd
3 changed files with 43 additions and 0 deletions

View File

@ -89,6 +89,7 @@ export default shield(
searchResults: allow, searchResults: allow,
searchPosts: allow, searchPosts: allow,
searchUsers: allow, searchUsers: allow,
searchHashtags: allow,
embed: allow, embed: allow,
Category: allow, Category: allow,
Tag: allow, Tag: allow,

View File

@ -91,6 +91,42 @@ export default {
session.close() session.close()
} }
}, },
searchHashtags: async (_parent, args, context, _resolveInfo) => {
const { query, hashtagsOffset, firstHashtags } = args
const { id: userId } = context.user
const tagCypher = `
CALL db.index.fulltext.queryNodes('tag_fulltext_search', $query)
YIELD node as tag, score
MATCH (tag)
WHERE score >= 0.0
AND NOT (tag.deleted = true OR tag.disabled = true)
RETURN { hashtagCount: toString(size(collect(tag))), hashtags: collect( tag {.*, __typename: labels(tag)[0]}) } AS hashtagResult
SKIP $hashtagsOffset
LIMIT $firstHashtags
`
const myQuery = queryString(query)
const session = context.driver.session()
const searchResultPromise = session.readTransaction(async (transaction) => {
const userTransactionResponse = await transaction.run(tagCypher, {
query: myQuery,
hashtagsOffset,
firstHashtags,
userId,
})
return userTransactionResponse
})
try {
const hashtagResults = await searchResultPromise
log(hashtagResults)
return hashtagResults.records[0].get('hashtagResult')
} finally {
session.close()
}
},
searchResults: async (_parent, args, context, _resolveInfo) => { searchResults: async (_parent, args, context, _resolveInfo) => {
const { query, limit } = args const { query, limit } = args
const { id: thisUserId } = context.user const { id: thisUserId } = context.user

View File

@ -10,8 +10,14 @@ type userSearchResults {
users: [User]! users: [User]!
} }
type hashtagSearchResults {
hashtagCount: Int
hashtags: [Tag]!
}
type Query { type Query {
searchPosts(query: String!, firstPosts: Int, postsOffset: Int): postSearchResults! searchPosts(query: String!, firstPosts: Int, postsOffset: Int): postSearchResults!
searchUsers(query: String!, firstUsers: Int, usersOffset: Int): userSearchResults! searchUsers(query: String!, firstUsers: Int, usersOffset: Int): userSearchResults!
searchHashtags(query: String!, firstHashtags: Int, hashtagsOffset: Int): hashtagSearchResults!
searchResults(query: String!, limit: Int = 5): [SearchResult]! searchResults(query: String!, limit: Int = 5): [SearchResult]!
} }