Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Typesense Bundle Laravel Package

acseo/typesense-bundle

Symfony bundle integrating Typesense search. Configure Typesense host/key, map Doctrine entities to Typesense collections/fields, and keep indexes synced via Doctrine event listeners. Includes transformers and services for querying collections.

View on GitHub
Deep Wiki
Context7

Cookbook : Autocomplete

With Typsense and some Javascript, it can be pretty easy to create an autocomplete field based on an ajax request.

In order to do that, TypesenseBundle prodive a generic autocomplete controller that will allow to use a finder in order to search for data, and return a JSON Response that could be used to populate the autocomplete field

Step 1 : declare a specific finder

First of all, we will need a finder in order to search for data. A specific finder can easily be declared.

# config/packages/acseo_typesense.yml
acseo_typesense:
    # ...
    # Collection settings
    collections:
        books:                                       # Typesense collection name
            # ...                                    # Colleciton fields definition
            # ...
            finders:                                 # Declare your specific finder
                books_autocomplete:                  # Finder name
                    finder_parameters:               # Parameters used by the finder
                        query_by: title              #
                        limit: 10                    # You can add as key / valuesspecifications
                        prefix: true                 # based on Typesense Request 
                        num_typos: 1                 #
                        drop_tokens_threshold: 1     #

Step 2 : enable the autocomplete route

# config/routes.yaml
autocomplete:
   path: /autocomplete
   controller: typesense.autocomplete_controller:autocomplete

Step 3 : Create an ajax request that will populate your search field.

The example bellow is based on bootstrap-autocomplete but you can use any script you want once you understand how this works

<!-- templates/base.html.twig -->
<html>
    <head>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
    </head>
    <body>
        <div class="container">
            {% block body %}{% endblock %}
        </div>
        <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>

        {% block javascripts %}{% endblock %}
    </body>
</html>
<!-- templates/book/search.html.twig -->
{% extends 'base.html.twig' %}

{% block body %}
    <input class="form-control bookAutocomplete" type="text" autocomplete="off">
{% endblock %}

{% block javascripts %}
<script src="https://cdn.jsdelivr.net/gh/xcash/[email protected]/dist/latest/bootstrap-autocomplete.min.js"></script>
<script type="text/javascript">

    $(document).ready(function(e) {
        $('.bookAutocomplete').autoComplete({
            minLength: 2,
            resolverSettings: {
                // Route to the autocomplete Controller, and name of the finder to use
                url: "{{path('autocomplete', {'finder_name' : 'books.books_autocomplete'})}}",
            },
            events: {
                searchPost: function (resultFromServer) {
                    // Manipulate returned data in order to display title in the search result
                    results = new Array();
                    resultFromServer.forEach(element => {
                        results.push(element.document.title);
                    });
                    return results;
                }
            }
        });
    });
</script>
{% endblock %}
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
mehedimi/laravel-amp-mail
happones/laravel-vue-i18n-generator
jwerd/inertia-table
siberfx/flysystem-wasabi
hollyit/token-replace
ippanelcom/laravel-sdk
adachsoft/changelog-linter
adachsoft/collection
payerurl/telegrambot-crypto-payment-instant-payout
dskripchenko/laravel-hybrid-search
riorizkyrainey/lara-ced
mehedimi/static-vel
zharp/zharp
nonsapiens/bigquery-model-sync
lgu-bayambang-ict-office/lgu-laravel-development-standards
andydefer/laravel-support
se7enxweb/flysystem
lampwick/laravel
jeslage/statamic-emojis
micahdshackelford/rmap-laravel