Umbraco V8 uses a brand new version of Examine - there isn't much information available on how this latest version of Examine works... the Examine wiki: https://github.com/Shazwazza/Examine/wiki - so information in the Umbraco documentation currently is only for V7.
However a lot of the concepts are the same, the main difference is how you get underway and how to configure Examine in Umbraco, and the names of some methods and events have changed.
Anyway. first things first, how do you get an ExamineManager? this can now be achieved via DI, so if you have an MVC Controller you can get an ExamineManager object via its constructor:
eg
using System.Web.Mvc;
using Umbraco.Web.Models;
using Umbraco8.Services;
using Umbraco.Core.Logging;
using Umbraco.Core.Services;
using Umbraco.Core.Models.Membership;
using Umbraco.Core.Composing;
using Examine;
namespace Umbraco8.Controllers
{
public class BlogPostController : Umbraco.Web.Mvc.RenderMvcController
{
private readonly IExamineManager _examineManager;
public BlogPostController(IExamineManager examineManager)
{
// and now we have an instance of an ExamineManager we can use in our controller actions...
_examineManager = examineManager;
}
given we have an ExamineManager how do we get our ExamineSearcher for a particular index?
Looking at the source of Umbraco which also uses Examine here and there, we can use a TryGetIndex method like so:
public override ActionResult Index(ContentModel model)
{
var examineSearcher = _examineManager.TryGetIndex("ExternalIndex", out var externalIndex) ? externalIndex.GetSearcher() : null;
}
That should get us a searcher for the ExternalIndex!
Now we're starting to get on more familiar territory, as we can fluid-ily create our examine search criteria:
public override ActionResult Index(ContentModel model)
{
var examineSearcher = _examineManager.TryGetIndex("ExternalIndex", out var externalIndex) ? externalIndex.GetSearcher() : null;
//restrict teh search to the Content section, create our search criteria object
var criteria = examineSearcher.CreateQuery("content");
// build up our search filter in the same way as in V7/early examine:
var filter = criteria.Field("bodyText", "Fish");
Once we have our criteria ready to search, there is I think a further change, we now call Execute() instead of Search():
public override ActionResult Index(ContentModel model)
{
var examineSearcher = _examineManager.TryGetIndex("ExternalIndex", out var externalIndex) ? externalIndex.GetSearcher() : null;
var criteria = examineSearcher.CreateQuery("content");
var filter = criteria.Field("bodyText", "Fish");
// call Execute() to get matching search results
ISearchResults results = filter.Execute();
foreach (var result in results)
{
var id = result.Id;
var name = result.Values.TryGetValue("nodeName", out string nodeName) ? nodeName : "no name!";
}
Anyway hope that gets you going, there are lots of little subtle changes to how you do things, it's helpful to look at Examine queries in Umbraco source to see how they are executed there with the new Examine, or if you know what something was called before eg GatheringNodes Event, you can find it in an old 'dev' branch of Examine:
and then compare that file to see what has changed in the Examine 1.0 release branch, and then make a guess as to what things have been changed to... eg GatheringNodeEvent appears now to be TransformingIndexValues event
Unable to access searchers by their name in Umbraco 8 using Fluent API
Unable to call the method to fetch a particular searcher using the following method in Umbraco 8:
var externalSearcher = ExamineManager.Instance.SearchProviderCollection["ExternalSearcher"];
It says 'IExamineManager' does not contain a definition for 'SearchProviderCollection' Examine version: 1.0.0.0
Umbraco documentation: Link
Hi Vidyesh
Umbraco V8 uses a brand new version of Examine - there isn't much information available on how this latest version of Examine works... the Examine wiki: https://github.com/Shazwazza/Examine/wiki - so information in the Umbraco documentation currently is only for V7.
However a lot of the concepts are the same, the main difference is how you get underway and how to configure Examine in Umbraco, and the names of some methods and events have changed.
Anyway. first things first, how do you get an ExamineManager? this can now be achieved via DI, so if you have an MVC Controller you can get an ExamineManager object via its constructor:
eg
given we have an ExamineManager how do we get our ExamineSearcher for a particular index?
Looking at the source of Umbraco which also uses Examine here and there, we can use a TryGetIndex method like so:
That should get us a searcher for the ExternalIndex!
Now we're starting to get on more familiar territory, as we can fluid-ily create our examine search criteria:
Once we have our criteria ready to search, there is I think a further change, we now call Execute() instead of Search():
Anyway hope that gets you going, there are lots of little subtle changes to how you do things, it's helpful to look at Examine queries in Umbraco source to see how they are executed there with the new Examine, or if you know what something was called before eg GatheringNodes Event, you can find it in an old 'dev' branch of Examine:
https://github.com/Shazwazza/Examine/tree/dev
and then compare that file to see what has changed in the Examine 1.0 release branch, and then make a guess as to what things have been changed to... eg GatheringNodeEvent appears now to be TransformingIndexValues event
regards Marc
This works like a charm :)
Examine team is also still working on the documentation of their latest version (1.0.1)
Thanks a lot for the detailed explanation Marc. This helped a lot !
cool Vidyesh, and also, as if by magic...
there is now V8 Examine documentation appearing: https://our.umbraco.com/Documentation/Reference/Searching/Examine/quick-start/
Finally !! :)
is working on a reply...