简体   繁体   中英

Is Twitter Typeahead.js library limited to 6 datasets?

I am using Typeahed.js library from Twitter to search multiple datasets in my database from a single input box.

I am currently using 6 data-sets (see the code below) and I want to add 1 more. I found it not working for the 7th datasets ( products dataset from below code). When typing search query into input box it would only sent GET AJAX requests for first six datasets and would ignore the 7th one?

GET http://127.0.0.1/app/typeahead_orders.json?q=MSI-20mA
GET http://127.0.0.1/app/typeahead_invoices.json?q=MSI-20mA
GET http://127.0.0.1/app/typeahead_services.json?q=MSI-20mA%
GET http://127.0.0.1/app/typeahead_serials.json?q=MSI-20mA%
GET http://127.0.0.1/app/typeahead_users.json?q=MSI-20mA%
GET http://127.0.0.1/app/typeahead_licenses.json?q=MSI-20mA%

The library docs are pour and I haven't seen it mention any kind of limit on number of datasets you can use...

$('#search-query').typeahead([
    {
        name: 'orders',
        remote: base_url+"utilities/ajaxprocess/typeahead_orders.json?q=%QUERY",
        template: '<a href="'+base_url+'orders/view/{{order_id}}">{{value}} - Reference no.: {{reference_number}}</a>',
        header: '<h5 class="search-result-header"><i class="icon-shopping-cart"></i> Orders</h5>',
        engine: Hogan,
        limit: 6
    },
    {
        name: 'invoices',
        remote: base_url+"utilities/ajaxprocess/typeahead_invoices.json?q=%QUERY",
        template: '<a href="'+base_url+'invoices/view/{{invoice_id}}">{{invoice_number}} - {{company}}</a>',
        header: '<h5 class="search-result-header"><i class="icon-file"></i> Invoices</h5>',
        engine: Hogan,
        limit: 6
    },
    {
        name: 'services',
        remote: base_url+"utilities/ajaxprocess/typeahead_services.json?q=%QUERY%",
        template: '<a href="'+base_url+'services/view/{{rma_id}}">{{value}} - {{firstname}} {{lastname}}</a>',
        header: '<h5 class="search-result-header"><i class="icon-wrench"></i> RMA services</h5>',
        engine: Hogan,
        limit: 6
    },
    {
        name: 'serials',
        remote: base_url+"utilities/ajaxprocess/typeahead_serials.json?q=%QUERY%",
        template: '<a href="'+base_url+'serials/view/{{serial_id}}">{{value}} - {{product}} {{module_name}}</a>',
        header: '<h5 class="search-result-header"><i class="icon-barcode"></i> Serials</h5>',
        engine: Hogan,
        limit: 6
    },
    {
        name: 'users',
        remote: base_url+"utilities/ajaxprocess/typeahead_users.json?q=%QUERY%",
        template: '<a href="'+base_url+'users?f=1&filter_id={{user_id}}">{{firstname}} {{lastname}} - {{email}}</a>',
        header: '<h5 class="search-result-header"><i class="icon-user"></i> Users</h5>',
        engine: Hogan,
        limit: 6
    },
    {
        name: 'licenses',
        remote: base_url+"utilities/ajaxprocess/typeahead_licenses.json?q=%QUERY%",
        template: '<a href="'+base_url+'licenses?f=1&filter_id={{license_id}}">{{key}} - {{version}}</a>',
        header: '<h5 class="search-result-header"><i class="icon-lock"></i> Licenses</h5>',
        engine: Hogan,
        limit: 6
    },
    {
        name: 'products',
        remote: base_url+"utilities/ajaxprocess/typeahead_products.json?q=%QUERY%",
        template: '<a href="'+base_url+'products?f=1&filter_id={{product_id}}">{{code}} - {{name}}</a>',
        header: '<h5 class="search-result-header"><i class="icon-briefcase"></i> Products</h5>',
        engine: Hogan,
        limit: 6
    }
]).on('typeahead:selected', function($e, data) {
    window.location = data.url;
});

Ok I figured it out. It is not limited, but default max parallel request is 6. From the typeahead.js docs:

maxParallelRequests – The max number of parallel requests typeahead.js can have pending. Defaults to 6.

So I have increased this and it works. Here is the final corrected code:

$('#search-query').typeahead([
    {
        name: 'orders',
        remote: {
            url: base_url+"utilities/ajaxprocess/typeahead_orders.json?q=%QUERY",
            maxParallelRequests: 8,
        },
        template: '<a href="'+base_url+'orders/view/{{order_id}}">{{value}} - Reference no.: {{reference_number}}</a>',
        header: '<h5 class="search-result-header"><i class="icon-shopping-cart"></i> Orders</h5>',
        engine: Hogan,
        limit: 6
    },
    {
        name: 'invoices',
        remote: {
            url: base_url+"utilities/ajaxprocess/typeahead_invoices.json?q=%QUERY",
            maxParallelRequests: 8,
        },
        template: '<a href="'+base_url+'invoices/view/{{invoice_id}}">{{invoice_number}} - {{company}}</a>',
        header: '<h5 class="search-result-header"><i class="icon-file"></i> Invoices</h5>',
        engine: Hogan,
        limit: 6
    },
    {
        name: 'services',
        remote: {
            url: base_url+"utilities/ajaxprocess/typeahead_services.json?q=%QUERY%",
            maxParallelRequests: 8,
        },
        template: '<a href="'+base_url+'services/view/{{rma_id}}">{{value}} - {{firstname}} {{lastname}}</a>',
        header: '<h5 class="search-result-header"><i class="icon-wrench"></i> RMA services</h5>',
        engine: Hogan,
        limit: 6
    },
    {
        name: 'serials',
        remote: {
            url: base_url+"utilities/ajaxprocess/typeahead_serials.json?q=%QUERY%",
            maxParallelRequests: 8,
        },
        template: '<a href="'+base_url+'serials/view/{{serial_id}}">{{value}} - {{product}} {{module_name}}</a>',
        header: '<h5 class="search-result-header"><i class="icon-barcode"></i> Serials</h5>',
        engine: Hogan,
        limit: 6
    },
    {
        name: 'users',
        remote: {
            url: base_url+"utilities/ajaxprocess/typeahead_users.json?q=%QUERY%",
            maxParallelRequests: 8,
        },
        template: '<a href="'+base_url+'users?f=1&filter_id={{user_id}}">{{firstname}} {{lastname}} - {{email}}</a>',
        header: '<h5 class="search-result-header"><i class="icon-user"></i> Users</h5>',
        engine: Hogan,
        limit: 6
    },
    {
        name: 'licenses',
        remote: {
            url: base_url+"utilities/ajaxprocess/typeahead_licenses.json?q=%QUERY%",
            maxParallelRequests: 8,
        },
        template: '<a href="'+base_url+'licenses?f=1&filter_id={{license_id}}">{{key}} - {{version}}</a>',
        header: '<h5 class="search-result-header"><i class="icon-lock"></i> Licenses</h5>',
        engine: Hogan,
        limit: 6
    },
    {
        name: 'products',
        remote: {
            url: base_url+"utilities/ajaxprocess/typeahead_products.json?q=%QUERY%",
            maxParallelRequests: 8,
        },
        template: '<a href="'+base_url+'products?f=1&filter_id={{product_id}}">{{code}} - {{name}}</a>',
        header: '<h5 class="search-result-header"><i class="icon-briefcase"></i> Products</h5>',
        engine: Hogan,
        limit: 6
    },
    {
        name: 'tasks',
        remote: {
            url: base_url+"utilities/ajaxprocess/typeahead_tasks.json?q=%QUERY%",
            maxParallelRequests: 8,
        },
        template: '<a href="'+base_url+'tasks?f=1&filter_id={{task_id}}">#{{task_id}} - {{description}}</a>',
        header: '<h5 class="search-result-header"><i class="icon-briefcase"></i> Tasks</h5>',
        engine: Hogan,
        limit: 6
    }
]).on('typeahead:selected', function($e, data) {
    window.location = data.url;
});

I haven't heard of such a limit, I wonder if there is a maximum amount of returned results that might be being satisfied by the first 6?

A quick test would be to essentially force a couple of your remote queries to always return nothing.

If your seventh search starts getting hit than that could explain it.

如果有人遇到这个老问题,并希望将maxPendingRequests设置增加到6以上(或使其更小),请参阅我最近提交给维护的typeahead分支的PR

Open Twitter typeahead.js file.

Search for : "maxPendingRequests = 6"

Instead of 6 Just put whatever value you want.

Now i can see more than 6 requests run parallel.

It works fine for me.

Don't go for 'maxParallelRequests' property it doesn't work at all...

I am sure its the final solution.....

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM