geolocationpolygoninstantsearch.jstypesense

How to use geo location within filter polygon using typesense instantsearch adapter


I create one demo instantsearch js with typesense.

Issue is when i search city the result come all result not filtering with _geoloc and polygon.

I use _geoloc field to store lat long with float array in typesense.

{"name": "_geoloc", "type": "float[]" , "facet": true },

And _geoloc pass geoLocationField parameter in Typesense instantSearch adapter.

const polygon = [
    42.01,-124.31,
    48.835509470063045,-124.40453125000005,
    45.01082951668149,-65.95726562500005,
    31.247243545293433,-81.06578125000004,
    25.924152577235226,-97.68234374999997,
    32.300311895879545,-117.54828125      
];

const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
    server: {
        apiKey: "xyz",
        nodes: [{
            host: "localhost",
            port: "8108",
            protocol: "http",
        }, ],
        cacheSearchResultsForSeconds: 2 * 60,
    },
    insidePolygon: [polygon],
    geoLocationField: "_geoloc",
    additionalSearchParameters: {
        queryBy: "name",
    },
});

Solution

  • Thank you for helping @ErJab

    After some research, I got a new solution and it's working perfectly.

    Typesense adapter updated their code for the polygon search.

    https://github.com/typesense/typesense-instantsearch-adapter/blob/978af9577ef632003aa2de6b1761772d979377eb/src/SearchRequestAdapter.js#L167-L198

    now we can able to search inside a polygon.

    const polygon = [
        42.01,-124.31,
        48.835509470063045,-124.40453125000005,
        45.01082951668149,-65.95726562500005,
        31.247243545293433,-81.06578125000004,
        25.924152577235226,-97.68234374999997,
        32.300311895879545,-117.54828125      
    ];
    const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
        server: {
            apiKey: "xyz",
            nodes: [{
                host: "localhost",
                port: "8108",
                protocol: "http",
            }, ],
            cacheSearchResultsForSeconds: 2 * 60,
        },
        geoLocationField: "_geoloc",
        additionalSearchParameters: {
            queryBy: "name",
        },
    });
    const searchClient = typesenseInstantsearchAdapter.searchClient;
    
    const search = instantsearch({
        searchClient,
        indexName: "airports",
    });
    
    search.addWidgets([
        searchBox({
            container: '#searchbox',
            placeholder: 'Search for products',
        }),
        configure({
            insidePolygon : polygon,
        }),
    ]);