sitecore7.2 - Ordering Sitecore search results -
i have iqueryable<t>
object search results object. apply filtering , sorting on search object.
before call getresults()
, want order results based on 1 of field's (fieldname - priority
) value. items in iqueryable<t>
object, want order them desc priority field, items has value field stay @ top , rest @ bottom.
i have fieldmap
entry priority field.
search.orderbydescending(i => !string.isnullorempty(i.getitem().getfieldvalue("priority")))
the above command doesn't work. apparently, can't use sitecore extension methods iqueryable?
if convert search.tolist()
. ordering , convert asqueryable()
, following error:
there no method 'getresults' on type 'sitecore.contentsearch.linq.queryableextensions' matches specified arguments
is there neat , quick way around this?
cheers
i think need add field searchresultitem , mark int. making assumption field int. make custom class inherits searchresultitem.
public class customsearchresultitem : searchresultitem { [indexfield("priority")] public int priority { get; set; } }
then use in search. order it.
using (var context = contentsearchmanager.getindex("sitecore_master_index").createsearchcontext()) { var results = context.getqueryable<customsearchresultitem>().where(prod => prod.content.contains("search box text").orderbydescending(t => t.priority); }
some data found here.
Comments
Post a Comment