Today we’re releasing a first, early version of the Truffler integration for EPiServer CMS. This version contains the essential parts for automatically indexing PageData objects and querying them. There’s quite a lot of work remaining before we’re near as feature complete as we would like to be, but this version should contain the essentials for development.
We’ll be adding documentation and a lot more functionality over the coming days and weeks, but we wanted to get it out there as quickly as possible so that we could get some feedback. So, please create yourself a Truffler index if you haven’t already and try it out :)
Components
The integration, which is shipped along with the download package for the regular .NET API contains two assemblies, both of which should be referenced. Features included are:
- A singleton class named EPiSearchClient. This should be used when searching for EPiServer entities (currently PageData but in the future files in VPPs, Community entities etc). It will use the same configuration as the Client.CreateFromConfig method.
- A module that will handle automatic indexing of pages as they are published.
- A scheduled job for doing a full reindexing of the site.
- An extension method named GetPagesResult that can be used on search queries (example below). This method will retrieve only the PageReferences for matching pages and fetch the actual pages using the DataFactory.GetPages method. If PageTypeBuilder is used the returned pages will be returned as the correct type. This method will also cache the result with a dependency to EPiServer’s master cache key.
- An extension method named Match for filtering on PageReferences.
Querying pages
A simple example of searching for pages and retrieving the actual PageData objects can look like this:
var pages = EPiSearchClient.Instance.Search<NewsitemPageType>() .Filter(x => x.Author.Match("John")) .OrderByDescending(x => x.StartPublish) .GetPagesResult();
Note that with the above code the result will be actual PageData objects and that the query will be cached. The cache will be released if any page on the site is changed.
Searching
The above example, using GetPagesResult is suitable for querying scenarios where we’d otherwise had used FindPagesWithCriteria. We can of course also use the Select method to project matching pages to a different type, including highlights etc.
EPiSearchClient.Instance.Search<StartpagePageType>() .For("Truffler") .Select(x => new { x.PageName, x.LinkURL, Content = x.MainBody.AsHighlighted()}) .GetResult();
Naturally, no matter if we’re using the GetPagesResult method to get actual PageData objects or projecting to something else we can use cool features such as geo search and boosting, as well as facets.
Excluded and included fields
We exclude a number of properties (like IsReadOnly) when serializing PageData objects but also include a few extension methods, for instance the RolesWithAccess method which we can use to filter matched pages for read access rights for a certain group (in a rather crude way at the moment).
EPiSearchClient.Instance.Search<StandardPage>() .For("Possibly secret stuff") .Filter(x => x.RolesWithReadAccess().Match("Everyone")) .GetPagesResult();
Feedback, please?
Like I wrote above, please keep in mind that this is an early version and that we will be ever so grateful for any feedback that you give us! Of course much more information and documentation, as well as a NuGet package is coming.
We’re also interested in hearing from you what we should prioritize next. Currently two things that we see as important is indexing files in VPPs and re-indexing pages when their ACL changes.
PS. For updates about new posts, sites I find useful and the occasional rant you can follow me on Twitter. You are also most welcome to subscribe to the RSS-feed.
Similar articles
- Truffler update – dotting the i’s and crossing the t’s
- Building a search page for an EPiServer site using Truffler
- Introducing Truffler – Advanced search made easy
- New in EPiServer Find – Unified Search
- Highlighting should be easy too
- Cool new features in the Truffler .NET API
- Would you like some business logic with that search?
- Building a search page for an EPiServer site using Truffler - Part 2
My book
Want a structured way to learn EPiServer 7 development? Check out my book on Leanpub!
Comments
comments powered by Disqus