YQL (Yahoo! Query Language) - Help with adding parameters - yql

I'm doing a very simple YQL statement:
select * from xml where url="http://www.wowhead.com/item=50278&xml"
The rest query looks like this (super long with crazy url escape codes):
http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D%22http%3A%2F%2Fwww.wowhead.com%2Fitem%3D50278%26amp%3Bamp%3Bxml%22
So I'm trying to use the query alias to shorten it down. I know I can use something like url=#parameter but how would I do it so the item number is the variable and the rest query would look something like:
http://query.yahooapis.com/v1/public/yql/RVCA18/wowheadXML?item=50278
I appreciate the help :)

You can build the URL to the XML file using a URI Template (info, YQL uses the 03 draft). The YQL query to do that would look like the following.
select * from xml where url in (
select url from uritemplate
where template="http://www.wowhead.com/item={item}&xml" and item=#item
);
(Try this in the YQL console)
The next stage, which it looks like you already know how to do, is to alias the above query to wowheadXML and call it with the item value in the query string (example).

Related

Sql Server Full-Text Search with wild card suffix using Entity Framework 6 Interceptor

http://www.entityframework.info/Home/FullTextSearch
This example works fine for full word searches but does not talk about how to implement wild card suffix.
For example, I can do the following in SQL and get results for "bill" or "billy" using '*' in the end. How do I add that to my Interceptor?
select * from dbo.messagethread a
where contains(Text, '"bil*"')
If you look at that example code in that link above, I was thinking if something like this (below) is possible, but obviously that does not work as it is getting added to the parameter name not the value.
string.Format(#"contains([$1].[$2], #{0} *)", parameter.ParameterName));
There are questions like this one which talk about wildcards in full-text in SQL.
Look for this line in the example link provided in the question.
parameter.Value = value;
Then, to do prefix match, just add this line below that.
value = $"\"{value}*\""; // prefix match
We're basically changing the value of the parameter to have the * in it inside double quotes.
Now if you search for "bil", you get results for "bill"/"billy" and so on.

Retrieve list of Strings from Spray path

I have a base url of an API like this
http://host/api/categories
In my database categories are a tree based model. I'd like to be able to have an api where I can hit urls like
http://host/api/categories/delivery
http://host/api/categories/delivery/food
http://host/api/categories/delivery/medicine
How can I pull everything after the word "categories" as a single string (and split it myself) or as a list of strings? Essentially getting List("delivery","medicine") out of the third example would be great.
Super easy answer just use
pathPrefix("listJobCategories" / Segments) { query =>
and query will be List[String]

Is there a way to see the string version of a parameterized cypher query?

In Ruby on Rails, using NeoGraphy, I'm constructing a parameterized cypher query and getting back a result.
#results = $neo.execute_query(query, parameters)
Using gon, I put all these to the client and checked them out in the javascript console:
gon.results = #results
gon.search_query = query
gon.search_parameters = parameters
gon.search_query is just what I see in the .rb file, so I guess that means cypher takes that and takes the parameters and then creates the query. Can I get to the string version of the query that must be created by using the parameter values?
The reason I want this is so that I can paste it into the neo4j web admin console tool and tweak it.
Thanks!
Perhaps the simplest way to accomplish that is to write your own print method that given the query and the parameters would print the expanded query. And you can call it before / after the $neo.execute_query

How get a like twitter url

i would like a simple help...
i have a url like this:
example.com/profile.php?id= & name=
my .htaccess file like this.
RewriteRule ^profile/(.)/(.) profile.php?id=$1&name=$2
so i have a end url like this:
example.com/profile/id/name
i can make
example.com/id
but how can i get a url like this:
example.com/name
??
thax
Obviously, your profile.php script is expecting two GET variables, and your desired URL only has one. So you will probably have to change both the script and your database schema.
Your rewrite rule is subtly wrong. Yours will only select a single character in each of the bracketed parts. If you put a * after each dot, it will instead select one or more characters which I think is what you need.
RewriteRule ^profile/(.*)/(.*) profile.php?id=$1&name=$2
If what you're looking for is exactly this:
example.com/name
You will need to change your profile.php to only expect the name variable, and use it to query the database.
I believe previously you had something like:
mysql_query("SELECT * from table where id=$id");
You will need to change it to be
mysql_query("SELECT * from table where name$name");
So you are telling your page to query the user by the name, instead of by the ID.
There's a few drawbacks related to this, as your query won't be as fast as it used to be, as I believe your name column is not the primary key, therefore no indexing.
Twitter uses Rails, so they will be calling it in a slightly different way using something like (onMissingMethod):
get_user_by_username()
Which isn't great either, as it's still querying the database by a string, but has some performance improvements to enable rails to do that.
Your htaccess will then looki like:
RewriteRule ^(.*) profile.php?name=$1
Hope that answers your question

How does a website know the Google query I used to find it?

When I search for something such as "rearrange table columns in asp.net" on Google, and click the link to Wrox's forum site, the site greets me with a message such as "Your Google search for 'rearrange table columns in asp.net' brought you to Wrox Forum...".
How does a site know what query I typed into Google? And how could I add such an ablity to my site?
It is parsing your query from the query parameters in the HTTP_REFERER server variable, which contains the URL you're coming from and is provided in your HTTP request.
It uses a header known as the "HTTP referrer". See http://en.wikipedia.org/wiki/HTTP_referrer
To use it in your site, you would need some kind of dynamic page generation, such as ASP / ASP.NET, PHP, or Perl. For example in Perl, you could do something like:
if ($ENV{HTTP_REFERER} =~ /google.com\?.+&q=(.+?)&/)
print "Your google search of $1 brought you to this site";
WARNING: The code above is only an example and may not be correct or secure!
Like these guys are suggesting, it's the HTTP_REFERER header variable. The query is in the "q" key in the URL. So if you want to parse that, you can just sort out the querystring and URL decode the "q" variable.
It looks at the referrer header. Here is some fairly basic PHP code to do it.

Resources