This project is read-only.

Prioritising content types in the search

Topics: Customizing Orchard
Jun 4, 2013 at 11:37 AM

Is there a way to prioritise search results by their content type?

I'm currently looking in to the ISearchService.Query<T> method and I assume that any ordering would need to happen in the Search().Parse call.

Before spend too much time looking in to this, I was just wondering/hoping someone has already done this or has a good suggestion as to how I can prioritise content based on type

Thank you for any help
Jun 4, 2013 at 12:08 PM
Edited Jun 4, 2013 at 12:10 PM
In the line 30 from SearchService.cs, there is a parameter string query.
My assumption is you need to modify this query before to call the service.
Is someone can give his point of view?
Jun 4, 2013 at 1:35 PM
Hello alexandreb

Thank you for your response, but the parameter query pertains to the searchable areas of the content type such as title or body.
I don't know how modifying the query would help?

Jun 5, 2013 at 12:01 PM

If anyone needs to do this in the future, it can be done by adding a DocumentIndex field (i.e pagePriority) to the common part via a ContentHandler class. assign your content types an integer value for priority. Then in the SearchService for the Search().Parse() call you need to sort the results by the DocumentIndex filed.

e.g - SiteSearchHandler

public class SiteSearchHandler : ContentHandler {
    public SiteSearchHandler() {
        OnIndexing<CommonPart>((context, commonPart) => context.DocumentIndex
            .Add("pagePriority", GetPriority(commonPart.ContentItem.ContentType)).Analyze().Store()

    private int GetPriority(string contentType) {
        if (contentType == "ImportantPages") {
            return 3;
        else if (contentType == "LessImportantPages"){
            return 2;
            return 1;

e.g - SearchService

searchBuilder = Search().Parse(searchFields, formattedQuery.Trim(), false).SortByInteger("pagePriority").Ascending();

PS - We created another module that overrides the current module