我用typesense创建了一个示例实例搜索js。
问题是当我搜索城市结果时,所有结果都用_geoloc和多边形进行过滤。。
我使用_geoloc字段来存储lat长,并在类型中使用浮点数数组。
{"name": "_geoloc", "type": "float[]" , "facet": true },
_geoloc在Typesense instantSearch适配器中传递geoLocationField参数。
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",
},
});发布于 2021-09-14 14:17:09
谢谢你帮助@ErJab
经过一番研究,我找到了一个新的解决方案,而且效果很好。
Typesense适配器更新了用于多边形搜索的代码。
现在我们可以在多边形内搜索。
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,
}),
]);发布于 2021-08-27 23:51:24
从Typesense Instantsearch适配器的v2.1.0开始,您可以为此使用configure InstantSearch.js小部件,而不是将其传递到Typesense适配器。
就像这样:
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
];
instantsearch.widgets.configure({
insidePolygon: polygon,
});https://stackoverflow.com/questions/68904397
复制相似问题