diff --git a/backend/src/schema/resolvers/searches.js b/backend/src/schema/resolvers/searches.js index cbf301e24..fb46e6e8a 100644 --- a/backend/src/schema/resolvers/searches.js +++ b/backend/src/schema/resolvers/searches.js @@ -1,64 +1,56 @@ -import uuid from 'uuid/v4' - const transformReturnType = record => { return { - id: uuid(), - searchResults: { - __typename: record.get('type'), - ...record.get('resource').properties, - }, + __typename: record.get('type'), + ...record.get('resource').properties, } } export default { Query: { findResources: async (_parent, args, context, _resolveInfo) => { - const query = args.query + const { query, limit } = args const filter = {} - const limit = args.limit - const { user } = context - const thisUserId = user.id - const postQuery = query.replace(/\s/g, '~ ') + '~' - const userQuery = query.replace(/\s/g, '~ ') + '~' + const { id: thisUserId } = context.user + // const postQuery = query.replace(/\s/g, '~ ') + '~' + // const userQuery = query.replace(/\s/g, '~ ') + '~' const postCypher = ` CALL db.index.fulltext.queryNodes('post_fulltext_search', $query) YIELD node as resource, score MATCH (resource)<-[:WROTE]-(user:User) - WHERE score >= 0.2 + WHERE score >= 0.5 AND NOT user.deleted = true AND NOT user.disabled = true AND NOT resource.deleted = true AND NOT resource.disabled = true AND NOT user.id in COALESCE($filter.author_not.id_in, []) - AND NOT (:User { id: $thisUserId })-[:BLOCKED]->(user) + AND NOT (:User { id: $thisUserId })-[:BLOCKED]-(user) RETURN resource, labels(resource)[0] AS type LIMIT $limit ` const session = context.driver.session() const postResults = await session.run(postCypher, { - query: postQuery, - filter: filter, - limit: limit, - thisUserId: thisUserId, + query, + filter, + limit, + thisUserId, }) session.close() const userCypher = ` CALL db.index.fulltext.queryNodes('user_fulltext_search', $query) YIELD node as resource, score MATCH (resource) - WHERE score >= 0.2 + WHERE score >= 0.5 AND NOT resource.deleted = true AND NOT resource.disabled = true - AND NOT (:User { id: $thisUserId })-[:BLOCKED]->(resource) + AND NOT (:User { id: $thisUserId })-[:BLOCKED]-(resource) RETURN resource, labels(resource)[0] AS type LIMIT $limit ` const userResults = await session.run(userCypher, { - query: userQuery, - filter: filter, - limit: limit, - thisUserId: thisUserId, + query, + filter, + limit, + thisUserId, }) - session.close() - const result = postResults.records.concat(userResults.records).map(transformReturnType) - + let result = [...postResults.records, ...userResults.records] + result = result.map(transformReturnType) return result }, }, diff --git a/backend/src/schema/types/type/Search.gql b/backend/src/schema/types/type/Search.gql index eab7f87ba..2c22fa61f 100644 --- a/backend/src/schema/types/type/Search.gql +++ b/backend/src/schema/types/type/Search.gql @@ -1,9 +1,4 @@ -type SearchResult { - id: ID! - searchResults: ResourceResults -} - -union ResourceResults = Post | User +union SearchResult = Post | User type Query { findResources(query: String!, limit: Int = 5): [SearchResult]! diff --git a/webapp/components/SearchInput/SearchInput.vue b/webapp/components/SearchInput/SearchInput.vue index c94a2baec..9de9f5042 100644 --- a/webapp/components/SearchInput/SearchInput.vue +++ b/webapp/components/SearchInput/SearchInput.vue @@ -150,8 +150,7 @@ export default { query: value, }, }) - const searchResults = findResources.map(searchResult => searchResult.searchResults) - this.searchResults = searchResults + this.searchResults = findResources } catch (error) { this.searchResults = [] } finally { diff --git a/webapp/graphql/Search.js b/webapp/graphql/Search.js index f71c848c7..4d5f47f38 100644 --- a/webapp/graphql/Search.js +++ b/webapp/graphql/Search.js @@ -3,27 +3,25 @@ import gql from 'graphql-tag' export const findResourcesQuery = gql` query($query: String!) { findResources(query: $query, limit: 5) { - id - searchResults { - __typename - ... on Post { - id - title - slug - commentsCount - shoutedCount - createdAt - author { - name - } - } - ... on User { + __typename + ... on Post { + id + title + slug + commentsCount + shoutedCount + createdAt + author { id name - slug - avatar } } + ... on User { + id + name + slug + avatar + } } } ` diff --git a/webapp/layouts/default.vue b/webapp/layouts/default.vue index 852e19699..8b6b78900 100644 --- a/webapp/layouts/default.vue +++ b/webapp/layouts/default.vue @@ -82,7 +82,7 @@