Algolia - excluding results with specific values - search

I'm trying to figure out how to exclude specific records from my search results.
My records look like this:
eventId:bcf9e22b-adb1-11e6-b058-0623f336d3b3
name:Event Name
fullAddress:1964 Long Beach Rd, Toronto, ON, Canada
latitude:44.998148000000
longitude:-79.319882400000
eventStartAt:1469948400
objectID:eyJpZCI6ImJjZjllMjJiLWFkYjEtMTFlNi1iMDU4LTA2MjNmMzM2ZDNiMyJ9
So while searching for event name I'm trying to exclude certain records that have specific eventId.
I'm using Symfony bundle provided by Algolia so my code looks like this:
$results = $this->get('algolia.indexer')->search(
$this->get('doctrine.orm.entity_manager'),
'MyBundle:Entity',
'Random Event Name',
[
'numericFilters' => 'eventStartAt > 1469948000',
'minWordSizefor1Typo' => 2,
'filters' => 'NOT eventId:b2c7a242-e17d-11e6-b058-0623f336d3b3',
]
);
Which produces request body:
{
"params": "numericFilters=eventStartAt+%3E+1469948000&minWordSizefor1Typo=2&filters=NOT+eventId%3Ab2c7a242-e17d-11e6-b058-0623f336d3b3&query=Random+Event+Name"
}
Problem is that NOT eventId:b2c7a242-e17d-11e6-b058-0623f336d3b3 filter does not seem to be applied at all, and record with eventId of b2c7a242-e17d-11e6-b058-0623f336d3b3 is still present in my results.

Related

Shopware filter is using parents price also for products where only variants are being used

We have a sage integration to shopware 6. They integrate product variants as well.
BUT: For the parent product of variant products - they put into the price field 999.999€. The product variants indeed have correct prices.
The problem is: We use the client-api to fetch all products of a category and with that also their filters. (see https://shopware.stoplight.io/docs/store-api/cf2592a37b40b-fetch-a-product-listing-by-category)
The price filter does show the very high 999.999€ price, even though no product variant has this price. Only the (not used/shown) parents.
Is there a way around this? Especially without maintaining the Parent-Price manually? Ideally the Shopware API would not include the prices of the parent products... Can this be configured maybe?
Any hint appreciated :wink:
Example response from /store-api/product-listing/CATEGORY_ID
"aggregations": {
"price": {
"min": "249.0000",
"max": "999999.9900",
"avg": null,
"sum": null,
"apiAlias": "price_aggregation"
},
I called the api endpoint for a category that contains variant products. Their parent products have 999.999€ as a price. As a filter aggregation for price I get a max price of 999999 where I would expect the highest price of all products and variant products. But not having the price of the variants parents included.
One possible approach would be to subscribe to the ProductListingCriteriaEvent and wrap the original price aggregation in a FilterAggregation. With the filter aggregation you can limit the range of the inner StatsAggregation named price.
class MyProductListingSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents(): array
{
// set a priority for the listener below -100
// so it is executed after the original aggregations are set
return [
ProductListingCriteriaEvent::class => [
['enhanceCriteria', -101],
],
ProductSearchCriteriaEvent::class => [
['enhanceCriteria', -101],
],
];
}
public function enhanceCriteria(ProductListingCriteriaEvent $event): void
{
$criteria = $event->getCriteria();
$aggregations = $criteria->getAggregations();
$criteria->resetAggregations(); // remove all aggregations
foreach ($aggregations as $aggregation) {
if ($aggregation->getName() !== 'price') {
// re-add aggregations not name 'price'
$criteria->addAggregation($aggregation);
continue;
}
// wrap original aggregation and set a `RangeFilter` for the gross price
$filterAggregration = new FilterAggregation(
'filter-price-stats',
$aggregation,
[
new RangeFilter(
'cheapestPrice.gross',
[
RangeFilter::LT => 999999.99,
]
)
]
);
$criteria->addAggregation($filterAggregration);
}
}
}
This should yield a max price for the filter with the exception of prices equal to or larger than 999999.99.
The problem was the indexing behavior. We had products on this installation before, which were deleted. New products were imported then. Something must have gone wrong with the indexing.
What solved our issue was refreshing the index using the console
.bin/console dal:refresh:index

Nodejs Elasticsearch query default behaviour

On a daily basis, I'm pushing data (time_series) to Elasticsearch. I created an index pattern, and my index have the name: myindex_* , where * is today date (an index pattern has been setup). Thus after a week, I have: myindex_2022-06-20, myindex_2022-06-21... myindex_2022-06-27.
Let's assume my index is indexing products' prices. Thus inside each myindex_*, I have got:
myindex_2022-06-26 is including many products prices like this:
{
"reference_code": "123456789",
"price": 10.00
},
...
myindex_2022-06-27:
{
"reference_code": "123456789",
"price": 12.00
},
I'm using this query to get the reference code and the corresponding prices. And it works great.
const data = await elasticClient.search({
index: myindex_2022-06-27,
body: {
query: {
match: {
"reference_code": "123456789"
}
}
}
});
But, I would like to have a query that if in the index of the date 2022-06-27, there is no data, then it checks, in the previous index 2022-06-26, and so on (until e.g. 10x).
Not sure, but it seems it's doing this when I replace myindex_2022-06-27 by myindex_* (not sure it's the default behaviour).
The issue is that when I'm using this way, I got prices from other index but it seems to use the oldest one. I would like to get the newest one instead, thus the opposite way.
How should I proceed?
If you query with index wildcard, it should return a list of documents, where every document will include some meta fields as _index and _id.
You can sort by _index, to make elastic search return the latest document at position [0] in your list.
const data = await elasticClient.search({
index: myindex_2022-*,
body: {
query: {
match: {
"reference_code": "123456789"
}
}
sort : { "_index" : "desc" },
}
});

How do I get json data with retrhinkdb

(I'm not good eng.)
I use a group to include dates. I want to get the information out in a row. What do i need to do
.group(r.row('time_create').dayOfWeek())
json export
[
{
group: 1,
reduction: [
{
detail: "no",
id: "37751c10-97ea-4a3a-b2c9-3e8b39383b79",
order_id: "15",
status: "Not_Delivery",
time_create: "2018-09-23T15:25:13.141Z"
}
]
}
]
i want change data json to
{
"date":
{
"Sun": [
{
detail: "no",
order_id: "15",
status: "Not_Delivery",
time_create: "2018-09-28 15:25:13"
}
]
}
}
Do i have to give the information out as i want.
Looks like you tried but didn't manage to transform the data from your previous question. ;)
Here is a proposition, this is not the only way of doing it.
First, it seems you want to remove the id field. You may do that in your ReQL using without:
.group(r.row('time_create').dayOfWeek()).without('id')
(You may apply without('id') before group, it should work the same, see this for more details.)
Then, to transform the result array (let's call it queryResult) into an object (let's call it output):
// prepare the skeleton of the output
let output = {
date: {}
};
// walk the result, filling the output in the process
queryResult.forEach((groupData) => {
let key = groupData.group;
if (!output[key]) {
output[key] = [];
}
output.date[key].push(...groupData.reduction);
})
Now you almost have your desired structure in output, the only thing is that day keys are still numbers and not a short day name. In my opinion, this should be handled by the front-end, since you may want to have different languages implemented for your front-end. But anyway, the idea is always the same: having a translation table that maps Rethink's day numbers with human-readable day names:
const translationTable = {
1: 'Mon',
2: 'Tue',
// ...
7: 'Sun'
};
Now if you do that in your front-end, you just replace the data's keys on the fly, when displaying is needed (or retrieve the key from the day name, depending on how you display stuff). Otherwise, if you go for a back-end implementation (which, again, is clearly not the best solution), you can change one line in the code above (assuming you declared translationTable already):
let key = groupData.group;
// becomes
let key = translationTable[groupData.group];
Feel free to ask in comments if there's something you don't understand!

Suitescript 2.0 - how to get a particular product SKU within a Sales Order

I'm working on a script which required to find a particular product SKU within a Sales Order.
Order is placed through webservice API and every time an order is placed, I need to search for a particular product.
I did look at the Suitescript 2.0 API documentation and its seems there are a two options for me to investigate: 1 - Line item, 2 - Sublist
I'm wondering if anyone can give me a hint on how to achieve this on suitescript 2.0
Here's how to find a line in SS2.0.
// Finding a specific line item in SuiteScript 2.0...
require(["N/record"], function (r) {
var rec = r.load({
"type": r.Type.SALES_ORDER,
"id": 123
});
// Find the line that contains item 777
var index = rec.findSublistLineWithValue({"sublistId": "item", "fieldId": "item", "value": 777});
// find returns -1 if the item isn't found
if (index > -1) {
// we found it on line "index"
} else {
// item 777 is not in the list
}
});

MongoDB Location NearBy unique

I have created a collection in DB and updated with proper indexing to retrieve it back. Im getting with the folloging
Example:
db.car.save({ "name":"Toyota car", "affiliation":"Toyota", "loc":{"lon":55.93939251390387,"lat":-113.999}})
db.car.find({"loc" : {"$within" : {"$center" : [[50.93939251390,-114],5]}}})
I have 100K + records in Database when I search the above query returns 20K records.
Actually this has some duplicate values in the "name" column. How can I get the distinct value of "name".
You can't get the results you need using a query in MongoDB 2.0.x, so will need to manipulate the results in your application code.
If you are only after names you can limit the fields in the output:
db.car.find(
{"loc" : {"$within" : {"$center" : [[50.93939251390,-114],5]}}},
{"_id": 0, "name": 1}
)
If you want to find distinct names you could do something like:
// Save cars we've seen
> var cars_seen = {}
// The unique list we actually want
> var cars = []
// Find closest cars to given geo point
> db.car.find(
{"loc" : {"$within" : {"$center" : [[50.93939251390,-114],5]}}},
{"_id": 0, "name": 1}
).forEach(
function(doc) {
// Add names we haven't seen yet
if (!cars_seen[doc.name]) {
cars_seen[doc.name] = 1;
cars.push(doc.name);
}
}
)
> cars
[ "Skoda", "Benz", "Skoda SUV" ]

Resources