## DhKeywordModel DhKeywordModel — A custom GtkTreeModel implementation for searching DhLink's |

## Functions

DhKeywordModel * | dh_keyword_model_new ()
DhLink * | dh_keyword_model_filter ()

## Types and Values

struct | DhKeywordModel

## Object Hierarchy

        GObject
        ╰── DhKeywordModel

## Implemented Interfaces

DhKeywordModel implements GtkTreeModel.

## Includes

    #include <devhelp/devhelp.h>

## Description

DhKeywordModel is a custom GtkTreeModel implementation (as a list, not a tree) for searching DhLink's.

The `dh_keyword_model_filter()` function is used to set the search criteria. It fills the GtkTreeModel with the list of DhLink's that match the search criteria (up to a certain maximum number of matches).

How the search works (for end users) is explained in the user documentation of the Devhelp application.

### Filter by book and page

As a kind of API for integrating Devhelp with other applications, the search string supports additional features. Those features are not intended to be used directly by end users when typing the search string in the GUI, because it's not really convenient. It is intended to be used with the `devhelp --search "search-string"` command line, so that another application can launch Devhelp and set a specific search string.

It is possible to filter by book by prefixing the search string with “book:the-book-ID”. For example “book:gtk3”. If there are no other search terms, it shows the top-level page of that book. If there are other search terms, it limits the search to the specified book. See also the `dh_book_get_id()` function (in the `*.devhelp2` index file format it's called the book “name”, not ID, but ID is clearer).

Similarly, it is possible to filter by page, by prefixing the search string with “page:the-page-ID”. For example “page:GtkWindow”. If there are no other search terms, the top of the page is shown and the search matches all the symbols part of that page. If there are other search terms, it limits the search to the specified page. To know what is the “page ID”, see the `dh_link_belongs_to_page()` function.

“book:” and “page:” can be combined. Normal search terms must be after “book:” and “page:”.

The book and page IDs – even if they contain an uppercase letter – don't affect the case sensitivity for the other search terms.

## Functions

### dh_keyword_model_new ()

    DhKeywordModel *
    dh_keyword_model_new (void);

#### Returns

a new DhKeywordModel object.

### dh_keyword_model_filter ()

    DhLink *
    dh_keyword_model_filter (DhKeywordModel *model,
                             const gchar *search_string,
                             const gchar *current_book_id,
                             DhProfile *profile);

Searches in the DhBookList of `profile` the list of DhLink's that correspond to `search_string` , and fills the `model` with that list (erasing the previous content).

Attention, when calling this function the `model` needs to be disconnected from the GtkTreeView, because the GtkTreeModel signals are not emitted, to improve the performances (sending a lot of signals is slow) and have a simpler implementation. The previous row selection is anyway no longer relevant.

Note that there is a maximum number of matches (configured internally). When the maximum is reached the search is stopped, to avoid blocking the GUI (since this function runs synchronously) if the `search_string` contains for example only one character. (And it is anyway not very useful to show to the user tens of thousands search results).

#### Parameters

model | a DhKeywordModel. |
search_string | a search query. |
current_book_id | the ID of the book currently shown, or `NULL`. | [nullable]
profile | a DhProfile, or `NULL` for the default profile. | [nullable]

#### Returns

the DhLink that matches exactly `search_string` , or `NULL` if no such DhLink was found within the maximum number of matches.

[nullable][transfer none]

## Types and Values

### struct DhKeywordModel

    struct DhKeywordModel;