Skip to content

Commit

Permalink
Fixed var, special case for google image search
Browse files Browse the repository at this point in the history
  • Loading branch information
dangrossman committed Jan 10, 2011
1 parent 84b95a1 commit 73b7477
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions searchparser.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
var patterns = new Array();

var patterns = [];
patterns.push( { 'name': 'Google', 'pattern': 'google', 'var': 'q' } );
patterns.push( { 'name': 'Live', 'pattern': 'search.live', 'var': 'q' } );
patterns.push( { 'name': 'Bing', 'pattern': 'bing', 'var': 'q' } );
Expand Down Expand Up @@ -42,21 +41,23 @@ patterns.push( { 'name': 'Baidu', 'pattern': 'baidu', 'var': 'wd' } );
exports.parse = function(url) {

var parts = require('url').parse(url, true);
console.log(require('util').inspect(parts));

var found = false;
var info = [];

console.log("Patterns: \n" + require('util').inspect(patterns) + "\nLength: " + patterns.length);

for (var i = 0; i < patterns.length; i++) {
var search = patterns[i];

console.log("Checking " + require('util').inspect(search));

if (parts.hostname.search(search.pattern) != -1) {
info['search_engine'] = search.name;
info['search_keywords'] = parts.query['q'];
info['search_keywords'] = parts.query[search.var];

/* Special case for Google Image Search */
if (typeof parts.query['prev'] != 'undefined' && parts.query['prev'].length > 0) {
var dparts = require('url').parse(parts.query['prev'], true);
info['search_keywords'] = dparts.query[search.var];
}

found = true;
break;
}
Expand Down

0 comments on commit 73b7477

Please sign in to comment.