mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
searchHashtags added
This commit is contained in:
parent
1adc2b6962
commit
269c2d78dd
@ -89,6 +89,7 @@ export default shield(
|
||||
searchResults: allow,
|
||||
searchPosts: allow,
|
||||
searchUsers: allow,
|
||||
searchHashtags: allow,
|
||||
embed: allow,
|
||||
Category: allow,
|
||||
Tag: allow,
|
||||
|
||||
@ -91,6 +91,42 @@ export default {
|
||||
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) => {
|
||||
const { query, limit } = args
|
||||
const { id: thisUserId } = context.user
|
||||
|
||||
@ -10,8 +10,14 @@ type userSearchResults {
|
||||
users: [User]!
|
||||
}
|
||||
|
||||
type hashtagSearchResults {
|
||||
hashtagCount: Int
|
||||
hashtags: [Tag]!
|
||||
}
|
||||
|
||||
type Query {
|
||||
searchPosts(query: String!, firstPosts: Int, postsOffset: Int): postSearchResults!
|
||||
searchUsers(query: String!, firstUsers: Int, usersOffset: Int): userSearchResults!
|
||||
searchHashtags(query: String!, firstHashtags: Int, hashtagsOffset: Int): hashtagSearchResults!
|
||||
searchResults(query: String!, limit: Int = 5): [SearchResult]!
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user