Permalink
Browse files

initial search results

  • Loading branch information...
1 parent 36a6bb1 commit 7441fd63c0d14b2cb7dfed809f54e233fecc5e4a @brion committed Apr 11, 2012
Showing with 36 additions and 1 deletion.
  1. +36 −1 WikipediaMetroTest/js/default.js
@@ -77,9 +77,44 @@
doSearch(e.queryText);
});
+ function stripHtmlTags(html) {
+ return html.replace(/<[^>]+>/g, ''); // fixme put in real html parser
+ }
+
function doSearch(query) {
var title = document.getElementById('title');
title.textContent = query;
+ var url = 'https://en.wikipedia.org/w/api.php';
+ $.ajax({
+ url: url,
+ data: {
+ action: 'query',
+ list: 'search',
+ srwhat: 'text',
+ srsearch: query,
+ format: 'json'
+ },
+ success: function (data) {
+ // data.query.search
+ // [
+ // {ns, size, snippet, timestamp, title, wordcount
+ // ]
+ // data.query.searchinfo
+ // totalhits
+ if (data.error) {
+ // ..
+ $("#content").text('Search error');
+ } else {
+ $("#content").empty();
+ var $dl = $("<dl>");
+ data.query.search.forEach(function (item, i) {
+ $("<dt>").text(item.title).appendTo($dl);
+ $("<dd>").text(stripHtmlTags(item.snippet)).appendTo($dl);
+ });
+ $dl.appendTo("#content");
+ }
+ }
+ });
}
@@ -114,7 +149,7 @@
console.log(summaries);
var summary = summaries[summaries.length - 1];
var html = summary.text,
- txt = html.replace(/<[^>]+>/g, ''); // fixme put in real html parser
+ txt = stripHtmlTags(html);
updateLiveTile("Featured Article", txt);
}
});

0 comments on commit 7441fd6

Please sign in to comment.