sycsvpro 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +3 -1
- data/README.md +21 -8
- data/README.rdoc +3 -2
- data/bin/sycsvpro +17 -6
- data/lib/sycsvpro/aggregator.rb +16 -5
- data/lib/sycsvpro/calculator.rb +19 -5
- data/lib/sycsvpro/counter.rb +17 -7
- data/lib/sycsvpro/dsl.rb +43 -0
- data/lib/sycsvpro/filter.rb +0 -7
- data/lib/sycsvpro/sorter.rb +28 -8
- data/lib/sycsvpro/version.rb +1 -1
- data/spec/sycsvpro/sorter_spec.rb +50 -0
- data/sycsvpro.gemspec +1 -0
- metadata +18 -66
- data/html/Dsl.html +0 -277
- data/html/Object.html +0 -187
- data/html/README_rdoc.html +0 -187
- data/html/Sycsvpro/Aggregator.html +0 -482
- data/html/Sycsvpro/Allocator.html +0 -293
- data/html/Sycsvpro/Analyzer.html +0 -239
- data/html/Sycsvpro/Calculator.html +0 -407
- data/html/Sycsvpro/Collector.html +0 -281
- data/html/Sycsvpro/ColumnFilter.html +0 -170
- data/html/Sycsvpro/ColumnTypeFilter.html +0 -191
- data/html/Sycsvpro/Counter.html +0 -492
- data/html/Sycsvpro/Extractor.html +0 -269
- data/html/Sycsvpro/Filter.html +0 -411
- data/html/Sycsvpro/Header.html +0 -239
- data/html/Sycsvpro/Inserter.html +0 -275
- data/html/Sycsvpro/Mapper.html +0 -288
- data/html/Sycsvpro/Profiler.html +0 -234
- data/html/Sycsvpro/RowFilter.html +0 -175
- data/html/Sycsvpro/ScriptCreator.html +0 -235
- data/html/Sycsvpro/ScriptList.html +0 -281
- data/html/Sycsvpro/Sorter.html +0 -346
- data/html/Sycsvpro.html +0 -155
- data/html/created.rid +0 -24
- data/html/fonts/Lato-Light.ttf +0 -0
- data/html/fonts/Lato-LightItalic.ttf +0 -0
- data/html/fonts/Lato-Regular.ttf +0 -0
- data/html/fonts/Lato-RegularItalic.ttf +0 -0
- data/html/fonts/SourceCodePro-Bold.ttf +0 -0
- data/html/fonts/SourceCodePro-Regular.ttf +0 -0
- data/html/fonts.css +0 -167
- data/html/images/add.png +0 -0
- data/html/images/arrow_up.png +0 -0
- data/html/images/brick.png +0 -0
- data/html/images/brick_link.png +0 -0
- data/html/images/bug.png +0 -0
- data/html/images/bullet_black.png +0 -0
- data/html/images/bullet_toggle_minus.png +0 -0
- data/html/images/bullet_toggle_plus.png +0 -0
- data/html/images/date.png +0 -0
- data/html/images/delete.png +0 -0
- data/html/images/find.png +0 -0
- data/html/images/loadingAnimation.gif +0 -0
- data/html/images/macFFBgHack.png +0 -0
- data/html/images/package.png +0 -0
- data/html/images/page_green.png +0 -0
- data/html/images/page_white_text.png +0 -0
- data/html/images/page_white_width.png +0 -0
- data/html/images/plugin.png +0 -0
- data/html/images/ruby.png +0 -0
- data/html/images/tag_blue.png +0 -0
- data/html/images/tag_green.png +0 -0
- data/html/images/transparent.png +0 -0
- data/html/images/wrench.png +0 -0
- data/html/images/wrench_orange.png +0 -0
- data/html/images/zoom.png +0 -0
- data/html/index.html +0 -225
- data/html/js/darkfish.js +0 -140
- data/html/js/jquery.js +0 -18
- data/html/js/navigation.js +0 -142
- data/html/js/search.js +0 -109
- data/html/js/search_index.js +0 -1
- data/html/js/searcher.js +0 -228
- data/html/rdoc.css +0 -580
- data/html/table_of_contents.html +0 -347
data/html/js/search_index.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
var search_data = {"index":{"searchIndex":["dsl","object","sycsvpro","aggregator","allocator","analyzer","calculator","collector","columnfilter","columntypefilter","counter","extractor","filter","header","inserter","mapper","profiler","rowfilter","scriptcreator","scriptlist","sorter","execute()","execute()","execute()","execute()","execute()","execute()","execute()","execute()","execute()","execute()","execute()","has_filter?()","method_missing()","method_missing()","new()","new()","new()","new()","new()","new()","new()","new()","new()","new()","new()","new()","new()","new()","new()","pivot_each_column()","process()","process()","process()","process()","process()","process_aggregation()","process_count()","result()","rows()","set_max_row()","str2utf8()","unstring()","write_result()","write_result()","write_to()","readme"],"longSearchIndex":["dsl","object","sycsvpro","sycsvpro::aggregator","sycsvpro::allocator","sycsvpro::analyzer","sycsvpro::calculator","sycsvpro::collector","sycsvpro::columnfilter","sycsvpro::columntypefilter","sycsvpro::counter","sycsvpro::extractor","sycsvpro::filter","sycsvpro::header","sycsvpro::inserter","sycsvpro::mapper","sycsvpro::profiler","sycsvpro::rowfilter","sycsvpro::scriptcreator","sycsvpro::scriptlist","sycsvpro::sorter","sycsvpro::aggregator#execute()","sycsvpro::allocator#execute()","sycsvpro::calculator#execute()","sycsvpro::collector#execute()","sycsvpro::counter#execute()","sycsvpro::extractor#execute()","sycsvpro::inserter#execute()","sycsvpro::mapper#execute()","sycsvpro::profiler#execute()","sycsvpro::scriptlist#execute()","sycsvpro::sorter#execute()","sycsvpro::filter#has_filter?()","sycsvpro::calculator#method_missing()","sycsvpro::filter#method_missing()","sycsvpro::aggregator::new()","sycsvpro::allocator::new()","sycsvpro::analyzer::new()","sycsvpro::calculator::new()","sycsvpro::collector::new()","sycsvpro::counter::new()","sycsvpro::extractor::new()","sycsvpro::filter::new()","sycsvpro::header::new()","sycsvpro::inserter::new()","sycsvpro::mapper::new()","sycsvpro::profiler::new()","sycsvpro::scriptcreator::new()","sycsvpro::scriptlist::new()","sycsvpro::sorter::new()","sycsvpro::filter#pivot_each_column()","sycsvpro::columnfilter#process()","sycsvpro::columntypefilter#process()","sycsvpro::filter#process()","sycsvpro::header#process()","sycsvpro::rowfilter#process()","sycsvpro::aggregator#process_aggregation()","sycsvpro::counter#process_count()","sycsvpro::analyzer#result()","dsl#rows()","object#set_max_row()","dsl#str2utf8()","dsl#unstring()","sycsvpro::aggregator#write_result()","sycsvpro::counter#write_result()","dsl#write_to()",""],"info":[["Dsl","","Dsl.html","","<p>Methods to be used in customer specific script files\n"],["Object","","Object.html","",""],["Sycsvpro","","Sycsvpro.html","","<p>Operating csv files\n<p>Operating csv files\n<p>Operating csv files\n"],["Sycsvpro::Aggregator","","Sycsvpro/Aggregator.html","","<p>An Aggregator counts specified row values and adds a sum to the end of the\nrow\n"],["Sycsvpro::Allocator","","Sycsvpro/Allocator.html","","<p>Allocates columns to a key column\n"],["Sycsvpro::Analyzer","","Sycsvpro/Analyzer.html","","<p>Analyzes the file structure\n"],["Sycsvpro::Calculator","","Sycsvpro/Calculator.html","","<p>Processes arithmetic operations on columns of a csv file. A column value\nhas to be a number. Possible …\n"],["Sycsvpro::Collector","","Sycsvpro/Collector.html","","<p>Collects values from rows and groups them in categories\n"],["Sycsvpro::ColumnFilter","","Sycsvpro/ColumnFilter.html","","<p>Creates a new column filter\n"],["Sycsvpro::ColumnTypeFilter","","Sycsvpro/ColumnTypeFilter.html","","<p>Create a filter based on a colum and its type\n"],["Sycsvpro::Counter","","Sycsvpro/Counter.html","","<p>Counter counts values and uses the values as column names and uses the\ncount as the column value\n"],["Sycsvpro::Extractor","","Sycsvpro/Extractor.html","","<p>Extracts rows and columns from a csv file\n"],["Sycsvpro::Filter","","Sycsvpro/Filter.html","","<p>Creates a new filter that can be extended by sub-classes. A sub-class needs\nto override the process method …\n"],["Sycsvpro::Header","","Sycsvpro/Header.html","","<p>Creates a header\n"],["Sycsvpro::Inserter","","Sycsvpro/Inserter.html","","<p>Insert a text file into another textfile at a specified position\n"],["Sycsvpro::Mapper","","Sycsvpro/Mapper.html","","<p>Map values to new values described in a mapping file\n"],["Sycsvpro::Profiler","","Sycsvpro/Profiler.html","","<p>A profiler takes a Ruby script and executes the provided method in the\nscript\n"],["Sycsvpro::RowFilter","","Sycsvpro/RowFilter.html","","<p>Filters rows based on provided patterns\n"],["Sycsvpro::ScriptCreator","","Sycsvpro/ScriptCreator.html","","<p>Creates a ruby script scaffold\n"],["Sycsvpro::ScriptList","","Sycsvpro/ScriptList.html","","<p>Lists the contents of the script directory. Optionally listing a specific\nscript file and also optionally …\n"],["Sycsvpro::Sorter","","Sycsvpro/Sorter.html","","<p>Sorts an input file based on a column sort filter\n"],["execute","Sycsvpro::Aggregator","Sycsvpro/Aggregator.html#method-i-execute","()","<p>Executes the aggregator\n"],["execute","Sycsvpro::Allocator","Sycsvpro/Allocator.html#method-i-execute","()","<p>Executes the allocator and assigns column values to the key\n"],["execute","Sycsvpro::Calculator","Sycsvpro/Calculator.html#method-i-execute","()","<p>Executes the calculator\n"],["execute","Sycsvpro::Collector","Sycsvpro/Collector.html#method-i-execute","()","<p>Execute the collector\n"],["execute","Sycsvpro::Counter","Sycsvpro/Counter.html#method-i-execute","()","<p>Executes the counter\n"],["execute","Sycsvpro::Extractor","Sycsvpro/Extractor.html#method-i-execute","()","<p>Executes the extractor\n"],["execute","Sycsvpro::Inserter","Sycsvpro/Inserter.html#method-i-execute","()","<p>Inserts the content of the insert-file at the specified positions (top or\nbottom)\n"],["execute","Sycsvpro::Mapper","Sycsvpro/Mapper.html#method-i-execute","()","<p>Executes the mapper\n"],["execute","Sycsvpro::Profiler","Sycsvpro/Profiler.html#method-i-execute","(method)","<p>Executes the provided method in the Ruby script\n"],["execute","Sycsvpro::ScriptList","Sycsvpro/ScriptList.html#method-i-execute","()","<p>Retrieves the information about scripts and methods from the script\ndirectory\n"],["execute","Sycsvpro::Sorter","Sycsvpro/Sorter.html#method-i-execute","()","<p>Sorts the data of the infile\n"],["has_filter?","Sycsvpro::Filter","Sycsvpro/Filter.html#method-i-has_filter-3F","()","<p>Checks whether a filter has been set. Returns true if filter has been set\notherwise false\n"],["method_missing","Sycsvpro::Calculator","Sycsvpro/Calculator.html#method-i-method_missing","(id, *args, &block)","<p>Retrieves the values from a row as the result of a arithmetic operation\n"],["method_missing","Sycsvpro::Filter","Sycsvpro/Filter.html#method-i-method_missing","(id, *args, &block)","<p>Creates the filters based on the given patterns\n"],["new","Sycsvpro::Aggregator","Sycsvpro/Aggregator.html#method-c-new","(options={})","<p>Creates a new aggregator. Takes as attributes infile, outfile, key, rows,\ncols, date-format and indicator …\n"],["new","Sycsvpro::Allocator","Sycsvpro/Allocator.html#method-c-new","(options={})","<p>Creates a new allocator. Options are infile, outfile, key, rows and columns\nto allocate to key\n"],["new","Sycsvpro::Analyzer","Sycsvpro/Analyzer.html#method-c-new","(file)","<p>Creates a new analyzer\n"],["new","Sycsvpro::Calculator","Sycsvpro/Calculator.html#method-c-new","(options={})","<p>Creates a new Calculator. Options expects :infile, :outfile, :rows and\n:columns. Optionally a header …\n"],["new","Sycsvpro::Collector","Sycsvpro/Collector.html#method-c-new","(options={})","<p>Creates a new Collector\n"],["new","Sycsvpro::Counter","Sycsvpro/Counter.html#method-c-new","(options={})","<p>Creates a new counter. Takes as attributes infile, outfile, key, rows,\ncols, date-format and indicator …\n"],["new","Sycsvpro::Extractor","Sycsvpro/Extractor.html#method-c-new","(options={})","<p>Creates a new extractor\n"],["new","Sycsvpro::Filter","Sycsvpro/Filter.html#method-c-new","(values, options={})","<p>Creates a new filter\n"],["new","Sycsvpro::Header","Sycsvpro/Header.html#method-c-new","(header)","<p>Create a new header\n"],["new","Sycsvpro::Inserter","Sycsvpro/Inserter.html#method-c-new","(options={})","<p>Creates an Inserter and takes options infile, outfile, insert-file and\nposition where to insert the insert-file …\n"],["new","Sycsvpro::Mapper","Sycsvpro/Mapper.html#method-c-new","(options={})","<p>Creates new mapper\n"],["new","Sycsvpro::Profiler","Sycsvpro/Profiler.html#method-c-new","(pro_file)","<p>Creates a new profiler\n"],["new","Sycsvpro::ScriptCreator","Sycsvpro/ScriptCreator.html#method-c-new","(options={})","<p>Creates a new ScriptCreator\n"],["new","Sycsvpro::ScriptList","Sycsvpro/ScriptList.html#method-c-new","(options={})","<p>Creates a new ScriptList. Takes params script_dir, script_file and\nshow_methods\n"],["new","Sycsvpro::Sorter","Sycsvpro/Sorter.html#method-c-new","(options={})","<p>Creates a Sorter and takes as options infile, outfile, rows, cols including\ntypes and a date format for …\n"],["pivot_each_column","Sycsvpro::Filter","Sycsvpro/Filter.html#method-i-pivot_each_column","(values=[])","<p>Yields the column value and whether the filter matches the column\n"],["process","Sycsvpro::ColumnFilter","Sycsvpro/ColumnFilter.html#method-i-process","(object, options={})","<p>Processes the filter and returns the values that respect the filter\n"],["process","Sycsvpro::ColumnTypeFilter","Sycsvpro/ColumnTypeFilter.html#method-i-process","(object, options={})","<p>Processes the filter and returns the filtered columns\n"],["process","Sycsvpro::Filter","Sycsvpro/Filter.html#method-i-process","(object, options={})","<p>Processes the filter. Needs to be overridden by the sub-class\n"],["process","Sycsvpro::Header","Sycsvpro/Header.html#method-i-process","(line)","<p>Returns the header\n"],["process","Sycsvpro::RowFilter","Sycsvpro/RowFilter.html#method-i-process","(object, options={})","<p>Processes the filter on the given row\n"],["process_aggregation","Sycsvpro::Aggregator","Sycsvpro/Aggregator.html#method-i-process_aggregation","()","<p>Process the aggregation of the key values\n"],["process_count","Sycsvpro::Counter","Sycsvpro/Counter.html#method-i-process_count","()","<p>Processes the counting on the in file\n"],["result","Sycsvpro::Analyzer","Sycsvpro/Analyzer.html#method-i-result","()","<p>Analyzes the file and returns the result\n"],["rows","Dsl","Dsl.html#method-i-rows","(options={})","<p>Retrieves rows and columns from the file and returns them to the block\nprovided by the caller\n"],["set_max_row","Object","Object.html#method-i-set_max_row","(options, max_row)","<p>the -r flag can take a EOF value which is replaced by the actual row value\nof the input file\n"],["str2utf8","Dsl","Dsl.html#method-i-str2utf8","(str)","<p>Remove non-UTF chars from string\n"],["unstring","Dsl","Dsl.html#method-i-unstring","(line)","<p>Remove leading and trailing “ and spaces as well as reducing more than 2\nspaces between words from …\n"],["write_result","Sycsvpro::Aggregator","Sycsvpro/Aggregator.html#method-i-write_result","()","<p>Writes the aggration results\n"],["write_result","Sycsvpro::Counter","Sycsvpro/Counter.html#method-i-write_result","()","<p>Writes the count results\n"],["write_to","Dsl","Dsl.html#method-i-write_to","(file)","<p>writes values provided by a block to the given file\n"],["README","","README_rdoc.html","","<p>sycsvpro\n<p>Author — Pierre Sugar (pierre@sugaryourcoffee.de)\n<p>Copyright — Copyright © 2014 by Pierre Sugar\n"]]}}
|
data/html/js/searcher.js
DELETED
|
@@ -1,228 +0,0 @@
|
|
|
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
|
-
|