Posted on 29/01/2019 13:55:31
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