Search with Lucene

Mats Knutsen-Valen
Member since: 2010

I am using the built-in search in EPiServer, and so far so good. However I need to display the part of the page that matches the query. For instance: A user searches for "water" and in one page the match is "it is water in the ocean" , I want to display:

1) title of the page

2) the text where the search matched.


Is this possible?

#64442 Dec 20, 2012 14:26
  • Mats Knutsen-Valen
    Member since: 2010

    Figured out this is inside the IndexResponseItems property on SearchResults

    #64444 Dec 20, 2012 14:59
  • Mats Knutsen-Valen
    Member since: 2010

    A bit of a follow-up here: Through the IndexResponseItem I am able to extract DisplayText and Title, When I then try to fetch a link to the result through the Uri property I only get strings on this format: 


    Earlier I used :

    var urlResolver = ServiceLocator.Current.GetInstance<UrlResolver>();

    urlResolver.GetVirtualPath(someContentReference here); <-- giving me a nice url like :/production/myitem/

    However, I dont have a contentreference for the result. Any suggestions ?

    #64446 Dec 20, 2012 15:38
  • Mats Knutsen-Valen
    Member since: 2010

    Solved it like this:

    string myUrl =  urlResolver.GetVirtualPath(contentSearchHandler.GetContent<PageData>(item).ContentLink)

    #64460 Dec 20, 2012 16:38