Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filtering based on average Review/Comment scores and Sorting #569

Open
wants to merge 32 commits into
base: dev
Choose a base branch
from

Conversation

samberrry
Copy link

@samberrry samberrry commented Dec 12, 2021

Questions Answers
Description? Adds the ability to filter products based on average comment scores and sorting. This feature works with native PrestaShop comments module
Type? new feature
BC breaks? yes / no
Deprecations? no
Fixed ticket?
How to test?

This change is Reviewable

@samberrry
Copy link
Author

Hi guys,
I worked on this feature couple months ago, and I thought that it would be a good idea to be added to faceted search module as it's a nice feature for shops, so I decided to make a PR for that :)
thank you

@samberrry samberrry changed the title Filtering basd on average Review/Comment scores and Sorting Filtering based on average Review/Comment scores and Sorting Dec 12, 2021
@samberrry
Copy link
Author

samberrry commented Dec 13, 2021

Screen Shot 2021-12-12 at 8 15 10 PM

@samberrry
Copy link
Author

there is also an online demo here (ps1.7.7.7):
https://demo.binshops.com/en/6-accessories

Screen Shot 2021-12-12 at 8 10 50 PM
as you see in previous PrestaShop versions we had scores on product carts, but they are removed in new version, I've not checked that it comes from theme or comment module, but it would be better to have it on category list.

@samberrry
Copy link
Author

I will add more explanation to the Description or in comments ;) thanks

ps_facetedsearch.php Outdated Show resolved Hide resolved
ps_facetedsearch.php Outdated Show resolved Hide resolved
ps_facetedsearch.php Outdated Show resolved Hide resolved
ps_facetedsearch.php Outdated Show resolved Hide resolved
ps_facetedsearch.php Outdated Show resolved Hide resolved
ps_facetedsearch.php Outdated Show resolved Hide resolved
];

$query = 'SELECT count(g.grade) as count ,g.grade FROM (SELECT t.id_product, case
when t.avg_grade between 1 and 1.99 then "1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't be able to do 0.5 star? I think it costs nothing to start at 0 instead of 1

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually the average score can not be less than 1, because we do not have comments with 0 grade, user must choose between 1-5 values.

when t.avg_grade between 3 and 3.99 then "3"
when t.avg_grade between 4 and 5 then "4"
end as grade
FROM (SELECT avg(h.grade) as avg_grade,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two much subqueries, I'm afraid of performance problems 🤔

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes you are right, I think at least 3 joins are inevitable, but an alternative could be another table which keeps counts for all categories, and can be calculated during indexing.

Copy link
Contributor

@PierreRambaud PierreRambaud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey thank you @samberrry that's a good idea, but I think there are missing important things before being able to merge it.
You can't select two stars, which is something we should be able to do like "I want all 4 and 5 stars items"
image
Seen SQL request are buggy ^^
image

I'll continue the review after ;)

@samberrry
Copy link
Author

samberrry commented Dec 13, 2021

Hi @PierreRambaud, Thanks for review and your comments.
Sorry I did not have a chance to explain in details, so there are some misunderstandings.
Before doing a comment/review filter it's important to figure out what is our measurement? actually how we want to filter and prune product result..
we have multiple options to choose: filter products based on number of comments, based on sum of scores or average scores, etc.. and you know they have different indexing..

so, I've implemented something like what Amazon does in filtering:
https://www.amazon.com/s?k=Home+bedding&i=kitchen-intl-ship&bbn=16225011011&rh=p_72%3A1248917011&dc&pd_rd_r=6a42ef25-9ece-45e9-956f-aafdc97e2421&pd_rd_w=FAkBn&pd_rd_wg=YaJWn&pf_rd_p=bbbef69f-3d9e-41ab-b1eb-e08d5690939b&pf_rd_r=27756W73C6EYFG572GVS&qid=1639410469&rnid=1248913011&ref=sr_nr_p_72_3
Screen Shot 2021-12-13 at 10 08 57 AM

we do not filter based on counts, so when we click on this:
Screen Shot 2021-12-13 at 10 25 26 AM
we expect to see products which have average score equal to "2" or higher stars. This 'two' shows that there are two available products with '2' stars. It's an 'up' filtering, this filter is not multiple choices (like others), we do not expect to have both 'products with average 4 stars and up' and 'products with average 1 star and up'.

Also the number 3 in here:
Screen Shot 2021-12-13 at 10 33 51 AM
It shows that the '3 stars Up' filter is selected, it's just an identifier, I should check that if it's possible change it to 'Avg. Customer Average Reviews: 3 Up'

Again thanks for your review, I should fix the items you mentioned on code.. actually I could not work on the feature too much to optimized and review it very well, we still have some considerations in some sections which one of the important issues is about indexing. It works well when a moderator must approve comments, because I do indexing on comment validated action hook, we also need to do indexing on comment addition when the moderator checking is disabled.
I will continue to work on it.

Thanks ;)

@PierreRambaud
Copy link
Contributor

I really like your idea and better understand the reason about the & Up 😅
I'll try to help you as much as I can 👍

@samberrry
Copy link
Author

@PierreRambaud Thank you 😊
I try to make it better too 😉

@samberrry
Copy link
Author

Hey @PierreRambaud, I was just working on comment indexing and I noticed that the product comment module is using doctrine ORM to store the product comment models, and there is not action hook to get comment addition event or delete event. We need it for the case that the moderator approval is disabled:
Screen Shot 2021-12-15 at 5 07 03 PM
In this situation any comment will be shown without approval, and we need to index these comments somehow. We have action hook for comment approval, so we can update index very well, but when the approval is disabled we do not have events from comment addition as the model is handled by doctrine.
I think the only way is to set cron job, I don know if there is another way to get these events.
I would be happy to know your opinion 😉 thanks

@PierreRambaud
Copy link
Contributor

Hey @PierreRambaud, I was just working on comment indexing and I noticed that the product comment module is using doctrine ORM to store the product comment models, and there is not action hook to get comment addition event or delete event. We need it for the case that the moderator approval is disabled: Screen Shot 2021-12-15 at 5 07 03 PM In this situation any comment will be shown without approval, and we need to index these comments somehow. We have action hook for comment approval, so we can update index very well, but when the approval is disabled we do not have events from comment addition as the model is handled by doctrine. I think the only way is to set cron job, I don know if there is another way to get these events. I would be happy to know your opinion wink thanks

We have two possible choices:

  • Use only SQL queries to retrieve the status of each comment
  • Reduce compatibility range and use Doctrine in this one too

I'm not sure we should remove the compatibility range of this module since it's use by a lot of people, maybe playing with SQL should be enough

@samberrry
Copy link
Author

Hey @PierreRambaud, I was just working on comment indexing and I noticed that the product comment module is using doctrine ORM to store the product comment models, and there is not action hook to get comment addition event or delete event. We need it for the case that the moderator approval is disabled: Screen Shot 2021-12-15 at 5 07 03 PM In this situation any comment will be shown without approval, and we need to index these comments somehow. We have action hook for comment approval, so we can update index very well, but when the approval is disabled we do not have events from comment addition as the model is handled by doctrine. I think the only way is to set cron job, I don know if there is another way to get these events. I would be happy to know your opinion wink thanks

We have two possible choices:

* Use only SQL queries to retrieve the status of each comment

* Reduce compatibility range and use Doctrine in this one too

I'm not sure we should remove the compatibility range of this module since it's use by a lot of people, maybe playing with SQL should be enough

yes. But how should we get notified on comment addition/deletion even?
now there is not any event to trigger indexing.. I think we have another option to do that. We can add an action hook in product comment module, so we can get the event and index it for filtering.
So, I think we have two options, one is cron job, and the second is action hook within product comments module.
If it's necessary, I will try to make a PR on product comments module to add this action hook.

@Hlavtox
Copy link
Contributor

Hlavtox commented Jan 6, 2022

@samberrry @PierreRambaud Guys, this will be a NICE addition! Impressive 🚀

Few points from myself:

  • Try to maintain performance, ideally combine it in one single query as it is now. It's already not very optimized, we must keep performance a priority. :-)
  • What about if you hide other ratings, if you select one? The filter would reappear if the user deletes the selected filter from "Active filters".

@samberrry
Copy link
Author

@samberrry @PierreRambaud Guys, this will be a NICE addition! Impressive 🚀

Few points from myself:

* Try to maintain performance, ideally combine it in one single query as it is now. It's already not very optimized, we must keep performance a priority. :-)

* What about if you hide other ratings, if you select one? The filter would reappear if the user deletes the selected filter from "Active filters".

Hi, thanks for your interest 😉I agree with you on to keeping performance a priority.
About the ratings, I think it would be better to keep it like what amazon does, as it's not like other filters, and here we have 'up' idea which implies a range.

@kpodemski
Copy link
Contributor

Hey @samberrry

It's a great contribution. I know you're probably busy, but will you continue with it? It's been a while since the last activity there.

@samberrry
Copy link
Author

  • git rebase (to the latest master version) and conflict resolution done.
  • I've not tested yet.
  • After doing tests I will mention reviewers.

@matks matks changed the base branch from master to dev September 8, 2022 14:34
@matks
Copy link
Contributor

matks commented Sep 8, 2022

@samberrry PRs must be submitted against dev branch, not master 😉 I changed the base branch of this Pull Request

@samberrry
Copy link
Author

@samberrry PRs must be submitted against dev branch, not master 😉 I changed the base branch of this Pull Request

Oh thanks! mistaken :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants