Skip to content
This repository has been archived by the owner on Oct 17, 2020. It is now read-only.

[Feature] Make Filter structure in Search package more extendible #879

Open
rohithbalaji123 opened this issue Jun 24, 2020 · 5 comments
Open
Labels
enhancement New feature or request

Comments

@rohithbalaji123
Copy link
Member

What is the problem?

There is an inherent coupling between Resource and Order structures in Filter and it is quite difficult to extend when we try to add more resources or order by classes. That is., there is a requirement for every Resource to support each Order bys which will not be the case at all times.

When trying to add a new Resource:

  • We will need to add a method to the Order interface with the name ArrangeResource. That would mean that we need to implement those methods in all existing structures which implements Order(say CreatedTime ). But, the newly added Resource may not even have any field related to created time.

When trying to add a new Order:

  • When we have a requirement to add a new Order By(say a new column which tracks number of times the short link is visited), we cannot add this Order By as that would mean, we will have to implement all the methods in the Order interface (currently has ArrangeShortLinks, ArrangeUsers). But, this new Order By is related only to ShortLinks.

Your solution

Will have to think through to come up with a more generic solution.

Alternatives considered

For resources not supporting a particular order by, we can throw NotApplicable error when the package's client tries to order by the unsupported order by. This will also include validating in NewFilter that the resource and order arrays are compatible with each other.

@magicoder10
Copy link
Member

magicoder10 commented Jun 24, 2020

@rohithbalaji123

  1. I don't think all resources has to support the same order. When can do unchanged order for those not supported. Validation is needed though.
  2. We don't have generics support in Go 1. Waiting for Go 2. It's already in experimentation stage

@rohithbalaji123
Copy link
Member Author

@byliuyang Yes, we can do unchanged order for unsupported resource. My concern is, what should ArrangeNewResource method's implementation be in CreatedTime structure when NewResource doesn't have a column called createdAt?

@magicoder10
Copy link
Member

@rohithbalaji123 It doesn’t do anything? Is this avoidable?

@rohithbalaji123
Copy link
Member Author

@byliuyang , I am not sure how to avoid it. When we add more and more resources and Order By implementations, there will be a lot combinations where the method implementations will be empty.

@arberiii
Copy link
Member

We can also reverse things here, so each resource implements each order, and in case that an implementation is not possible we keep the slice unchanged. So we can have a resource type []entity.ShortLink which implements all the order types

@magicoder10 magicoder10 added this to To do in Search Engine via automation Jul 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
Search Engine
  
To do
Development

No branches or pull requests

3 participants