whistlepig 0.10 → 0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/README +1 -1
- data/ext/whistlepig/entry.c +18 -38
- data/ext/whistlepig/entry.h +3 -7
- data/ext/whistlepig/extconf.h +3 -0
- data/ext/whistlepig/lock.h +2 -2
- data/ext/whistlepig/rarray.h +41 -0
- data/ext/whistlepig/snippeter.c +127 -0
- data/ext/whistlepig/snippeter.h +10 -0
- data/ext/whistlepig/tokenizer.lex.c +576 -577
- data/ext/whistlepig/whistlepig.c +39 -0
- data/ext/whistlepig/whistlepig.h +2 -0
- metadata +34 -28
data/ext/whistlepig/whistlepig.c
CHANGED
@@ -447,6 +447,44 @@ static VALUE query_or(VALUE self, VALUE v_other) {
|
|
447
447
|
return o_result;
|
448
448
|
}
|
449
449
|
|
450
|
+
/*
|
451
|
+
* call-seq: snippetize(field, string, max_num_results=10)
|
452
|
+
*
|
453
|
+
* Returns an array of [start, end] subarrays that mark the matching positions of
|
454
|
+
* the query within the string. 'field' determines which field the string is
|
455
|
+
* taken to be.
|
456
|
+
*
|
457
|
+
*/
|
458
|
+
static VALUE query_snippetize(int argc, VALUE* argv, VALUE self) {
|
459
|
+
VALUE v_field, v_string, v_max_num_results;
|
460
|
+
rb_scan_args(argc, argv, "21", &v_field, &v_string, &v_max_num_results);
|
461
|
+
Check_Type(v_string, T_STRING);
|
462
|
+
|
463
|
+
wp_query* query; Data_Get_Struct(self, wp_query, query);
|
464
|
+
uint32_t num_results, max_num_results;
|
465
|
+
if(NIL_P(v_max_num_results)) max_num_results = 10;
|
466
|
+
else max_num_results = NUM2INT(v_max_num_results);
|
467
|
+
|
468
|
+
uint32_t* start_offsets = malloc(sizeof(uint32_t) * max_num_results);
|
469
|
+
uint32_t* end_offsets = malloc(sizeof(uint32_t) * max_num_results);
|
470
|
+
|
471
|
+
wp_error* e = wp_snippetize_string(query, RSTRING_PTR(v_field), RSTRING_PTR(v_string), max_num_results, &num_results, start_offsets, end_offsets);
|
472
|
+
RAISE_IF_NECESSARY(e);
|
473
|
+
|
474
|
+
VALUE array = rb_ary_new2(num_results);
|
475
|
+
for(uint32_t i = 0; i < num_results; i++) {
|
476
|
+
VALUE subarray = rb_ary_new2(2);
|
477
|
+
rb_ary_store(subarray, 0, INT2NUM(start_offsets[i]));
|
478
|
+
rb_ary_store(subarray, 1, INT2NUM(end_offsets[i]));
|
479
|
+
rb_ary_store(array, i, subarray);
|
480
|
+
}
|
481
|
+
|
482
|
+
free(start_offsets);
|
483
|
+
free(end_offsets);
|
484
|
+
|
485
|
+
return array;
|
486
|
+
}
|
487
|
+
|
450
488
|
static VALUE query_init(VALUE self, VALUE query) {
|
451
489
|
rb_iv_set(self, "@query", query);
|
452
490
|
return self;
|
@@ -568,6 +606,7 @@ void Init_whistlepig() {
|
|
568
606
|
rb_define_method(c_query, "to_s", query_to_s, 0);
|
569
607
|
rb_define_method(c_query, "clone", query_clone, 0);
|
570
608
|
rb_define_method(c_query, "term_map", query_map_terms, 0);
|
609
|
+
rb_define_method(c_query, "snippetize", query_snippetize, -1);
|
571
610
|
rb_define_attr(c_query, "query", 1, 0);
|
572
611
|
|
573
612
|
c_error = rb_define_class_under(m_whistlepig, "Error", rb_eStandardError);
|
data/ext/whistlepig/whistlepig.h
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whistlepig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.11'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,8 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
12
|
+
date: 2012-04-10 00:00:00.000000000 -07:00
|
13
|
+
default_executable:
|
13
14
|
dependencies: []
|
14
15
|
description: Whistlepig is a minimalist realtime full-text search index. Its goal
|
15
16
|
is to be as small and minimally-featured as possible, while still remaining useful,
|
@@ -27,40 +28,45 @@ files:
|
|
27
28
|
- COPYING
|
28
29
|
- ext/whistlepig/extconf.rb
|
29
30
|
- lib/whistlepig.rb
|
31
|
+
- ext/whistlepig/query-parser.lex.h
|
32
|
+
- ext/whistlepig/entry.h
|
33
|
+
- ext/whistlepig/lock.c
|
34
|
+
- ext/whistlepig/stringmap.c
|
35
|
+
- ext/whistlepig/tokenizer.lex.h
|
36
|
+
- ext/whistlepig/whistlepig.h
|
30
37
|
- ext/whistlepig/error.c
|
38
|
+
- ext/whistlepig/snippeter.h
|
31
39
|
- ext/whistlepig/lock.h
|
32
|
-
- ext/whistlepig/
|
33
|
-
- ext/whistlepig/query-parser.tab.c
|
34
|
-
- ext/whistlepig/defaults.h
|
40
|
+
- ext/whistlepig/extconf.h
|
35
41
|
- ext/whistlepig/stringmap.h
|
36
|
-
- ext/whistlepig/query.c
|
37
|
-
- ext/whistlepig/stringmap.c
|
38
|
-
- ext/whistlepig/query.h
|
39
|
-
- ext/whistlepig/segment.h
|
40
|
-
- ext/whistlepig/entry.c
|
41
|
-
- ext/whistlepig/search.c
|
42
|
-
- ext/whistlepig/mmap-obj.c
|
43
|
-
- ext/whistlepig/query-parser.tab.h
|
44
42
|
- ext/whistlepig/query-parser.lex.c
|
45
|
-
- ext/whistlepig/
|
43
|
+
- ext/whistlepig/defaults.h
|
44
|
+
- ext/whistlepig/tokenizer.lex.c
|
45
|
+
- ext/whistlepig/termhash.c
|
46
|
+
- ext/whistlepig/query-parser.h
|
47
|
+
- ext/whistlepig/index.c
|
46
48
|
- ext/whistlepig/stringpool.c
|
49
|
+
- ext/whistlepig/query.h
|
50
|
+
- ext/whistlepig/query-parser.c
|
47
51
|
- ext/whistlepig/stringpool.h
|
48
|
-
- ext/whistlepig/
|
52
|
+
- ext/whistlepig/mmap-obj.c
|
53
|
+
- ext/whistlepig/whistlepig.c
|
54
|
+
- ext/whistlepig/search.c
|
55
|
+
- ext/whistlepig/snippeter.c
|
56
|
+
- ext/whistlepig/termhash.h
|
57
|
+
- ext/whistlepig/query.c
|
58
|
+
- ext/whistlepig/query-parser.tab.h
|
49
59
|
- ext/whistlepig/khash.h
|
50
|
-
- ext/whistlepig/
|
51
|
-
- ext/whistlepig/
|
52
|
-
- ext/whistlepig/query-parser.lex.h
|
53
|
-
- ext/whistlepig/mmap-obj.h
|
54
|
-
- ext/whistlepig/tokenizer.lex.h
|
60
|
+
- ext/whistlepig/query-parser.tab.c
|
61
|
+
- ext/whistlepig/entry.c
|
55
62
|
- ext/whistlepig/index.h
|
56
|
-
- ext/whistlepig/
|
57
|
-
- ext/whistlepig/
|
58
|
-
- ext/whistlepig/
|
59
|
-
- ext/whistlepig/whistlepig.c
|
60
|
-
- ext/whistlepig/termhash.c
|
63
|
+
- ext/whistlepig/segment.h
|
64
|
+
- ext/whistlepig/mmap-obj.h
|
65
|
+
- ext/whistlepig/rarray.h
|
61
66
|
- ext/whistlepig/segment.c
|
62
|
-
- ext/whistlepig/
|
63
|
-
- ext/whistlepig/
|
67
|
+
- ext/whistlepig/search.h
|
68
|
+
- ext/whistlepig/error.h
|
69
|
+
has_rdoc: true
|
64
70
|
homepage: http://masanjin.net/whistlepig
|
65
71
|
licenses: []
|
66
72
|
post_install_message:
|
@@ -87,7 +93,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
93
|
version: '0'
|
88
94
|
requirements: []
|
89
95
|
rubyforge_project:
|
90
|
-
rubygems_version: 1.
|
96
|
+
rubygems_version: 1.6.0
|
91
97
|
signing_key:
|
92
98
|
specification_version: 3
|
93
99
|
summary: a minimalist realtime full-text search index
|