diff --git a/app/graphql/types/categories_type.rb b/app/graphql/types/categories_type.rb new file mode 100644 index 0000000..bf1cbbf --- /dev/null +++ b/app/graphql/types/categories_type.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module Types + class CategoriesType < Types::BaseObject + description 'Information about one category linked to this search term' + + field :confidence, Float, null: false, description: 'The application\'s confidence that the term belongs to this category - measured from 0.0 to 1.0' + field :name, String, null: false, description: 'The name of this category' + + def name + @object.category.name + end + end +end diff --git a/app/graphql/types/search_event_type.rb b/app/graphql/types/search_event_type.rb index 38f0e14..a8a3f3a 100644 --- a/app/graphql/types/search_event_type.rb +++ b/app/graphql/types/search_event_type.rb @@ -2,6 +2,7 @@ module Types class SearchEventType < Types::BaseObject + field :categories, [Types::CategoriesType], description: 'The list of categories linked to term provided in this search' field :created_at, GraphQL::Types::ISO8601DateTime, null: false field :detectors, Types::DetectorsType field :id, ID, null: false @@ -14,6 +15,10 @@ def phrase @object.term.phrase end + def categories + @object.term.categorizations + end + def detectors @object.term.phrase end diff --git a/app/graphql/types/term_type.rb b/app/graphql/types/term_type.rb index 409d940..b3ef6ef 100644 --- a/app/graphql/types/term_type.rb +++ b/app/graphql/types/term_type.rb @@ -2,6 +2,7 @@ module Types class TermType < Types::BaseObject + field :categories, [Types::CategoriesType], description: 'The list of categories linked to this term' field :created_at, GraphQL::Types::ISO8601DateTime, null: false field :detectors, Types::DetectorsType field :id, ID, null: false @@ -14,6 +15,10 @@ def occurence_count @object.search_events.count end + def categories + @object.categorizations + end + def detectors @object.phrase end