Skip to content

Commit befc527

Browse files
committed
feat(Discovery): add support for the new metrics and event endpoints
1 parent 877d4eb commit befc527

File tree

1 file changed

+238
-5
lines changed

1 file changed

+238
-5
lines changed

lib/ibm_watson/discovery_v1.rb

Lines changed: 238 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ def configure_http_client(proxy: {}, timeout: {})
174174
# instance. An attempt to create another environment results in an error.
175175
# @param name [String] Name that identifies the environment.
176176
# @param description [String] Description of the environment.
177-
# @param size [Fixnum] **Deprecated**: Size of the environment.
177+
# @param size [String] Size of the environment.
178178
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
179179
def create_environment(name:, description: nil, size: nil)
180180
raise ArgumentError("name must be provided") if name.nil?
@@ -1094,7 +1094,7 @@ def delete_document(environment_id:, collection_id:, document_id:)
10941094
# exact answer. Aggregations are useful for building applications, because you can
10951095
# use them to build lists, tables, and time series. For a full list of possible
10961096
# aggregrations, see the Query reference.
1097-
# @param count [Fixnum] Number of documents to return.
1097+
# @param count [Fixnum] Number of results to return.
10981098
# @param return_fields [Array[String]] A comma separated list of the portion of the document hierarchy to return.
10991099
# @param offset [Fixnum] The number of query results to skip at the beginning. For example, if the total
11001100
# number of results that are returned is 10, and the offset is 8, it returns the
@@ -1195,7 +1195,7 @@ def query(environment_id:, collection_id:, filter: nil, query: nil, natural_lang
11951195
# exact answer. Aggregations are useful for building applications, because you can
11961196
# use them to build lists, tables, and time series. For a full list of possible
11971197
# aggregrations, see the Query reference.
1198-
# @param count [Fixnum] Number of documents to return.
1198+
# @param count [Fixnum] Number of results to return.
11991199
# @param return_fields [Array[String]] A comma separated list of the portion of the document hierarchy to return.
12001200
# @param offset [Fixnum] The number of query results to skip at the beginning. For example, if the total
12011201
# number of results that are returned is 10, and the offset is 8, it returns the
@@ -1286,7 +1286,7 @@ def query_notices(environment_id:, collection_id:, filter: nil, query: nil, natu
12861286
# exact answer. Aggregations are useful for building applications, because you can
12871287
# use them to build lists, tables, and time series. For a full list of possible
12881288
# aggregrations, see the Query reference.
1289-
# @param count [Fixnum] Number of documents to return.
1289+
# @param count [Fixnum] Number of results to return.
12901290
# @param return_fields [Array[String]] A comma separated list of the portion of the document hierarchy to return.
12911291
# @param offset [Fixnum] The number of query results to skip at the beginning. For example, if the total
12921292
# number of results that are returned is 10, and the offset is 8, it returns the
@@ -1386,7 +1386,7 @@ def federated_query(environment_id:, collection_ids:, filter: nil, query: nil, n
13861386
# exact answer. Aggregations are useful for building applications, because you can
13871387
# use them to build lists, tables, and time series. For a full list of possible
13881388
# aggregrations, see the Query reference.
1389-
# @param count [Fixnum] Number of documents to return.
1389+
# @param count [Fixnum] Number of results to return.
13901390
# @param return_fields [Array[String]] A comma separated list of the portion of the document hierarchy to return.
13911391
# @param offset [Fixnum] The number of query results to skip at the beginning. For example, if the total
13921392
# number of results that are returned is 10, and the offset is 8, it returns the
@@ -1884,6 +1884,239 @@ def delete_user_data(customer_id:)
18841884
nil
18851885
end
18861886
#########################
1887+
# Events and feedback
1888+
#########################
1889+
1890+
##
1891+
# @!method create_event(type:, data:)
1892+
# Create event.
1893+
# The **Events** API can be used to create log entries that are associated with
1894+
# specific queries. For example, you can record which documents in the results set
1895+
# were \"clicked\" by a user and when that click occured.
1896+
# @param type [String] The event type to be created.
1897+
# @param data [EventData] Data object used to create a query event.
1898+
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
1899+
def create_event(type:, data:)
1900+
raise ArgumentError("type must be provided") if type.nil?
1901+
raise ArgumentError("data must be provided") if data.nil?
1902+
headers = {
1903+
}
1904+
params = {
1905+
"version" => @version
1906+
}
1907+
data = {
1908+
"type" => type,
1909+
"data" => data
1910+
}
1911+
method_url = "/v1/events"
1912+
response = request(
1913+
method: "POST",
1914+
url: method_url,
1915+
headers: headers,
1916+
params: params,
1917+
json: data,
1918+
accept_json: true
1919+
)
1920+
response
1921+
end
1922+
1923+
##
1924+
# @!method query_log(filter: nil, query: nil, count: nil, offset: nil, sort: nil)
1925+
# Search the query and event log.
1926+
# Searches the query and event log to find query sessions that match the specified
1927+
# criteria. Searching the **logs** endpoint uses the standard Discovery query syntax
1928+
# for the parameters that are supported.
1929+
# @param filter [String] A cacheable query that limits the documents returned to exclude any documents that
1930+
# don't mention the query content. Filter searches are better for metadata type
1931+
# searches and when you are trying to get a sense of concepts in the data set.
1932+
# @param query [String] A query search returns all documents in your data set with full enrichments and
1933+
# full text, but with the most relevant documents listed first. Use a query search
1934+
# when you want to find the most relevant search results. You cannot use
1935+
# **natural_language_query** and **query** at the same time.
1936+
# @param count [Fixnum] Number of results to return.
1937+
# @param offset [Fixnum] The number of query results to skip at the beginning. For example, if the total
1938+
# number of results that are returned is 10, and the offset is 8, it returns the
1939+
# last two results.
1940+
# @param sort [Array[String]] A comma separated list of fields in the document to sort on. You can optionally
1941+
# specify a sort direction by prefixing the field with `-` for descending or `+` for
1942+
# ascending. Ascending is the default sort direction if no prefix is specified.
1943+
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
1944+
def query_log(filter: nil, query: nil, count: nil, offset: nil, sort: nil)
1945+
headers = {
1946+
}
1947+
params = {
1948+
"version" => @version,
1949+
"filter" => filter,
1950+
"query" => query,
1951+
"count" => count,
1952+
"offset" => offset,
1953+
"sort" => sort.to_a
1954+
}
1955+
method_url = "/v1/logs"
1956+
response = request(
1957+
method: "GET",
1958+
url: method_url,
1959+
headers: headers,
1960+
params: params,
1961+
accept_json: true
1962+
)
1963+
response
1964+
end
1965+
1966+
##
1967+
# @!method get_metrics_query(start_time: nil, end_time: nil, result_type: nil)
1968+
# Number of queries over time.
1969+
# Total number of queries using the **natural_language_query** parameter over a
1970+
# specific time window.
1971+
# @param start_time [Time] Metric is computed from data recorded after this timestamp; must be in
1972+
# `YYYY-MM-DDThh:mm:ssZ` format.
1973+
# @param end_time [Time] Metric is computed from data recorded before this timestamp; must be in
1974+
# `YYYY-MM-DDThh:mm:ssZ` format.
1975+
# @param result_type [String] The type of result to consider when calculating the metric.
1976+
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
1977+
def get_metrics_query(start_time: nil, end_time: nil, result_type: nil)
1978+
headers = {
1979+
}
1980+
params = {
1981+
"version" => @version,
1982+
"start_time" => start_time,
1983+
"end_time" => end_time,
1984+
"result_type" => result_type
1985+
}
1986+
method_url = "/v1/metrics/number_of_queries"
1987+
response = request(
1988+
method: "GET",
1989+
url: method_url,
1990+
headers: headers,
1991+
params: params,
1992+
accept_json: true
1993+
)
1994+
response
1995+
end
1996+
1997+
##
1998+
# @!method get_metrics_query_event(start_time: nil, end_time: nil, result_type: nil)
1999+
# Number of queries with an event over time.
2000+
# Total number of queries using the **natural_language_query** parameter that have a
2001+
# corresponding \"click\" event over a specified time window. This metric requires
2002+
# having integrated event tracking in your application using the **Events** API.
2003+
# @param start_time [Time] Metric is computed from data recorded after this timestamp; must be in
2004+
# `YYYY-MM-DDThh:mm:ssZ` format.
2005+
# @param end_time [Time] Metric is computed from data recorded before this timestamp; must be in
2006+
# `YYYY-MM-DDThh:mm:ssZ` format.
2007+
# @param result_type [String] The type of result to consider when calculating the metric.
2008+
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
2009+
def get_metrics_query_event(start_time: nil, end_time: nil, result_type: nil)
2010+
headers = {
2011+
}
2012+
params = {
2013+
"version" => @version,
2014+
"start_time" => start_time,
2015+
"end_time" => end_time,
2016+
"result_type" => result_type
2017+
}
2018+
method_url = "/v1/metrics/number_of_queries_with_event"
2019+
response = request(
2020+
method: "GET",
2021+
url: method_url,
2022+
headers: headers,
2023+
params: params,
2024+
accept_json: true
2025+
)
2026+
response
2027+
end
2028+
2029+
##
2030+
# @!method get_metrics_query_no_results(start_time: nil, end_time: nil, result_type: nil)
2031+
# Number of queries with no search results over time.
2032+
# Total number of queries using the **natural_language_query** parameter that have
2033+
# no results returned over a specified time window.
2034+
# @param start_time [Time] Metric is computed from data recorded after this timestamp; must be in
2035+
# `YYYY-MM-DDThh:mm:ssZ` format.
2036+
# @param end_time [Time] Metric is computed from data recorded before this timestamp; must be in
2037+
# `YYYY-MM-DDThh:mm:ssZ` format.
2038+
# @param result_type [String] The type of result to consider when calculating the metric.
2039+
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
2040+
def get_metrics_query_no_results(start_time: nil, end_time: nil, result_type: nil)
2041+
headers = {
2042+
}
2043+
params = {
2044+
"version" => @version,
2045+
"start_time" => start_time,
2046+
"end_time" => end_time,
2047+
"result_type" => result_type
2048+
}
2049+
method_url = "/v1/metrics/number_of_queries_with_no_search_results"
2050+
response = request(
2051+
method: "GET",
2052+
url: method_url,
2053+
headers: headers,
2054+
params: params,
2055+
accept_json: true
2056+
)
2057+
response
2058+
end
2059+
2060+
##
2061+
# @!method get_metrics_event_rate(start_time: nil, end_time: nil, result_type: nil)
2062+
# Percentage of queries with an associated event.
2063+
# The percentage of queries using the **natural_language_query** parameter that have
2064+
# a corresponding \"click\" event over a specified time window. This metric
2065+
# requires having integrated event tracking in your application using the **Events**
2066+
# API.
2067+
# @param start_time [Time] Metric is computed from data recorded after this timestamp; must be in
2068+
# `YYYY-MM-DDThh:mm:ssZ` format.
2069+
# @param end_time [Time] Metric is computed from data recorded before this timestamp; must be in
2070+
# `YYYY-MM-DDThh:mm:ssZ` format.
2071+
# @param result_type [String] The type of result to consider when calculating the metric.
2072+
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
2073+
def get_metrics_event_rate(start_time: nil, end_time: nil, result_type: nil)
2074+
headers = {
2075+
}
2076+
params = {
2077+
"version" => @version,
2078+
"start_time" => start_time,
2079+
"end_time" => end_time,
2080+
"result_type" => result_type
2081+
}
2082+
method_url = "/v1/metrics/event_rate"
2083+
response = request(
2084+
method: "GET",
2085+
url: method_url,
2086+
headers: headers,
2087+
params: params,
2088+
accept_json: true
2089+
)
2090+
response
2091+
end
2092+
2093+
##
2094+
# @!method get_metrics_query_token_event(count: nil)
2095+
# Most frequent query tokens with an event.
2096+
# The most frequent query tokens parsed from the **natural_language_query**
2097+
# parameter and their corresponding \"click\" event rate within the recording period
2098+
# (queries and events are stored for 30 days). A query token is an individual word
2099+
# or unigram within the query string.
2100+
# @param count [Fixnum] Number of results to return.
2101+
# @return [DetailedResponse] A `DetailedResponse` object representing the response.
2102+
def get_metrics_query_token_event(count: nil)
2103+
headers = {
2104+
}
2105+
params = {
2106+
"version" => @version,
2107+
"count" => count
2108+
}
2109+
method_url = "/v1/metrics/top_query_tokens_with_event_rate"
2110+
response = request(
2111+
method: "GET",
2112+
url: method_url,
2113+
headers: headers,
2114+
params: params,
2115+
accept_json: true
2116+
)
2117+
response
2118+
end
2119+
#########################
18872120
# Credentials
18882121
#########################
18892122

0 commit comments

Comments
 (0)