youtube/v3/search - id.kind criteria - youtube-api

Is there a way I can specify the id.kind criteria along with the other criteria in youtube/v3/search?
I tried entering the parameter &id.kind=youtube#video in my get url it didn't work.

For the search endpoint, you can filter the type of resource returned with the "type" parameter; if you set it to "channel," for example, you'll only get back resources where the id.kind value is "youtube#channel."
Acceptable values for the "type" parameter of a search are "channel," "video," or "playlist," and you can search on multiple types with a comma-delimited list of the types you want back.

Related

InfluxDB query and filter values

cant seem to find if similar post.
I am using Grafana / InfluxDB I am trying to create a variable in Grafana, to create this variable I need to query values which I can do easily with this piece:
SHOW TAG VALUES WITH KEY = "name"
However, I need to filter the values that I get, in example, I would like only to see values that have specific url maybe just https://google.com.
I tried something like this
SHOW TAG VALUES WITH KEY = "name" WHERE "name" = 'https://google.com'
And I get only on instance of this URL, perhaps there is a way to find all the URL's which contain https://google.com
Try regular expressions, probably:
SHOW TAG VALUES WITH KEY = "name"
WHERE "name" =~ /.https:\/\/google\.com./

matches_any throws exception on empty array writing custom filter for Datatables using Arel

I have am working with Ruby on Rails using the ajax-datatables-rails gem for datatables for which I need a custom filter.
My current filter looks like this:
def filter_status_column
statuses = []
->(column, value) do
# Do stuff and put statuses in the array
::Arel::Nodes::SqlLiteral.new(column.field.to_s).matches_any(statuses)
end
end
This, when my array is not empty will generate some sql like this:
0> ::Arel::Nodes::SqlLiteral.new(column.field.to_s).matches_any(like_mapped_values).to_sql
=> "(status ILIKE 'Foo' OR status ILIKE 'Bar')"
If the array this causes an exception which my expectation is after running .where("status in ?", []) against the model is like this as that turns [] to null:
"(status ILIKE NULL)"
Calling
::Arel::Nodes::SqlLiteral.new(column.field.to_s).matches_any([]).to_sql
generates the error
Unsupported argument type: NilClass. Construct an Arel node instead.
What is the correct method to handle an empty array in matches_any? I could also do this without arel I suppose as well. Status is just a column on a model
EDIT: Further background, this datatable on the UI side has a search box and this field differs in text between what's displayed and what's actually in the database. This custom filter takes the distinct values from the database and maps the view text to the meaningful database text. It "likes" the viewed text, takes the match from the database side, and needs to apply filters as it goes. So, a partial match on the view text is matched to the actual database match. This means there could be no database matches and match_any? pukes on that.
Querying for "status matches an empty array" is ambiguous, depending on your use case it may mean several things, you may want to:
match all possible statuses
match no rows at all
match rows that have a NULL status
match all possible statuses except NULL
You should therefore check if statuses is empty and return a query that matches what you would like to do. Either:
not adding a filter (or 1=1)
filter out everything (or 1=0)
status IS NULL
status IS NOT NULL

In QUERY on unique values, NO_COLUMN error

I have a list of U.S. states where duplicate values are also available. I need to find how many unique states are there in a list.
'Unique' function returns all the unique states but in conjunction with 'query' function the following error message is returned:
Unable to parse query string for Function QUERY parameter 2: NO_COLUMN: A
=query(unique(A3:A26),"Select count(A)")
What am I doing wrong?
Having reconstructed the data (after UNIQUE it is different) you can't then continue with letters for column references. So:
=query(unique(A3:A26),"Select count(Col1)")

Solr and Rails: [* TO *] value instead of nil (asterisk TO asterisk)

Inside my model at searchable block I have index time added_at.
At search block for searching I added with(:added_at, nil), made reindex and now inside search object I have:
<Sunspot::Search:{:fq=>["-added_at_d:[* TO *]"]...}>
What is the meaning of this [* TO *] ? Something went wrong?
By adding with(:added_at, nil) you narrow down the search results to documents having no values in the field added_at, so we can expect the corresponding query filter to be defined as :
fq=>["added_at_d:null"] # not valid
The problem is that Solr Standard Query Parser does not support searching a field for empty/null value. In this situation the filter needs to be negated (exluding documents having any value in the field) so that the query remains valid.
The operator - can be used to exclude the field, and the wildcard character * can be used to match any value, now we can expect the query filter to look like :
fq=>["-added_at_d:*"]
However, although the above is valid for the query parser, using a range query should be preferred to prevent inconsitent behaviors when using wildcard within negative subqueries.
Range Queries allow one to match documents whose field(s) values are
between the lower and upper bound specified by the Range Query. Range
Queries can be inclusive or exclusive of the upper and lower bounds.
A * may be used for either or both endpoints to specify an open-ended range query.
Eventually there is nothing wrong with this filter that ends up looking like :
fq=>["-added_at_d:[* TO *]"]
cf. Lucene Range Queries, Solr Standard Query Parser

REST url for resource collection, which filters resource by attribute not equal to a given value

How to design REST url for resource collection, which filters resource by attribute not equal to a given value?
For example, to get the students in 8th grade, we use
GET /students?grade=8
How to do the same, if we need to get the students not in 8th grade? And how to design for less than (<) , greater than (>) etc ?
What I am thinking of doing is including the operator as part of the argument, delimited from the value. I would also define non-symbolic operators to avoid the need for ugly URL-encoding or confusion with the equals sign after the parameter name. For your example, this would be something like this for students not in grade 8:
GET /students?grade=neq|8
Students in grades > 8 would be:
GET /students?grade=gt|8
Students between grades 8 and 10 (inclusive):
GET /students?grade=gte|8,lte|10
This approach can be extended to other filterable fields without the need to add additional parameters to modify the way each field is filtered.
Stripe has one of the most respected APIs.
They use a separate parameter for each operator separated with a dot.
For example, to search on created date:
/charges?created.gt=
/charges?created.gte=
/charges?created.lt=
/charges?created.lte=
In your case you could do something like:
/students?grade.gt=8&grade.lt=8
Or even add another operator for not:
/students?grade.not=8
One option would be to add an additional query parameter such as gradeOperator in which you could pass the operator to be used when comparing the value against the grade parameter. E.g.,
GET /students?grade=8&gradeOperator=!%3D
!%3D is the URL-encoded form of !=, so your REST API would de-encode the operator and interpret this as grade != 8.
Another approach would be to pass the value and operator in the HTTP request body. Something like this would potentially work (with the body provided in JSON as an example):
GET /students
Content-Type: application/json
{ "grade": {"value": 8, "operator": "!=" } }
That could be nice since you wouldn't have to repeat the word 'grade' in gradeOperator, the operator is simply nested inside a JSON object as the value of grade.
In either solution, you could potentially define any number of operators, including <, >, >=, <=, etc. Just be sure to properly sanitize any input operators your API receives, especially if used in a DB query, to avoid things like SQL injection attacks.

Resources