Developer forum

Forum » Development » New index - create parameters programmatically

New index - create parameters programmatically

Lars Larsen
Reply

Hi,

Is it possible to programmatically add parameters to an index? If so how is it done?


Replies

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

You do not add parameters to an index. In the index you have documents which again has fields.

A search can have parameters - which are values for the right hand side of the search criteria.

Queries and its criterias (Expressions) and parameters are saved in a XML file found in /Files/System/Repositories/YourRepositoryName/YourQueryName.query

You can read it like this (Reference Dynamicweb.Querying):

Dim queryService As IQueryService = ServiceLocator.Current.GetInstance(Of IQueryService)()
Dim query As IQuery = queryService.LoadQuery("YourRepositoryName", "YourQueryName" + ".query")
Dim exp As Expressions.GroupExpression = DirectCast(query.Expression, Expressions.GroupExpression)
exp.Expressions.Add(any Expressions.* expression type)
 
The Expressioin property on the query can return any Expressions.* type - so test it - but usually it will be a GroupExpression. The group expression then has a collection of expressions in its Expressions property - that will be your search.
 
The Query also have a Parameters property - that returns your parameters - used in the querystring.
Votes for this answer: 1
 
Lars Larsen
Reply

Hi Nicolai

Oops, sorry I did not use the right terms for what I want to accomplish. But I want to add parameters to the search dynamically because I have added the sort order (in the backend) of products in product groups to fields in the index. Now I want to sort on these fields in the frontend and therefore needs these fields as parameters in the search. After having used your example code I managed to add the parameters to the Parameters property and now I can sort products in the frontend according to their sort order in the backend.

Thanks smiley

 

You must be logged in to post in the forum