How to get specific results using MediaWiki API in Rails backend? - ruby-on-rails

I'm doing my final project for a coding school that will be a deep song search app that returns every detail about a song (composer, personnel on the track, lyrics, studio, media uses, images, etc). I'm using React frontend/Rails backend API. I'm new to API's and have tried Discogs and Musicbrainz but find the Mediawiki to be the easiest to traverse. Messing with their sandbox using Query, I feel like I'm getting closer but wondering if anyone with more experience out there could help me get precisely what I need.
I would like a music search to return a list of matches (could be same title but different songs or same title but different recordings). A user can click on the results to see the details. I would like the API to return links and hopefully images (album cover, etc). Does anyone know the best way to go about this?
I've also tried using the Ruby Gem wrapper Mediawikitory https://github.com/molybdenum-99/mediawiktory. I like the clean interface but can't quite find the right parameters.
The closest I've come to what I'm looking for in the Mediawiki sandbox is an example like this for the All Star (Smash Mouth):
https://en.wikipedia.org//w/api.php?action=query&format=json&prop=&list=search&continue=-%7C%7C&srsearch=star%20(song)&srlimit=5&sroffset=15&srqiprofile=engine_autoselect&srwhat=text&srinfo=totalhits%7Csuggestion%7Crewrittenquery&srinterwiki=1
This gives a list of songs (I'll have to concatenate '(song)' in every search unless there's a specific category parameter I don't know about).

So with further research I was able to drill down to specific song searches (and this will work for any thing this specific). You have to use srsearch and then search option in lists. So an example for a list of songs based on a given title:
https://en.wikipedia.org/w/api.php?action=query&formatversion=2&format=json&prop=info%7Cpageimages&generator=search&inprop=url&piprop=thumbnail%7Cname&gsrsearch=I%20love%20you%20(song)&gsrwhat=text
Make sure you choose version 2 as it gives you a better formatted Object to map over.
The Mediawiki API is very robust. You just have to spend a little time with it. The sandbox is great.

Related

How to make search query on certain web site and display it as native app

I have a task to implement but after some thought I don't really know from where to begin.
What I need to achieve:
Lets take as example BestBay web site. From my app I would like to create a certain query which will go/use to BestBay search type what I need and bring me the result. On my device I would like to show it as 10 views of the first items the website returned. For instance if I type "tvs" I will get a list of tvs so I would like to show this list on my device with the price and the link to the item (at least for the 10 first items).
I have experience with native apps(i didn't worked with web apps).
I can't use Best buy api.
I am not sure from where to begin.
I read about YQL.
I thought maybe to use the web page with the results as html and parse it to the objects I need.
Did anyone do something similar and can give me some starting point.
How to approach this kind of problem.
(tutorials/documentations/sample code something that can help me to start).
Tnx a lot.
In the end I decided to do it by HTML parsing:
parsing HTML on the iPhone
How to Parse HTML on iOS

Facebook Search in Graph API

I'm developing an iOS application that let the user to search for a person throught the Graph API.
What I want is the SAME behavior that it's present on the Facebook website. You know when you begin to search for a person in the top text input? The first results will be mostly your friends AND some people you MAY know or people you already looked for.
The problem? Try to use the same search pattern here to search a person: Graph Api Explorer
The Graph Api returns DIFFERENT results than the search input on the Facebook website.
Does anyone knows why? Is there a way to achieve the same results?
Facebook are using many algorithms to display search result like Relevance Indicators, Complexities of User-Centric Search and The Product.
One of the algorithm to display result on their page as below.
Personal Context:
Unlike most search engines, every Facebook search involves two key elements - a query and a querier.
Just as we need to understand the query, it’s as essential to understand the person behind the query.
People are more likely to be looking for things located in their own city/country or for people who share the same college/workplace.
We consider this information and much more when ranking results. The more we know about you, the better your search results will be.
In Graph API, they are not using this algorithm.They are just displaying the queried result. Hence you can not achieve same result using graph search API.
To achieve this you can use following apporach -
Get the friend list of user using me/friends?limit=1&offset=1
Get the user list using search api
merge both the result
show result(s) to user
For more information(approach/algorithm) you can check Intro to Facebook Search
Is there a way to achieve the same results? - NO
Does anyone knows why? - NOT REALLY
(Edit: Seems in another answer, someone does actually, but it doesn't change the answer for "If you can achieve it")
But its safe to presume that Facebook does not allow all functionality through the API, why would they after all ? They need to keep the people coming to their own platform. So I can't give you a straight forward response on WHY, but IF ? Not possible, there is zero documentation about more specified search for type user. When you request user friends, you will only get the user friends who are using the same app starting v2.0
Am afraid that you will have to drop the functionality you want to achieve.
It is not just the graph search. When you refresh your TimeLine. The order of posts gets changed every time because Facebook takes a Pull on Demand approach. Which means whenever you login, the data from your friends is fetched. Which is why facebook has a limit to maximum number of friends.
Talking about the Graph search and Graph API. They are not same and the Graph Search cannot be accessed through the Graph API. So, you would have to change your approach.
To explain why the graph search gives different results on same search term. I would guess that it follows the game Pull on Demand model ( although it is not open and we cannot know for sure ). Following that model makes sense though.
Thanks

view search queries by popuarity containing keyword

I have been spending some time watching the search queries that bring people to my site on google analytics recently, in order to see if people are finding exacty what they are looking for and if not creating that new content. But i figured an easier way would be to what search queries are popular. But containing a keyword that relates to my site.
for example, i want to see all the most queried search terms that contain "in japanese".
like "dog in japanese", "i love you in japanese"
I have found http://www.google.com/trends/
but after playing with it for a while it doesnt seem like i can do this. seems like i can just see popularity of spesific queries. I dont want to see how popular specific queries are, i want to see what queries containing x are popular. Anywhere i can do this?
If you join the Google AdWords program, you can use the Keyword Planner tool to try out keywords and immediately get the number of searches per month in a chosen geography. This is a very interesting tool. See http://adwords.google.com.
I'm not sure this question belongs here on SO though.

search for and embed youtube videos in ruby on rails application

I have a website where I want to basically allow people to display several youtube videos onto the same page.
For example, I have a friend who has 3 different videos. Instead of sending a link to the three videos individually, they would go to my site see the 3 search boxes, search for the videos individually (the search is done on youtube), then they can pick the videos and click "done", at which point, the 3 videos would be embedded on their page.
I'm trying to figure out how to approach this in ruby on rails, but I'm not finding much information on how.
Here's a link from 2009 of a guy who's saying that he can actually do the search and retrieve from youtube: http://railsforum.com/viewtopic.php?id=30443
But I don't know how to do the search & retrieve, and I don't know how to do the embed. I think I can figure out the embed, but what's the best way to do the search/display results?
Thanks a lot for your help stackoverflow, you're my only hope (besides google, but google failed me today).
all you need to know about the search feature is described in YouTube Data Api. You will need your app to communicate with this API. The best thing to do may be to look after a gem specialized in this ; there is a list available in another StackOverflow question.

How to get product information from amazon, just based on the URL?

I just have a link to a product page, at amazon. How do I get all the information (photo, price etc), in my ruby program, just using this link?
Here's the list of supported urls as disclosed by amazon for their oembed, product advertising API would come to picture only after parsing through these URLs and getting the ASINs
http://*amazon.*/gp/product/*
http://*amazon.*/*/dp/*
http://*amazon.*/dp/*
http://*amazon.*/o/ASIN/*
http://*amazon.*/gp/offer-listing/*
http://*amazon.*/*/ASIN/*
http://*amazon.*/gp/product/images/*
http://*amazon.*/gp/aw/d/*
http://www.amzn.com/*
http://amzn.com/*
I found this library (I'm using Rails)
amazon-ecs
I'm experimenting with it. Still, I'd require some kind of ID (product id?) to get details of a particular product. For example, consider this link to kindle
http://www.amazon.com/Kindle-Amazons-Wireless-Reading-Generation/dp/B00154JDAI/ref=amb_link_84372271_1?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=center-1&pf_rd_r=06JJGQP9J3BHKPE38SXP&pf_rd_t=101&pf_rd_p=478184871&pf_rd_i=507846
In that link, I noticed ASIN, which is B00154JDAI.
Looks like I can use this ID, to get product information (using amazon-ecs). I just need to parse the URL, to get ASIN.
Is there any other way to do it?
No, I am not going to do screen scraping, that is not a good idea anytime.
If you want to do this, the Nokogiri or hpricot libraries both allow HTML parsing and searching. However, this kind of screen-scraping is notoriously unreliable (as it may break any time Amazon decides to reorganize their HTML), so if you're planning to do this sort of thing for any length of time I'd recommend leveraging the Amazon Product Advertising API instead.
In your program: fetch the page and parse HTML. Filter out the required information. There may be some libraries in Ruby (that I am unaware of), which parse HTML.
hpricot seems to do what you want.
You should use the library Ruby/AWS (google for it, my karma is not high enough to allow external links...). It has been written exactly for that.
You might need to use the built-in Search to find the item you're looking for. After that, the API gives access to pictures, links and all usable information.

Resources