Hi guys,
I know it might sound stupid, but I have to ask.
If I define a Grouping field in the index and set it to "Stored", is there any way of reading it in the template on the regular GetLoop("Products")?
Thank you,
Adrian
Hi guys,
I know it might sound stupid, but I have to ask.
If I define a Grouping field in the index and set it to "Stored", is there any way of reading it in the template on the regular GetLoop("Products")?
Thank you,
Adrian
Hi Adrian,
The Product Catalog App only gets back AutoIds from the Index, and then queries the Services layer (aka cache) and/or database to get the real data. So your options end up being:
I'd recommend the 3rd option. You can go with the 2nd, but I've never done quite like that, but here's some code that can get you the result of a query. It was built for Users, but it works just the same for Products
public static UserResult QueryUsers(string userName = "") |
{ |
var queryService = Dynamicweb.Extensibility.ServiceLocator.Current.GetInstance<Dynamicweb.Indexing.Querying.IQueryService>(); |
var querySettings = new Dynamicweb.Indexing.Querying.QuerySettings(); |
var parameters = new Dictionary<string, object>(); |
parameters.Add("username", userName); |
querySettings.Parameters = parameters; |
var result = queryService.Query(queryService.LoadQuery("Users", "Users.query"), querySettings); |
var counter = 0; |
var user = new UserResult() {Results = new List<IDictionary<string, object>>()}; |
foreach (object resultObject in result.QueryResult) |
{ |
var resultDictionary = resultObject as IDictionary<string, object>; |
user.Results.Add(resultDictionary); |
} |
user.TotalCount = result.TotalCount; |
return user; |
} |
var userLocations = QueryUsers(); |
if (userLocations.TotalCount > 0) |
{ |
@foreach (var userLocation in userLocations.Results) |
{ |
@userLocation["UserID"]" |
} |
} |
Best Regards,
Nuno
I would be careful to use 3rd option as it can be relatively slow - if you do that on a product list. Open, query, read the index on 30+ products is not super. If you choose this option you should query all the product documents in one go and store the result.
An alternative is to create a custom field on the product and make a scheduled task using the SQL add-in and put the value in that custom field. Then it can be indexed and it can be accessed from the product list for 'free'
BR Nicolai
Hi guys,
Thank you very much for all suggestions.
Performance is clearly something I need to be careful with.
I will evaluate my options now that I have quite a few :)
Thank you very much,
Adrian
You must be logged in to post in the forum