DzlFuzzyMutableIndex Matching: Dazzle Reference Manual

## DzlFuzzyMutableIndex Matching DzlFuzzyMutableIndex Matching — DzlFuzzyMutableIndex matching for GLib based programs. |

## Functions

DzlFuzzyMutableIndex * | dzl_fuzzy_mutable_index_new ()
DzlFuzzyMutableIndex * | dzl_fuzzy_mutable_index_new_with_free_func ()
void | dzl_fuzzy_mutable_index_set_free_func ()
void | dzl_fuzzy_mutable_index_begin_bulk_insert ()
void | dzl_fuzzy_mutable_index_end_bulk_insert ()
gboolean | dzl_fuzzy_mutable_index_contains ()
void | dzl_fuzzy_mutable_index_insert ()
GArray * | dzl_fuzzy_mutable_index_match ()
void | dzl_fuzzy_mutable_index_remove ()
DzlFuzzyMutableIndex * | dzl_fuzzy_mutable_index_ref ()
void | dzl_fuzzy_mutable_index_unref ()
gchar * | dzl_fuzzy_highlight ()

## Object Hierarchy

        GBoxed
        ╰── DzlFuzzyMutableIndex

## Description

DzlFuzzyMutableIndex provides a fulltext index that focuses around fuzzy matching words. This version of the datastructure is focused around in-memory storage. This makes mutability performance of adding or removing items from the corpus simpler.

If you need mostly read-only indexes, you might consider using DzlFuzzyIndex and DzlFuzzyIndexBuilder which can create a disk-based file and `mmap()` a read-only version of the data set.

It is a programming error to modify Fuzzy while holding onto an array of FuzzyMatch elements. The position of strings within the DzlFuzzyMutableIndexMatch may no longer be valid.

## Functions

### dzl_fuzzy_mutable_index_new ()

    DzlFuzzyMutableIndex *
    dzl_fuzzy_mutable_index_new (gboolean case_sensitive);

Create a new Fuzzy for fuzzy matching strings.

#### Parameters

case_sensitive | `TRUE` if case should be preserved. |

#### Returns

A newly allocated Fuzzy that should be freed with `dzl_fuzzy_mutable_index_unref()`.

### dzl_fuzzy_mutable_index_new_with_free_func ()

    DzlFuzzyMutableIndex *
    dzl_fuzzy_mutable_index_new_with_free_func
                                   (gboolean case_sensitive,
                                    GDestroyNotify free_func);

### dzl_fuzzy_mutable_index_set_free_func ()

    void
    dzl_fuzzy_mutable_index_set_free_func (DzlFuzzyMutableIndex *fuzzy,
                                           GDestroyNotify free_func);

### dzl_fuzzy_mutable_index_begin_bulk_insert ()

    void
    dzl_fuzzy_mutable_index_begin_bulk_insert
                                   (DzlFuzzyMutableIndex *fuzzy);

Start a bulk insertion. `fuzzy` is not ready for searching until `dzl_fuzzy_mutable_index_end_bulk_insert()` has been called.

This allows for inserting large numbers of strings and deferring the final sort until `dzl_fuzzy_mutable_index_end_bulk_insert()`.

#### Parameters

fuzzy | A Fuzzy. | [in]

### dzl_fuzzy_mutable_index_end_bulk_insert ()

    void
    dzl_fuzzy_mutable_index_end_bulk_insert
                                   (DzlFuzzyMutableIndex *fuzzy);

Complete a bulk insert and resort the index.

#### Parameters

fuzzy | A Fuzzy. | [in]

### dzl_fuzzy_mutable_index_contains ()

    gboolean
    dzl_fuzzy_mutable_index_contains (DzlFuzzyMutableIndex *fuzzy,
                                      const gchar *key);

### dzl_fuzzy_mutable_index_insert ()

    void
    dzl_fuzzy_mutable_index_insert (DzlFuzzyMutableIndex *fuzzy,
                                    const gchar *key,
                                    gpointer value);

Inserts a string into the fuzzy matcher.

#### Parameters

fuzzy | A Fuzzy. | [in]
key | A UTF-8 encoded string. | [in]
value | A value to associate with key. | [in]

### dzl_fuzzy_mutable_index_match ()

    GArray *
    dzl_fuzzy_mutable_index_match (DzlFuzzyMutableIndex *fuzzy,
                                   const gchar *needle,
                                   gsize max_matches);

DzlFuzzyMutableIndex searches within `fuzzy` for strings that fuzzy match `needle` . Only up to `max_matches` will be returned.

TODO: max_matches is not yet respected.

#### Parameters

fuzzy | A Fuzzy. | [in]
needle | The needle to fuzzy search for. | [in]
max_matches | The max number of matches to return. | [in]

#### Returns

A newly allocated GArray containing FuzzyMatch elements. This should be freed when the caller is done with it using `g_array_unref()`. It is a programming error to keep the structure around longer than the `fuzzy` instance.

[transfer full][element-type DzlFuzzyMutableIndexMatch]

### dzl_fuzzy_mutable_index_remove ()

    void
    dzl_fuzzy_mutable_index_remove (DzlFuzzyMutableIndex *fuzzy,
                                    const gchar *key);

### dzl_fuzzy_mutable_index_ref ()

    DzlFuzzyMutableIndex *
    dzl_fuzzy_mutable_index_ref (DzlFuzzyMutableIndex *fuzzy);

### dzl_fuzzy_mutable_index_unref ()

    void
    dzl_fuzzy_mutable_index_unref (DzlFuzzyMutableIndex *fuzzy);

Decrements the reference count of fuzzy by one. When the reference count reaches zero, the structure will be freed.

#### Parameters

fuzzy | A Fuzzy. |

### dzl_fuzzy_highlight ()

    gchar *
    dzl_fuzzy_highlight (const gchar *str,
                         const gchar *query,
                         gboolean case_sensitive);