hydra
Search…
Full-text queries
Run cross-field and cross-entity full-text queries
Full-text queries are able to search across a large amount of text data and aggregate the results across multiple fields and even entities. The query output provides the result rank and a highlight if there is a text match.
In order to enable full-text search queries in the API, decorate any number of Stringfields with @fulltext(query: <query_name>) decorator, like this:
1
type Post @entity{
2
title: String @fulltext(query: "forum"),
3
body: String @fulltext(query: "forum")
4
}
5
6
type Comment @entity {
7
text: String @fulltext(query: "forum")
8
}
Copied!
The generated output schema will define the required output type and the query:
1
type SearchResult {
2
item: Post | Comment,
3
rank: number,
4
highlight: String
5
}
6
7
type Query {
8
forum(text: String, limit?: Int): SearchResult[]
9
}
Copied!
One can now run similarity query:
1
query {
2
forum(text: "some partially matching text", limit: 5) {
3
rank
4
highlight
5
item {
6
... on Post {
7
body
8
}
9
... on Comment {
10
title
11
}
12
}
13
14
}
15
}
Copied!
Last modified 8mo ago
Copy link