Class: Whistlepig::Entry
- Inherits:
-
Object
- Object
- Whistlepig::Entry
- Defined in:
- lib/whistlepig.rb,
ext/whistlepig/whistlepig.c
Overview
Represents document, before being added to the index.
Entries allow you to build up a document in memory before indexing it. Once you’ve built it, pass it to Index#add_entry.
Class Method Summary collapse
-
.new ⇒ Object
Creates a new, empty entry.
Instance Method Summary collapse
-
#add_string(field, string) ⇒ Object
Adds a String
string
with field +field</field> to an entry. -
#add_token(field, token) ⇒ Object
Adds a single token
token
with field +field</field> to an entry. -
#size ⇒ Object
Returns the number of tokens in the entry.
Class Method Details
.new ⇒ Object
Creates a new, empty entry.
213 214 215 216 217 218 219 220 |
# File 'ext/whistlepig/whistlepig.c', line 213 static VALUE entry_new(VALUE class) { wp_entry* entry = wp_entry_new(); //printf("# entry create at %p\n", entry); VALUE o_entry = Data_Wrap_Struct(class, NULL, entry_free, entry); rb_obj_call_init(o_entry, 0, NULL); return o_entry; } |
Instance Method Details
#add_string(field, string) ⇒ Object
Adds a String string
with field field</field> to an entry. The string will be tokenized on whitespace. Both token
and string</field> must be strings.
Returns itself.
250 251 252 253 254 255 256 257 258 259 |
# File 'ext/whistlepig/whistlepig.c', line 250 static VALUE entry_add_string(VALUE self, VALUE field, VALUE string) { Check_Type(field, T_STRING); Check_Type(string, T_STRING); wp_entry* entry; Data_Get_Struct(self, wp_entry, entry); wp_error* e = wp_entry_add_string(entry, RSTRING_PTR(field), RSTRING_PTR(string)); RAISE_IF_NECESSARY(e); return self; } |
#add_token(field, token) ⇒ Object
Adds a single token token
with field field</field> to an entry. Both token
and field</field> must be strings.
Returns itself.
230 231 232 233 234 235 236 237 238 239 |
# File 'ext/whistlepig/whistlepig.c', line 230 static VALUE entry_add_token(VALUE self, VALUE field, VALUE term) { Check_Type(field, T_STRING); Check_Type(term, T_STRING); wp_entry* entry; Data_Get_Struct(self, wp_entry, entry); wp_error* e = wp_entry_add_token(entry, RSTRING_PTR(field), RSTRING_PTR(term)); RAISE_IF_NECESSARY(e); return self; } |
#size ⇒ Object
Returns the number of tokens in the entry.
264 265 266 267 |
# File 'ext/whistlepig/whistlepig.c', line 264 static VALUE entry_size(VALUE self) { wp_entry* entry; Data_Get_Struct(self, wp_entry, entry); return INT2NUM(wp_entry_size(entry)); } |