songkickr 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +6 -2
- data/Gemfile.lock +32 -10
- data/README.rdoc +7 -7
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/bin/autospec +16 -0
- data/bin/convert_to_should_syntax +16 -0
- data/bin/guard +16 -0
- data/bin/htmldiff +16 -0
- data/bin/httparty +16 -0
- data/bin/jeweler +16 -0
- data/bin/ldiff +16 -0
- data/bin/rake +16 -0
- data/bin/rake2thor +16 -0
- data/bin/rg +16 -0
- data/bin/ri +16 -0
- data/bin/rspec +16 -0
- data/bin/thor +16 -0
- data/doc/APIError.html +241 -0
- data/doc/APIKeyNotSet.html +164 -175
- data/doc/LICENSE.html +109 -109
- data/doc/README_rdoc.html +120 -117
- data/doc/ResourceNotFound.html +203 -0
- data/doc/Songkickr/Artist.html +210 -237
- data/doc/Songkickr/ArtistResult.html +228 -254
- data/doc/Songkickr/ConcertSetlistResult.html +205 -223
- data/doc/Songkickr/Event.html +344 -409
- data/doc/Songkickr/EventResult.html +226 -252
- data/doc/Songkickr/Location.html +210 -237
- data/doc/Songkickr/LocationResult.html +229 -255
- data/doc/Songkickr/Performance.html +222 -253
- data/doc/Songkickr/Remote.html +630 -481
- data/doc/Songkickr/Setlist.html +258 -296
- data/doc/Songkickr/SetlistItem.html +187 -206
- data/doc/Songkickr/Venue.html +205 -232
- data/doc/Songkickr.html +204 -271
- data/doc/created.rid +16 -16
- data/doc/images/add.png +0 -0
- data/doc/images/delete.png +0 -0
- data/doc/images/tag_blue.png +0 -0
- data/doc/images/transparent.png +0 -0
- data/doc/index.html +93 -127
- data/doc/js/darkfish.js +99 -62
- data/doc/js/jquery.js +15 -29
- data/doc/js/navigation.js +142 -0
- data/doc/js/search.js +94 -0
- data/doc/js/search_index.js +1 -0
- data/doc/js/searcher.js +228 -0
- data/doc/rdoc.css +119 -339
- data/doc/table_of_contents.html +185 -0
- data/lib/songkickr/artist.rb +3 -3
- data/lib/songkickr/remote.rb +36 -13
- data/lib/songkickr.rb +16 -2
- data/songkickr.gemspec +121 -4
- data/test/fixtures/vcr/invalid_api_key.yml +63 -0
- data/test/fixtures/vcr/invalid_event_id.yml +33 -0
- data/test/fixtures/vcr/invalid_user.yml +32 -0
- data/test/fixtures/vcr/invalid_venue_id.yml +33 -0
- data/test/fixtures/vcr/valid_event.yml +52 -0
- data/test/fixtures/vcr/valid_user.yml +71 -0
- data/test/fixtures/vcr/valid_venue.yml +53 -0
- data/test/helper.rb +2 -2
- data/test/songkickr/test_remote.rb +68 -24
- data/test/vcr_helper.rb +7 -0
- data/test.rb +2 -2
- metadata +626 -40
data/doc/js/search.js
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
Search = function(data, input, result) {
|
2
|
+
this.data = data;
|
3
|
+
this.$input = $(input);
|
4
|
+
this.$result = $(result);
|
5
|
+
|
6
|
+
this.$current = null;
|
7
|
+
this.$view = this.$result.parent();
|
8
|
+
this.searcher = new Searcher(data.index);
|
9
|
+
this.init();
|
10
|
+
}
|
11
|
+
|
12
|
+
Search.prototype = $.extend({}, Navigation, new function() {
|
13
|
+
var suid = 1;
|
14
|
+
|
15
|
+
this.init = function() {
|
16
|
+
var _this = this;
|
17
|
+
var observer = function() {
|
18
|
+
_this.search(_this.$input[0].value);
|
19
|
+
};
|
20
|
+
this.$input.keyup(observer);
|
21
|
+
this.$input.click(observer); // mac's clear field
|
22
|
+
|
23
|
+
this.searcher.ready(function(results, isLast) {
|
24
|
+
_this.addResults(results, isLast);
|
25
|
+
})
|
26
|
+
|
27
|
+
this.initNavigation();
|
28
|
+
this.setNavigationActive(false);
|
29
|
+
}
|
30
|
+
|
31
|
+
this.search = function(value, selectFirstMatch) {
|
32
|
+
value = jQuery.trim(value).toLowerCase();
|
33
|
+
if (value) {
|
34
|
+
this.setNavigationActive(true);
|
35
|
+
} else {
|
36
|
+
this.setNavigationActive(false);
|
37
|
+
}
|
38
|
+
|
39
|
+
if (value == '') {
|
40
|
+
this.lastQuery = value;
|
41
|
+
this.$result.empty();
|
42
|
+
this.setNavigationActive(false);
|
43
|
+
} else if (value != this.lastQuery) {
|
44
|
+
this.lastQuery = value;
|
45
|
+
this.firstRun = true;
|
46
|
+
this.searcher.find(value);
|
47
|
+
}
|
48
|
+
}
|
49
|
+
|
50
|
+
this.addResults = function(results, isLast) {
|
51
|
+
var target = this.$result.get(0);
|
52
|
+
if (this.firstRun && (results.length > 0 || isLast)) {
|
53
|
+
this.$current = null;
|
54
|
+
this.$result.empty();
|
55
|
+
}
|
56
|
+
|
57
|
+
for (var i=0, l = results.length; i < l; i++) {
|
58
|
+
target.appendChild(this.renderItem.call(this, results[i]));
|
59
|
+
};
|
60
|
+
|
61
|
+
if (this.firstRun && results.length > 0) {
|
62
|
+
this.firstRun = false;
|
63
|
+
this.$current = $(target.firstChild);
|
64
|
+
this.$current.addClass('current');
|
65
|
+
}
|
66
|
+
if (jQuery.browser.msie) this.$element[0].className += '';
|
67
|
+
}
|
68
|
+
|
69
|
+
this.move = function(isDown) {
|
70
|
+
if (!this.$current) return;
|
71
|
+
var $next = this.$current[isDown ? 'next' : 'prev']();
|
72
|
+
if ($next.length) {
|
73
|
+
this.$current.removeClass('current');
|
74
|
+
$next.addClass('current');
|
75
|
+
this.scrollIntoView($next[0], this.$view[0]);
|
76
|
+
this.$current = $next;
|
77
|
+
}
|
78
|
+
return true;
|
79
|
+
}
|
80
|
+
|
81
|
+
this.hlt = function(html) {
|
82
|
+
return this.escapeHTML(html).
|
83
|
+
replace(/\u0001/g, '<em>').
|
84
|
+
replace(/\u0002/g, '</em>');
|
85
|
+
}
|
86
|
+
|
87
|
+
this.escapeHTML = function(html) {
|
88
|
+
return html.replace(/[&<>]/g, function(c) {
|
89
|
+
return '&#' + c.charCodeAt(0) + ';';
|
90
|
+
});
|
91
|
+
}
|
92
|
+
|
93
|
+
});
|
94
|
+
|
@@ -0,0 +1 @@
|
|
1
|
+
var search_data = {"index":{"searchIndex":["apierror","apikeynotset","resourcenotfound","songkickr","artist","artistresult","concertsetlistresult","event","eventresult","location","locationresult","performance","remote","setlist","setlistitem","venue","api_key()","api_key=()","artist_events()","artist_search()","concert_setlists()","event()","events()","get()","gigography()","location_search()","metro_areas_events()","new()","new()","new()","new()","new()","new()","new()","new()","new()","new()","new()","new()","new()","parse_performance()","parse_results()","parse_results()","parse_results()","parse_results()","parse_setlist_items()","start_hash_to_datetime()","to_s()","to_s()","to_s()","users_events()","users_tracked_artists()","venue()","license","readme"],"longSearchIndex":["apierror","apikeynotset","resourcenotfound","songkickr","songkickr::artist","songkickr::artistresult","songkickr::concertsetlistresult","songkickr::event","songkickr::eventresult","songkickr::location","songkickr::locationresult","songkickr::performance","songkickr::remote","songkickr::setlist","songkickr::setlistitem","songkickr::venue","songkickr::api_key()","songkickr::api_key=()","songkickr::remote#artist_events()","songkickr::remote#artist_search()","songkickr::remote#concert_setlists()","songkickr::remote#event()","songkickr::remote#events()","songkickr::remote#get()","songkickr::remote#gigography()","songkickr::remote#location_search()","songkickr::remote#metro_areas_events()","apierror::new()","songkickr::artist::new()","songkickr::artistresult::new()","songkickr::concertsetlistresult::new()","songkickr::event::new()","songkickr::eventresult::new()","songkickr::location::new()","songkickr::locationresult::new()","songkickr::performance::new()","songkickr::remote::new()","songkickr::setlist::new()","songkickr::setlistitem::new()","songkickr::venue::new()","songkickr::event#parse_performance()","songkickr::artistresult#parse_results()","songkickr::concertsetlistresult#parse_results()","songkickr::eventresult#parse_results()","songkickr::locationresult#parse_results()","songkickr::setlist#parse_setlist_items()","songkickr::event#start_hash_to_datetime()","apierror#to_s()","apikeynotset#to_s()","resourcenotfound#to_s()","songkickr::remote#users_events()","songkickr::remote#users_tracked_artists()","songkickr::remote#venue()","",""],"info":[["APIError","","APIError.html","",""],["APIKeyNotSet","","APIKeyNotSet.html","",""],["ResourceNotFound","","ResourceNotFound.html","",""],["Songkickr","","Songkickr.html","",""],["Songkickr::Artist","","Songkickr/Artist.html","","<p>A single artist\n\n<pre>{\n "uri":"http://www.songkick.com/artists/253846-radiohead",\n "displayName":"Radiohead", ...</pre>\n"],["Songkickr::ArtistResult","","Songkickr/ArtistResult.html","","<p>A class to represent the result hash of an Artist search.\n"],["Songkickr::ConcertSetlistResult","","Songkickr/ConcertSetlistResult.html","","<p>A class to represent the result hash of an Setlist search.\n<p>www.songkick.com/developer/setlists\n"],["Songkickr::Event","","Songkickr/Event.html","","<p>A single event\n\n<pre>{\n "displayName": "Vampire Weekend at O2 Academy Brixton (February 16, 2010)",\n "type": ...</pre>\n"],["Songkickr::EventResult","","Songkickr/EventResult.html","","<p>A class to represent the result hash of an Event search.\n"],["Songkickr::Location","","Songkickr/Location.html","","<p>A class to represent the hash of a Location.\n\n<pre>{\n "city":{\n "displayName":"London",\n "country":{ ...</pre>\n"],["Songkickr::LocationResult","","Songkickr/LocationResult.html","","<p>TODO: very similar to concert_setlist_result, event_result, and\nartist_result, extract common stuff to …\n"],["Songkickr::Performance","","Songkickr/Performance.html","","<p>A single performance by an artist.\n\n<pre>{\n "artist": {\n "uri": "http://www.songkick.com/artists/288696-vampire-weekend", ...</pre>\n"],["Songkickr::Remote","","Songkickr/Remote.html","","<p>Create an instance of the remote class to interact with the Songkick API.\n"],["Songkickr::Setlist","","Songkickr/Setlist.html","","<p>A single set list by an artist.\n<p>{\n\n<pre>"displayName": "N.E.R.D. at Glastonbury Festival 2009",\n"artist": {\n ...</pre>\n"],["Songkickr::SetlistItem","","Songkickr/SetlistItem.html","","<p>A single set list item.\n\n<pre>{\n encore: 0\n name: "Anti Matter "\n}</pre>\n"],["Songkickr::Venue","","Songkickr/Venue.html","",""],["api_key","Songkickr","Songkickr.html#method-c-api_key","()","<p>Returns the Songkick API key In order to use the Songkick API, you must\nhave a Songkick API (their rule, …\n"],["api_key=","Songkickr","Songkickr.html#method-c-api_key-3D","(api_key)","<p>Set the API key. In the event you need to set the API key after\ninitializing the the remote.\n<p>Parameters …\n"],["artist_events","Songkickr::Remote","Songkickr/Remote.html#method-i-artist_events","(artist_id, query = {})","<p>Artist calendar (Upcoming)\n<p>Returns an array of Events.\n<p>www.songkick.com/developer/upcoming-events-for-artist …\n"],["artist_search","Songkickr::Remote","Songkickr/Remote.html#method-i-artist_search","(query={})","<p>Artist Search API\n<p>Returns Artist objects.\n<p>www.songkick.com/developer/artist-search\n"],["concert_setlists","Songkickr::Remote","Songkickr/Remote.html#method-i-concert_setlists","(event_id)","<p>Concert Setlists API\n<p>www.songkick.com/developer/setlists\n<p>Parameters\n"],["event","Songkickr::Remote","Songkickr/Remote.html#method-i-event","(event_id)","<p>Event API\n<p>www.songkick.com/developer/upcoming-events\n<p>Getting detailed information of a single event.\n"],["events","Songkickr::Remote","Songkickr/Remote.html#method-i-events","(query = {})","<p>Event Search API\n<p>www.songkick.com/developer/event-search\n<p>Parameters\n"],["get","Songkickr::Remote","Songkickr/Remote.html#method-i-get","(location, query_params = {})",""],["gigography","Songkickr::Remote","Songkickr/Remote.html#method-i-gigography","(artist_id, query= {})","<p>Gigography API\n<p>groups.google.com/group/songkick-api/browse_thread/thread/af15b9a6ad3c3513#\n<p>Parameters\n"],["location_search","Songkickr::Remote","Songkickr/Remote.html#method-i-location_search","(query = {})","<p>Location Search API\n<p>www.songkick.com/developer/location-search\n<p>Parameters\n"],["metro_areas_events","Songkickr::Remote","Songkickr/Remote.html#method-i-metro_areas_events","(metro_area_id, query = {})","<p>Metro Area Events (Upcoming)\n<p>Returns an array of Events.\n<p>www.songkick.com/developer/upcoming-events-for-metro-area …\n"],["new","APIError","APIError.html#method-c-new","(message = \"API Error\")",""],["new","Songkickr::Artist","Songkickr/Artist.html#method-c-new","(artist_hash = {})","<p>Accepts a hash of artist attributes.\n"],["new","Songkickr::ArtistResult","Songkickr/ArtistResult.html#method-c-new","(result_hash = {})","<p>Takes the result hash directly and parses out the page and total entries\nand finally passes off to the …\n"],["new","Songkickr::ConcertSetlistResult","Songkickr/ConcertSetlistResult.html#method-c-new","(result_hash = {})","<p>Takes the result ash and passes it to parse_results\n"],["new","Songkickr::Event","Songkickr/Event.html#method-c-new","(event_hash)",""],["new","Songkickr::EventResult","Songkickr/EventResult.html#method-c-new","(result_hash = {})","<p>Takes the result hash directly and parses out the page and total entries\nand finally passes off to the …\n"],["new","Songkickr::Location","Songkickr/Location.html#method-c-new","(location_hash)","<p>Takes a location hash. Handles the different city hashes from Event and\nLocation\n"],["new","Songkickr::LocationResult","Songkickr/LocationResult.html#method-c-new","(result_hash = {})","<p>Takes the result hash directly and parses out the page and total entries\nand finally passes off to the …\n"],["new","Songkickr::Performance","Songkickr/Performance.html#method-c-new","(performance_hash)","<p>Takes a the hash of the performance. Parses out an Artist object for the\nartist.\n"],["new","Songkickr::Remote","Songkickr/Remote.html#method-c-new","(api_key = nil)","<p>Create a new instance of the remote class to talk to Songkick\n<p>Get an API key for your app from developer.songkick.com/ …\n"],["new","Songkickr::Setlist","Songkickr/Setlist.html#method-c-new","(setlist_hash)","<p>Takes the setlist hash and parses out an Event and Artist and an array of\nSetlistItems.\n"],["new","Songkickr::SetlistItem","Songkickr/SetlistItem.html#method-c-new","(setlist_item_hash)","<p>Takes the set list item hash and parses a boolean out for encore.\n"],["new","Songkickr::Venue","Songkickr/Venue.html#method-c-new","(venue_hash)",""],["parse_performance","Songkickr::Event","Songkickr/Event.html#method-i-parse_performance","(performance_array = nil)","<p>Builds a list of Performance objects.\n"],["parse_results","Songkickr::ArtistResult","Songkickr/ArtistResult.html#method-i-parse_results","(results = {})","<p>Take the results hash directly and parse the artists into Artist objects.\n<p>Returns an array of Artists …\n"],["parse_results","Songkickr::ConcertSetlistResult","Songkickr/ConcertSetlistResult.html#method-i-parse_results","(results = {})","<p>Parses the setlist items into an array of SetlistItems\n"],["parse_results","Songkickr::EventResult","Songkickr/EventResult.html#method-i-parse_results","(results = {})",""],["parse_results","Songkickr::LocationResult","Songkickr/LocationResult.html#method-i-parse_results","(results = {})","<p>Take the results hash directly and parse the locations into Location\nobjects.\n<p>Returns an array of Locations …\n"],["parse_setlist_items","Songkickr::Setlist","Songkickr/Setlist.html#method-i-parse_setlist_items","(setlist_item_array = nil)","<p>Takes the array of setlist items and create SetLists\n"],["start_hash_to_datetime","Songkickr::Event","Songkickr/Event.html#method-i-start_hash_to_datetime","(start_hash)","<p>Takes the start hash and turns in into a DateTime object.\n"],["to_s","APIError","APIError.html#method-i-to_s","()",""],["to_s","APIKeyNotSet","APIKeyNotSet.html#method-i-to_s","()","<p>Warns of missing API key\n"],["to_s","ResourceNotFound","ResourceNotFound.html#method-i-to_s","()",""],["users_events","Songkickr::Remote","Songkickr/Remote.html#method-i-users_events","(username, query = {})","<p>User Events API\n<p>www.songkick.com/developer/upcoming-events-for-user\n<p>Parameters\n"],["users_tracked_artists","Songkickr::Remote","Songkickr/Remote.html#method-i-users_tracked_artists","(username, query = {})","<p>User Tracked Artists\n<p>www.songkick.com/developer/trackings\n<p>Parameters\n"],["venue","Songkickr::Remote","Songkickr/Remote.html#method-i-venue","(venue_id)","<p>Venue Search\n<p>www.songkick.com/developer/venue-details\n<p>Parameters\n"],["LICENSE","","LICENSE.html","","<p>Copyright © 2010-2011 Jared Mehle\n<p>Permission is hereby granted, free of charge, to any person obtaining …\n"],["README","","README_rdoc.html","","<p>songkickr\n<p>A Ruby wrapper around the Songkick API. Visit www.songkick.com/developer\nfor documentation on …\n"]]}}
|
data/doc/js/searcher.js
ADDED
@@ -0,0 +1,228 @@
|
|
1
|
+
Searcher = function(data) {
|
2
|
+
this.data = data;
|
3
|
+
this.handlers = [];
|
4
|
+
}
|
5
|
+
|
6
|
+
Searcher.prototype = new function() {
|
7
|
+
// search is performed in chunks of 1000 for non-blocking user input
|
8
|
+
var CHUNK_SIZE = 1000;
|
9
|
+
// do not try to find more than 100 results
|
10
|
+
var MAX_RESULTS = 100;
|
11
|
+
var huid = 1;
|
12
|
+
var suid = 1;
|
13
|
+
var runs = 0;
|
14
|
+
|
15
|
+
this.find = function(query) {
|
16
|
+
var queries = splitQuery(query);
|
17
|
+
var regexps = buildRegexps(queries);
|
18
|
+
var highlighters = buildHilighters(queries);
|
19
|
+
var state = { from: 0, pass: 0, limit: MAX_RESULTS, n: suid++};
|
20
|
+
var _this = this;
|
21
|
+
|
22
|
+
this.currentSuid = state.n;
|
23
|
+
|
24
|
+
if (!query) return;
|
25
|
+
|
26
|
+
var run = function() {
|
27
|
+
// stop current search thread if new search started
|
28
|
+
if (state.n != _this.currentSuid) return;
|
29
|
+
|
30
|
+
var results =
|
31
|
+
performSearch(_this.data, regexps, queries, highlighters, state);
|
32
|
+
var hasMore = (state.limit > 0 && state.pass < 4);
|
33
|
+
|
34
|
+
triggerResults.call(_this, results, !hasMore);
|
35
|
+
if (hasMore) {
|
36
|
+
setTimeout(run, 2);
|
37
|
+
}
|
38
|
+
runs++;
|
39
|
+
};
|
40
|
+
runs = 0;
|
41
|
+
|
42
|
+
// start search thread
|
43
|
+
run();
|
44
|
+
}
|
45
|
+
|
46
|
+
/* ----- Events ------ */
|
47
|
+
this.ready = function(fn) {
|
48
|
+
fn.huid = huid;
|
49
|
+
this.handlers.push(fn);
|
50
|
+
}
|
51
|
+
|
52
|
+
/* ----- Utilities ------ */
|
53
|
+
function splitQuery(query) {
|
54
|
+
return jQuery.grep(query.split(/(\s+|::?|\(\)?)/), function(string) {
|
55
|
+
return string.match(/\S/)
|
56
|
+
});
|
57
|
+
}
|
58
|
+
|
59
|
+
function buildRegexps(queries) {
|
60
|
+
return jQuery.map(queries, function(query) {
|
61
|
+
return new RegExp(query.replace(/(.)/g, '([$1])([^$1]*?)'), 'i')
|
62
|
+
});
|
63
|
+
}
|
64
|
+
|
65
|
+
function buildHilighters(queries) {
|
66
|
+
return jQuery.map(queries, function(query) {
|
67
|
+
return jQuery.map(query.split(''), function(l, i) {
|
68
|
+
return '\u0001$' + (i*2+1) + '\u0002$' + (i*2+2);
|
69
|
+
}).join('');
|
70
|
+
});
|
71
|
+
}
|
72
|
+
|
73
|
+
// function longMatchRegexp(index, longIndex, regexps) {
|
74
|
+
// for (var i = regexps.length - 1; i >= 0; i--){
|
75
|
+
// if (!index.match(regexps[i]) && !longIndex.match(regexps[i])) return false;
|
76
|
+
// };
|
77
|
+
// return true;
|
78
|
+
// }
|
79
|
+
|
80
|
+
|
81
|
+
/* ----- Mathchers ------ */
|
82
|
+
|
83
|
+
/*
|
84
|
+
* This record matches if the index starts with queries[0] and the record
|
85
|
+
* matches all of the regexps
|
86
|
+
*/
|
87
|
+
function matchPassBeginning(index, longIndex, queries, regexps) {
|
88
|
+
if (index.indexOf(queries[0]) != 0) return false;
|
89
|
+
for (var i=1, l = regexps.length; i < l; i++) {
|
90
|
+
if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
|
91
|
+
return false;
|
92
|
+
};
|
93
|
+
return true;
|
94
|
+
}
|
95
|
+
|
96
|
+
/*
|
97
|
+
* This record matches if the longIndex starts with queries[0] and the
|
98
|
+
* longIndex matches all of the regexps
|
99
|
+
*/
|
100
|
+
function matchPassLongIndex(index, longIndex, queries, regexps) {
|
101
|
+
if (longIndex.indexOf(queries[0]) != 0) return false;
|
102
|
+
for (var i=1, l = regexps.length; i < l; i++) {
|
103
|
+
if (!longIndex.match(regexps[i]))
|
104
|
+
return false;
|
105
|
+
};
|
106
|
+
return true;
|
107
|
+
}
|
108
|
+
|
109
|
+
/*
|
110
|
+
* This record matches if the index contains queries[0] and the record
|
111
|
+
* matches all of the regexps
|
112
|
+
*/
|
113
|
+
function matchPassContains(index, longIndex, queries, regexps) {
|
114
|
+
if (index.indexOf(queries[0]) == -1) return false;
|
115
|
+
for (var i=1, l = regexps.length; i < l; i++) {
|
116
|
+
if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
|
117
|
+
return false;
|
118
|
+
};
|
119
|
+
return true;
|
120
|
+
}
|
121
|
+
|
122
|
+
/*
|
123
|
+
* This record matches if regexps[0] matches the index and the record
|
124
|
+
* matches all of the regexps
|
125
|
+
*/
|
126
|
+
function matchPassRegexp(index, longIndex, queries, regexps) {
|
127
|
+
if (!index.match(regexps[0])) return false;
|
128
|
+
for (var i=1, l = regexps.length; i < l; i++) {
|
129
|
+
if (!index.match(regexps[i]) && !longIndex.match(regexps[i]))
|
130
|
+
return false;
|
131
|
+
};
|
132
|
+
return true;
|
133
|
+
}
|
134
|
+
|
135
|
+
|
136
|
+
/* ----- Highlighters ------ */
|
137
|
+
function highlightRegexp(info, queries, regexps, highlighters) {
|
138
|
+
var result = createResult(info);
|
139
|
+
for (var i=0, l = regexps.length; i < l; i++) {
|
140
|
+
result.title = result.title.replace(regexps[i], highlighters[i]);
|
141
|
+
result.namespace = result.namespace.replace(regexps[i], highlighters[i]);
|
142
|
+
};
|
143
|
+
return result;
|
144
|
+
}
|
145
|
+
|
146
|
+
function hltSubstring(string, pos, length) {
|
147
|
+
return string.substring(0, pos) + '\u0001' + string.substring(pos, pos + length) + '\u0002' + string.substring(pos + length);
|
148
|
+
}
|
149
|
+
|
150
|
+
function highlightQuery(info, queries, regexps, highlighters) {
|
151
|
+
var result = createResult(info);
|
152
|
+
var pos = 0;
|
153
|
+
var lcTitle = result.title.toLowerCase();
|
154
|
+
|
155
|
+
pos = lcTitle.indexOf(queries[0]);
|
156
|
+
if (pos != -1) {
|
157
|
+
result.title = hltSubstring(result.title, pos, queries[0].length);
|
158
|
+
}
|
159
|
+
|
160
|
+
result.namespace = result.namespace.replace(regexps[0], highlighters[0]);
|
161
|
+
for (var i=1, l = regexps.length; i < l; i++) {
|
162
|
+
result.title = result.title.replace(regexps[i], highlighters[i]);
|
163
|
+
result.namespace = result.namespace.replace(regexps[i], highlighters[i]);
|
164
|
+
};
|
165
|
+
return result;
|
166
|
+
}
|
167
|
+
|
168
|
+
function createResult(info) {
|
169
|
+
var result = {};
|
170
|
+
result.title = info[0];
|
171
|
+
result.namespace = info[1];
|
172
|
+
result.path = info[2];
|
173
|
+
result.params = info[3];
|
174
|
+
result.snippet = info[4];
|
175
|
+
return result;
|
176
|
+
}
|
177
|
+
|
178
|
+
/* ----- Searching ------ */
|
179
|
+
function performSearch(data, regexps, queries, highlighters, state) {
|
180
|
+
var searchIndex = data.searchIndex;
|
181
|
+
var longSearchIndex = data.longSearchIndex;
|
182
|
+
var info = data.info;
|
183
|
+
var result = [];
|
184
|
+
var i = state.from;
|
185
|
+
var l = searchIndex.length;
|
186
|
+
var togo = CHUNK_SIZE;
|
187
|
+
var matchFunc, hltFunc;
|
188
|
+
|
189
|
+
while (state.pass < 4 && state.limit > 0 && togo > 0) {
|
190
|
+
if (state.pass == 0) {
|
191
|
+
matchFunc = matchPassBeginning;
|
192
|
+
hltFunc = highlightQuery;
|
193
|
+
} else if (state.pass == 1) {
|
194
|
+
matchFunc = matchPassLongIndex;
|
195
|
+
hltFunc = highlightQuery;
|
196
|
+
} else if (state.pass == 2) {
|
197
|
+
matchFunc = matchPassContains;
|
198
|
+
hltFunc = highlightQuery;
|
199
|
+
} else if (state.pass == 3) {
|
200
|
+
matchFunc = matchPassRegexp;
|
201
|
+
hltFunc = highlightRegexp;
|
202
|
+
}
|
203
|
+
|
204
|
+
for (; togo > 0 && i < l && state.limit > 0; i++, togo--) {
|
205
|
+
if (info[i].n == state.n) continue;
|
206
|
+
if (matchFunc(searchIndex[i], longSearchIndex[i], queries, regexps)) {
|
207
|
+
info[i].n = state.n;
|
208
|
+
result.push(hltFunc(info[i], queries, regexps, highlighters));
|
209
|
+
state.limit--;
|
210
|
+
}
|
211
|
+
};
|
212
|
+
if (searchIndex.length <= i) {
|
213
|
+
state.pass++;
|
214
|
+
i = state.from = 0;
|
215
|
+
} else {
|
216
|
+
state.from = i;
|
217
|
+
}
|
218
|
+
}
|
219
|
+
return result;
|
220
|
+
}
|
221
|
+
|
222
|
+
function triggerResults(results, isLast) {
|
223
|
+
jQuery.each(this.handlers, function(i, fn) {
|
224
|
+
fn.call(this, results, isLast)
|
225
|
+
})
|
226
|
+
}
|
227
|
+
}
|
228
|
+
|