hydra
v3
v3
  • Hydra
  • Hydra CLI
  • Hydra Indexer
  • Hydra Indexer Gateway
  • Hydra Processor
  • Hydra Typegen
  • Overview
    • Query Node Manifest
    • Graphql Queries
    • Pagination
    • Sorting
    • Mappings
      • Context interfaces
      • Mapping Filters
      • Mapping Types
    • Schema
      • The Goodies
      • Entities
      • Enums
      • Interfaces
      • Algebraic types
      • Full-text queries
      • Entity Relationships
      • Cross filtering
      • Variant relations
    • Architecture
  • Install Hydra
  • Migration to Hydra v2
  • What's new in Hydra v3
  • FAQ
  • Quickstart
Powered by GitBook
On this page

Was this helpful?

  1. Overview
  2. Schema

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:

type Post @entity{
   title: String @fulltext(query: "forum"),
   body: String @fulltext(query: "forum")
}

type Comment @entity {
   text: String @fulltext(query: "forum")
}

The generated output schema will define the required output type and the query:

type SearchResult {
   item: Post | Comment,
   rank: number, 
   highlight: String
}

type Query {
   forum(text: String, limit?: Int): SearchResult[]
}

One can now run similarity query:

query {
   forum(text: "some partially matching text", limit: 5) {
      rank
      highlight 
      item {
         ... on Post {
            body
         }
         ... on Comment {
            title
         }
      }

   }
}
PreviousAlgebraic typesNextEntity Relationships

Last updated 4 years ago

Was this helpful?