Project Lucy has retired. For details please refer to its Attic page.
Lucy::Highlight::Highlighter – C API Documentation
Apache Lucy™

Lucy::Highlight::Highlighter

parcel Lucy
class variable LUCY_HIGHLIGHTER
struct symbol lucy_Highlighter
class nickname lucy_Highlighter
header file Lucy/Highlight/Highlighter.h

Name

Lucy::Highlight::Highlighter – Create and highlight excerpts.

Description

The Highlighter can be used to select relevant snippets from a document, and to surround search terms with highlighting tags. It handles both stems and phrases correctly and efficiently, using special-purpose data generated at index-time.

Functions

new
lucy_Highlighter* // incremented
lucy_Highlighter_new(
    lucy_Searcher *searcher,
    cfish_Obj *query,
    cfish_String *field,
    uint32_t excerpt_length
);

Create a new Highlighter.

searcher

An object which inherits from Searcher, such as an IndexSearcher.

query

Query object or a query string.

field

The name of the field from which to draw the excerpt. The field must marked as be highlightable (see FieldType).

excerpt_length

Maximum length of the excerpt, in characters.

init
lucy_Highlighter*
lucy_Highlighter_init(
    lucy_Highlighter *self,
    lucy_Searcher *searcher,
    cfish_Obj *query,
    cfish_String *field,
    uint32_t excerpt_length
);

Initialize a Highlighter.

searcher

An object which inherits from Searcher, such as an IndexSearcher.

query

Query object or a query string.

field

The name of the field from which to draw the excerpt. The field must marked as be highlightable (see FieldType).

excerpt_length

Maximum length of the excerpt, in characters.

Methods

Create_Excerpt
cfish_String* // incremented
lucy_Highlighter_Create_Excerpt(
    lucy_Highlighter *self,
    lucy_HitDoc *hit_doc
);

Take a HitDoc object and return a highlighted excerpt as a string if the HitDoc has a value for the specified field.

Encode
cfish_String* // incremented
lucy_Highlighter_Encode(
    lucy_Highlighter *self,
    cfish_String *text
);

Encode text with HTML entities. This method is called internally by Create_Excerpt() for each text fragment when assembling an excerpt. A subclass can override this if the text should be encoded differently or not at all.

Highlight
cfish_String* // incremented
lucy_Highlighter_Highlight(
    lucy_Highlighter *self,
    cfish_String *text
);

Highlight a small section of text. By default, prepends pre-tag and appends post-tag. This method is called internally by Create_Excerpt() when assembling an excerpt.

Set_Pre_Tag
void
lucy_Highlighter_Set_Pre_Tag(
    lucy_Highlighter *self,
    cfish_String *pre_tag
);

Setter. The default value is “<strong>”.

Set_Post_Tag
void
lucy_Highlighter_Set_Post_Tag(
    lucy_Highlighter *self,
    cfish_String *post_tag
);

Setter. The default value is “</strong>”.

Get_Pre_Tag
cfish_String*
lucy_Highlighter_Get_Pre_Tag(
    lucy_Highlighter *self
);

Accessor.

Get_Post_Tag
cfish_String*
lucy_Highlighter_Get_Post_Tag(
    lucy_Highlighter *self
);

Accessor.

Get_Field
cfish_String*
lucy_Highlighter_Get_Field(
    lucy_Highlighter *self
);

Accessor.

Get_Excerpt_Length
uint32_t
lucy_Highlighter_Get_Excerpt_Length(
    lucy_Highlighter *self
);

Accessor.

Get_Searcher
lucy_Searcher*
lucy_Highlighter_Get_Searcher(
    lucy_Highlighter *self
);

Accessor.

Get_Query
lucy_Query*
lucy_Highlighter_Get_Query(
    lucy_Highlighter *self
);

Accessor.

Get_Compiler
lucy_Compiler*
lucy_Highlighter_Get_Compiler(
    lucy_Highlighter *self
);

Accessor for the Lucy::Search::Compiler object derived from query and searcher.

Inheritance

Lucy::Highlight::Highlighter is a Clownfish::Obj.