Sha256: dd7a202dcd1a1ab6b3ea7561e634dab3e9262d96d03608724d19c29846277097

Contents?: true

Size: 1.24 KB

Versions: 12

Compression:

Stored size: 1.24 KB

Contents

require([
    'gitbook',
    'jquery'
], function(gitbook, $) {
    // Global search objects
    var engine      = null;
    var initialized = false;

    // Set a new search engine
    function setEngine(Engine, config) {
        initialized = false;
        engine      = new Engine(config);

        init(config);
    }

    // Initialize search engine with config
    function init(config) {
        if (!engine) throw new Error('No engine set for research. Set an engine using gitbook.research.setEngine(Engine).');

        return engine.init(config)
        .then(function() {
            initialized = true;
            gitbook.events.trigger('search.ready');
        });
    }

    // Launch search for query q
    function query(q, offset, length) {
        if (!initialized) throw new Error('Search has not been initialized');
        return engine.search(q, offset, length);
    }

    // Get stats about search
    function getEngine() {
        return engine? engine.name : null;
    }

    function isInitialized() {
        return initialized;
    }

    // Initialize gitbook.search
    gitbook.search = {
        setEngine:     setEngine,
        getEngine:     getEngine,
        query:         query,
        isInitialized: isInitialized
    };
});

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
ovto-0.6.2 docs/gitbook/gitbook-plugin-search/search-engine.js
ovto-0.6.1 docs/gitbook/gitbook-plugin-search/search-engine.js
ovto-0.6.0 docs/gitbook/gitbook-plugin-search/search-engine.js
ovto-0.6.0.rc1 docs/gitbook/gitbook-plugin-search/search-engine.js
ovto-0.5.0 docs/gitbook/gitbook-plugin-search/search-engine.js
ovto-0.4.1 docs/gitbook/gitbook-plugin-search/search-engine.js
ovto-0.4.0 docs/gitbook/gitbook-plugin-search/search-engine.js
ovto-0.3.0 docs/gitbook/gitbook-plugin-search/search-engine.js
ovto-0.2.3 docs/gitbook/gitbook-plugin-search/search-engine.js
ovto-0.2.2 docs/gitbook/gitbook-plugin-search/search-engine.js
ovto-0.2.1 docs/gitbook/gitbook-plugin-search/search-engine.js
ovto-0.2.0 docs/gitbook/gitbook-plugin-search/search-engine.js