Posted on 22/12/2020 09:50:58
Hi Kasper,
If you want a more Dynamicweb centric solution, here's an example of how to query an index using Dynamicweb APIs.
public void DoSearch(string queryPath)
{
var queryService = ServiceLocator.Current.GetInstance<IQueryService>();
var query = queryService.LoadQuery(queryPath);
var settings = new QuerySettings
{
Skip = 30,
Take = 30,
Parameters = new Dictionary<string, object>
{
{ "ProductID", new[] { "PROD10", "PROD11", "PROD12", "PROD13", "PROD14" } },
{ "LanguageID", "LANG2" }
}
};
var result = queryService.Query(query, settings);
var autoIds = new List<long>();
foreach (Dictionary<string, object> document in result.QueryResult)
{
var productAutoId = (long)document["AutoID"];
autoIds.Add(productAutoId);
}
var products = Services.Products.GetByAutoIDs(autoIds);
}
This example reads from a given index using a query, the queryPath must be the full path to a Dynamicweb query.
It is possible to create a query using code, but it's more involved, so I've omitted an example. If this is what you're looking for, please let me know.
- Jeppe