Developer forum

Forum » Development » Custom order in productlist

Custom order in productlist

Aki Ruuskanen
Aki Ruuskanen
Reply

Hi,

We have a solution where we render the productlist using the repository.

I would need to reorder the products before the paging is done based on some conditions of the current logged in user. 

The BeforeSort and BeforePaging gives me just one page of products. 

The Querying.BeforeQueryDatabase gives me a list of AutoIds but also just for one page. 

I tried BeforeQuery and Settings.Take = 1000 but that changes the pagesize.

Can i modify the order of the whole productlist before paging is done using the repository or could there be a different approach for this?

I want to order the products so that products where a productfield contains the customernumber of the currnet user are displayed first. 

Regards / Aki

 

 

Regards / Aki

 

 

 

 

 

 

 

 


Replies

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Nope - it is not doable. Lucene handles the sorting - because the search result could be 2 mio records long, or even more...

So using Take = 1000 and your own custom paging is one alternative. But it will fuck up facets and a trissillion other things, so I would be careful going down that path.

If you want this to work, you need to get the index to handle this for you. Personalized sorting is difficult using and index. The 'right' way is to implement a CustomScoreProvider for Lucene - but DW does not support that, and maybe not even Lucene.NET supports that.

But you might be able to use boosting for this.

So given you have a custom field on your product containing one or more customer numbers (i.e. Num1, Num2, etc).

Add a new field to the index - using this field and as a string array if it has more customer numbers. Mark it as analyzed (if there are more customer numbers) - or maybe not analyzed?? Try. Then also set boost to 100. That is what we will use to bubble on top. See dump #1.

Now then in your query, we create a 'hack' to give the result a score if the customer number on the product matches that of the user, but still not filter out products that does not have a match on customer number. We do that by adding an or-group and use equal on the customer number field (this should add scoring) and then an alternative expression that is always true. See dump #2

Then sort the result by "Score(), OtherField".

Now what happens is that your search does as it usually do - but now the expression on the customer number should add a high score, and the alternation ensures that items are not removed because of that first expression. Now the score for documents/products where the customer number matches should be high.

Hope you understand - and that it works :-).

BR Nicolai

Capture.PNG Capture2.PNG
Votes for this answer: 1
 
Aki Ruuskanen
Aki Ruuskanen
Reply

Thanks for the very thorough ninja-trick and explanation.  I agree that starting to mess with custom paging will end up in tears. 

I might have solved it an other way but this is a nice backup. 

I made a suggestion to customer where we use two product cataloges with different queries. The "above one" uses a query that checks the productfield for customer number using a macro. And it has only the productlist template. The lower one is the regular product cataloge. 

The CustomScoreProvider was a bit interesting. Looks like Lucene.Net is supporting it. Might come in handy in another case. :)  

Regards / Aki

 

 

 

 

You must be logged in to post in the forum