Is it possible to alias or rename fields in YQL? - yql

I'm making a bunch of YQL queries at once & have a standard way of accessing the fields on the server. Unfortunately one of the feeds uses a different name than the rest for a field so I was assuming I could alias it within YQL.
Something like:
SELECT title, link, encoded AS description FROM...
But it looks like YQL's parser doesn't like that as I get this error:
Syntax error(s) [line 1:37 expecting field got 'AS']
So, is it possible to alias fields in YQL like you can in SQL? I don't seen anything in the YQL docs or on the internet at large.
Tacking another (small) question on as well, is there a spec anywhere for YQL's syntax?

No, it's not possible to do an alias in the YQL query. (As #codeulike mentioned, it's really not true "SQL" like you might find in MySQL or other databases.)
One capability that might help your needs is the ability in Open Tables to create an alias for parameter names. See the YQL Open Tables documentation and search for "alias".

I think YQL corresponds to SQL in only a metaphorical sort of way; although it superficially uses things like SELECT, it doesn't try to cover much of the breadth of SQL. Hence if its not in the documentation, its probably not possible.
In this guide: http://developer.yahoo.com/yql/guide/select_statement.html ... aliasing of fields is not mentioned, so I figure its not a feature.
Although, if you run your YQL query through Yahoo Pipes, you can use their Rename module to rename elements of the data.

Related

Dart Parse Server creating an index for full text search

I'm trying to use dart parse server in order to do a full-text search as explained here.
So far as I understand, I have the falling 2 options if I want to do that:
whereContainsWholeWord
whereContains
In the case of the first one, I will search the whole database for that specific word, and for the second one, I will search the database for some partial word.
This is exactly what I need, but because the second search is going to utilize regex, this is going to be slow.
Is there any way to create an index for full-text search via the dart parse server, and afterward use some query on that index? Or this feature is not implemented yet, because I could not find anything in this regard in the document

How to do partial search in rails?

I am trying to fetch all cards that do not belong to the current user and it's title contains some keywords.
What I have so far after research is this code below.
#other_cards = Card.where(:user_id.ne => #temp_current_user, "title LIKE ?" => "%Business%").limit(10).order('created_at desc down_title asc')
But there are no records being returned even thought they are present.
I have also tried to skip the :user_id condition and all the limits and orders, resulting in this simple code to check if it will return anything
#other_cards = Card.where("title LIKE ?", "%Business%")
EDIT
I have also tried putting the conditions as an array suggested in the first comment. It also resulted in a error
EDIT 2
Attaching screenshot of running the query in rails console
LIKE syntax is part of SQL. MongoDB, and Mongoid, do not (directly) support SQL. The general rule of thumb is Ruby methods carry over from ActiveRecord to Mongoid, for example the following works with both AR and Mongoid:
Card.where(id: 123)
... but once you start to specify complex conditions in either keys or values, they are often specific to the database you are working with. In the code you provided, the :user_id.ne syntax will not be recognized by ActiveRecord, and Mongoid/MongoDB do not recognize title LIKE ?.
Your problem statement was:
I am trying to fetch all cards that do not belong to the current user and its title contains some keywords.
MongoDB has native full text search capability, which is a superior solution to trying to match keywords with regular expressions or SQL LIKE operators. MongoDB has good documentation on full text searches here. The Ruby driver has further documentation, and examples, for how to use full text search here. Mongoid does not currently have documentation for full text search (there is an in progress pull request to add it here) but the gist of it is to combine the driver documentation referenced earlier with the documentation here for how to work with indexes in Mongoid in general.

Insights for Twitter service in IBM Bluemix: Search case-sensitive string and other questions

I am trying to search for a case-sensitive string in Twitter. I know the standard query is case-insensitive. How can I do case-sensitive search?
Also, the search arguments are "AND". Is there a way that I can write arguments and treat them as "OR"? To say it more clear, for illustration, I would like to search for tweets with either one of the following arguments: bio_location:"Philippines" or country_code:PH. I don't want to use "AND" because I am aware that there are users without bio_location and also some users only have country_code populated. So I want to get those who will satisfy any one of these arguments.
Another question, is there a way that I can filter out retweets?
Thank you!
2) "OR" is supported. See Query language for usage of the OR operator. Searching for "bio_location:"Philippines" OR country_code:PH" should work.
In answer to your questions....
1) You can use an 'exact phrase match' for case-sensitivity - see API docs for more on this. Not sure what your use case is, so this may or may not work for you.
2) Currently the 'OR' conditional is not supported by the API, or at least it is not documented in the API. I will get in touch with our developers to see if it is possible but not documented. In the mean time, you can do an two API calls and process the data server side (such as removing duplicates).
3) Filtering out retweets is possible. See API docs here under
get /v1/messages/search. Look specifically under the message.bodywhere it states: For Retweets, Twitter modifies the value of the body at the root level. Your application should look at the object.body to ensure that it is extracting the non-modified text.
Hope this helps!

Search a document in Elasticsearch by a list of Wildcarded statements on a single field

If I have documents in ElasticSearch that have a field called url and the contents of the url field are strings like "http://www.foo.com" or "http://www.bar.com/some/url/segment/the-page.html", is it possible to search for documents matching a list of wildcarded url fragments e.g., ["http://www.foo.", "http://www.bar.com//segment/.html", "://*bar.com/**"]?
If it is possible, what is the best approach to do this? I have explored wildcard query which only seems to support 1 fragment not multiple. Filters don't seem to support wildcarding as I have tried using * in a term filter without any luck.
To make it a little more complex, I'm also interested in being able to search by a lot of these fragments. I have come across terms filter lookup which seems like it is a good solution for dealing with many search terms, but I'm not sure wildcarding works with filters.
Any thoughts?

Rails Active Record Relation sorting

Let's say I have a ruby on rails model, with a text field. Let's say I also have a query string. I want to make a query that sorts the database in descending order of maximal number of overlapping characters between the text field and the query string. How would I go about this?
Probably you can go with LIKE SQL statement, but will not be efficient.
Here is an example:
Company.where(Company.arel_table[:name].matches("%stack%"))
If you need to make a lot of queries search the text inside a field in database, you really need to start looking for a full text search software.
I can recommend you Elastic Search, unless you are familiar with some other tool.
You have here a recent tutorial and also a Railscast on subject.

Resources