Reputation: 21
I'm using algolia search as my search engine. But there is a problem with displaying the correct price with the results. The price is calculated based on search parameters so it can't be indexen in the records. Where should i calculate the price? Its a cap service where you can find drivers with ratings, name, company info. Price is calculated based in price for each mile. The search input is from > to location. Thanks. Im using php with JS results.
Upvotes: 2
Views: 1107
Reputation: 61
import { useState, useEffect } from 'react';
import { connectRange } from 'react-instantsearch-dom';
import { Paragraph } from '../atoms';
const priceRange = [
{ id: 1, min: undefined, max: undefined, title: 'All' },
{ id: 2, min: 20, max: 99, title: 'Under $99' },
{ id: 3, min: 100, max: 499, title: '$100 - $499' },
{ id: 4, min: 500, max: 999, title: '$500 - $999' },
{ id: 5, min: 1000, max: 2499, title: '$1000 - $2499' },
{ id: 6, min: 2500, max: 4999, title: '$2500 - $4900' },
{
id: 7,
min: 5000,
max: 8900,
title: 'Over $5,000',
},
];
const PricingFilter = ({ refine }) => {
const [selected, setSelected] = useState({});
useEffect(() => {
if (selected) {
refine({ min: selected?.min, max: selected?.max });
}
}, [selected]);
return (
<ul>
{priceRange &&
priceRange.map((item) => {
return (
<li key={item.id}>
<a
onClick={() => {
setSelected({
min: item.min || undefined,
max: item.max || undefined,
});
}}
role="button"
aria-hidden="true"
className="filter-item-wrapper">
<Paragraph
size="6"
className={item.id ? 'has-text-weight-bold my-1' : 'my-1'}>
{item.title}
</Paragraph>
</a>
</li>
);
})}
</ul>
);
};
export default connectRange(PricingFilter);
Upvotes: 0
Reputation: 3209
The issue with sorting or filtering by a dynamic value is that you need to first calculate that value...
e.g. Price = geo-distance(from user position to destination) * rate-per-mile + flag-drop
...for each document which could be valid.
If you have a lot of documents, and no way to filter your selection down before running your calculation, then the processing for your custom ranking will take the same computational effort as would processing a SQL query (requiring a full table scan).
Algolia, so far, seems to be all about speed. They build the data structures to support that speed at index-time. The current support for customRanking
is limited to sorting by a custom list of fields asc/desc.
You can implement what you describe using Solr or Elasticsearch using function score queries.
And since you probably don't have more than a few thousand drivers to run this query calculation against, the performance issue (mentioned first) may not be a big concern.
Upvotes: 1
Reputation: 2319
Maybe the best way to deal with that is to call a backend API endpoint on your end to compute the "dynamic" prices of the results returned by Algolia. I would go for an AJAX call as soon as you receive the results, before rendering them providing for each objectID
of the results set its price.
Upvotes: 1