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

Tracking issue: SortBy at query time #730

Closed
Kerollmops opened this issue May 28, 2020 · 30 comments
Closed

Tracking issue: SortBy at query time #730

Kerollmops opened this issue May 28, 2020 · 30 comments
Labels
feature request & feedback Go to https://github.com/meilisearch/product/

Comments

@Kerollmops
Copy link
Member

Kerollmops commented May 28, 2020

The SortBy feature is something that will help e-commerce websites or any website that needs to display documents in an order that depends on the user front-end settings, therefore at query time. This can be useful when you want the user to be able to choose if he want to see documents by ascending or descending price for example.

For that we will add two settings:

  • The sortableAttributes field to the settings, this way the engine is aware of the fields that it needs to index like numbers, etc...
  • The sortBy field to the search query parameters, it contains the name of one of the sortable attribute you defined in the settings and will be used as the last sorting criterion.

How Algolia handles that

Algolia uses replicas to handle this kind of custom search, for each of the custom sortable attributes you want to have, the tools of Algolia creates replicas of your main index and changes the settings.

When a search query with custom sorting rules is performed, the front-end tools will request the right index. This index is named based on the rules you changed e.g. "movies_asc(price)_desc(released_at)".

Notice that you pay for all the replicas you have and all documents that are in any index count, it means if your plan allows you to have 10k documents but you have one replica, therefore you can only have 5k documents.

@MarinPostma
Copy link
Contributor

Do really need to create multiple indexes? Right now, criteria are built at search time. The only place where we actually need a sorted document cache is for placeholder search, for which we need to cache sorted document_ids. What I am not completely sure about is how do we compose sorts. Should we allow sort by asc(foo) and desc(bar) for example? Should these case be specified in the sortableAttributes setting?

@MarinPostma
Copy link
Contributor

MarinPostma commented Jun 17, 2020

I am thinking of a SortStrategies settings, that maps strategy names to set of ranking rules. The sortBy search parameter accepts a sort strategy:

{
   "sortStrategies": {
        "price_asc": [typo, asc(price)],
    }
}

WDYT @Kerollmops @curquiza @bidoubiwa @eskombro

@jiminy-billy-bob
Copy link

So we would have to know in advance every possible sort filter combinations?

@MarinPostma
Copy link
Contributor

yeah this seems necessary to perform efficient sorting...

@MarinPostma
Copy link
Contributor

also if i'm not mistaken, we need a ranked_map for each sorting strategy, is that right @Kerollmops

@jiminy-billy-bob
Copy link

Okay, it's not ideal from a usage POV, but it's still usable. So it sounds like a good compromise.

@curquiza
Copy link
Member

curquiza commented Jun 17, 2020

Is sortStrategies a replacement for the sortableAttributes suggestion of @Kerollmops or another settings?

@MarinPostma
Copy link
Contributor

replacement, Algolia call them sorting strategies, and I think it makes more sense when you sort according to multiple criteria at the same time

@curquiza
Copy link
Member

I think:

  • sortStrategies is better if you set this kind of infomation:
{
    price_asc": [ typo, asc(price) ],
    ...
},
  • sortableAttributes is better if you can only set this kind of information:
[price,  ...]

@MarinPostma
Copy link
Contributor

How do you specify the other rules in this case?

@MarinPostma
Copy link
Contributor

Ah yes I get what you mean, but we can't support placeholder search if we do that

@curquiza
Copy link
Member

curquiza commented Jun 17, 2020

When I read the @Kerollmops issue description:

The sortableAttributes field to the settings, this way the engine is aware of the fields that it needs to index like numbers, etc..

I was not sure to really understand what you expected, so, I thought about an array of string with attributes names, but I was not sure at all 😅

@Kerollmops
Copy link
Member Author

Kerollmops commented Jun 17, 2020

Do really need to create multiple indexes?

No we don't we we do is adding a new setting where we list all of the attributes we use for the sortBy feature. This way the engine will create a ranked map for all of the listed attributes.

"sortableAttributes" : ["price", "createdAt"]

Right now, criteria are built at search time.

Yeah, but the ranking rules are already known by the engine, therefore the ranked map have already been created for all of the criteria i.e. asc(price).

Should we allow sort by asc(foo) and desc(bar) for example? Should these case be specified in the sortableAttributes setting?

I want to support combined sort startegies but @qdequele didn't thought it was useful.


also if i'm not mistaken, we need a ranked_map for each sorting strategy, is that right

@marin we have a ranked map by attribute that is used in any criterion, not a ranked map by criterion. Ranked maps doesn't know about the sort order i.e. asc, desc.

@MarinPostma
Copy link
Contributor

@Kerollmops we also keep a sorted list of doctors for every attributes then for placeholder search

@MarinPostma
Copy link
Contributor

How does that mix with existing ranking rules?

@qdequele
Copy link
Member

qdequele commented Jun 17, 2020

@Kerollmops I think we can easily do multiple sorts during the search by declaring in settings the possible sortable attributes.
sortableAttributes: ["time", "price"]

And in the search query, write the complete sort operation to do. sortBy:[dsc(time), asc(price)]. Does this seem too complicated?

@MarinPostma
Copy link
Contributor

This is not possible with placeholder search

@paligiannis
Copy link

do we have any news on issue?

@gmourier
Copy link
Member

Hello @paligiannis! This is an actively requested feature by our users, we will start working on it for releases coming after 0.21. I can't give an exact date but I will push this feature for our next iterations. We still need to define how far we want to go with the sortBy.

@paligiannis
Copy link

@gmourier thanks for the reply. I would be interested if I could help in research or anything, please let me know.

@gmourier
Copy link
Member

Thanks @paligiannis!

@ppamorim
Copy link
Contributor

ppamorim commented Jun 4, 2021

Any news on this matter? We have been looking in ways to order our data using multiple integer fields.

@curquiza
Copy link
Member

curquiza commented Jun 4, 2021

Hello @ppamorim, @gmourier answered about this less than 2 weeks ago in this same issue 😉 #730 (comment)
It's complicated for us to give an exact release date, but be sure it's in our roadmap.

@bmpf
Copy link

bmpf commented Jul 5, 2021

Filters : show document by true or false, example : product in stock = true , product has promo = false ;
Thank you @ppamorim ,

@curquiza curquiza added feature request & feedback Go to https://github.com/meilisearch/product/ and removed tracking issue Tracks development of a global issue labels Aug 5, 2021
@curquiza
Copy link
Member

curquiza commented Aug 5, 2021

Closed in favor of a future tracking issue coming soon! :)

@curquiza curquiza closed this as completed Aug 5, 2021
@vvnsrzn
Copy link

vvnsrzn commented Aug 5, 2021

It would have been nice to get the new issue link before closing this one.
Hope you will keep us updated.

@curquiza
Copy link
Member

curquiza commented Aug 5, 2021

We don't have any tracking issue ready yet, but here is most of the work done by our PM on it https://github.com/meilisearch/product/issues/43
This current issue it totally obsolete, that's why we close it

@curquiza
Copy link
Member

Here is the new one: #1581

@martijnderidder
Copy link

Ok! I got it al wotking, the big problem was that when using docker, i assumed that

meilisearch:
        image: getmeili/meilisearch:latest
...

Would be the latest version... but i got an old one.. maybe it was my cache or something. I now typed the version, and its working. Thank you guys for your time and effort!

@curquiza
Copy link
Member

When using docker you have to docker pull getmeili/meilisearch:latest otherwise docker will keep the one in cache :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request & feedback Go to https://github.com/meilisearch/product/
Projects
None yet
Development

No branches or pull requests