Developer forum

Forum » Ecommerce - Standard features » Boosting score on productlist

Boosting score on productlist

Thomas Larsen
Reply

Hi,

I need to make a productlist based on a index, and on that productlist I need to access the boosting score.

My priority one, is to access that on a normal productlist templete, is that possible?

Otherwise i’m thinking about using the Query Publisher and make that render the products. I’s I possible to make a template extender for the Query publisher?
I know I can get the Product object directly in the razor template, but I would like to reuse existing product list templates, used other places in the solution.

My last approach would be to create a custom modules that calls the index and handling all the rendering, is that possible?

BR
Thomas


Replies

 
Morten Bengtson Dynamicweb Employee
Morten Bengtson
Reply

You should be able to do that, but I wouldn't recommend it.

I'm curious to know why you need the score? It's just a number used internally by the query provider for sorting the search results.

Anyway, here is some untested VB code (sorry) that you might be able to use as a starting point...

' Get query
Dim queryService As New QueryService()
Dim query = queryService.LoadQuery("RepositoryName", "QueryName")
Dim querySetting As New QuerySettings() ' TODO: Provide settings

' Perform the search
Dim result As IQueryResult = queryService.Query(query, querySetting)

' Read AutoIDs from search result
Dim autoIds As New Dictionary(Of Long, Single)

For Each element In result.QueryResult
    Dim queryElement = DirectCast(element, Dictionary(Of String, Object))
    Dim autoId = DirectCast(queryElement("AutoID"), Long)
    Dim score = DirectCast(queryElement("_score"), Single)
    autoIds.Add(autoId, score)
Next

' Get products by AutoIDs
Dim products = Services.Products.GetProductsByAutoIDs(autoIds.Keys)

For Each product In products
   Dim score As Single = autoIds(product.AutoId)
   ' TODO: Render product and score
Next

Note: This code might break if we decide to change or replace the internal query provider implementation in a future major release.

Best regards,
Morten

 

You must be logged in to post in the forum