0

I have a Visual Studio project with 2 solutions: Solution 1: UmbracoCms (Umbraco 7.2 code base) Solution 2: SeachIndexer (lucene.net spatial - Windows Console Application)

In my solution 2 I have reference to the following .dlls from the Umbraco solution:

  • UmbracoCms.dll
  • cms.dll
  • businesslogic.ddl
  • umbraco.dll
  • umbraco.DataLayer.dll

In the Program.cs file I have the following code:

Node rootNode = new Node(1103);
string nodeTypeAlias = "articlePage";

if (node.NodeTypeAlias == nodeTypeAlias)
    listNode.Add(node);

foreach (Node childNode in node.Children)
{
    GetDescendantOrSelfNodeList(childNode, nodeTypeAlias);
}

//some other code

When I run the code I get the following error:

could not load the umbraco.core.configuration.umbracosettings.iumbracosettingssection from config file

What I'm trying to do is index Umbraco pages using Lucene.net spatial (Examine does not support spatial) in a seperate solution keeping the Umbraco base code clean. I want to able to schedule the SearchIndexer at 15 mins interval.

What's best way to go about this?

Jan Bluemink
  • 3,467
  • 1
  • 21
  • 35
Huzzi
  • 561
  • 2
  • 7
  • 21
  • You could perform the processing within the Umbraco website environment by hooking into the service events - that way you don't need to worry about whether the configuration is set correctly, or run it in an external console application etc. - see my answer below for details – Robert Foster Oct 01 '15 at 12:11

2 Answers2

1

You got that kind of error because Umbraco does not see its configurations.

you could have two solutions:

Umbraco Console: it means to recreate the Umbraco environment in a console application. You could see/use this project (e.g.). As you can see, in the App.config has been recreated all the configurations necessary for Umbraco. I've never used it before (it was my first google result), but it seems a good starting point.

Direct access to Umbraco DB: if you don't need to use the Umbraco API extensively, probably it's better to look for your content directly in the Umbraco DB. Obviously you have to explore the Umbraco DB to understand what to look for, and it could be time-comsuming if you don't know Umbraco

wilver
  • 2,106
  • 1
  • 19
  • 26
  • How? sorry, I'm new to Umbraco. I would like to implement this tutorial for Umbraco pages of certain document type. https://www.leapinggorilla.com/Blog/Read/1010/spatial-search-in-lucenenet---worked-example – Huzzi May 03 '15 at 23:47
  • I would not recommend trying to access the Umbraco database directly - the meta data for a content node is complex to query, and on top of that every time a content node is saved a new version of everything is added to the database tables. Better to let Umbraco translate the data for you into it's models. – Robert Foster Oct 01 '15 at 12:14
1

Instead of using a console project and scheduling it to run every 15 minutes, you could take advantage of Umbraco's Content event handling and index the node every time it's published. This way your index is refreshed straight away, and you don't have to worry about external scheduling etc.

Here's how:

  1. Create a new solution (I normally use an empty Web Project but you can just create a Library project) and install the UmbracoCms.Core nuget package corresponding to your UmbracoCms version (it will install all the necessary dependencies for you including Examine).
  2. Add the Luncene.Net packages as per the tutorial
  3. Add a class deriving from Umbraco.Core.ApplicationEventHandler and override ApplicationStarted - this will give you access to the Umbraco Services as well as the Examine Indexing events - you can use either for this exercise - you may find the Examine Events more suitable.
  4. In your Umbraco project add a reference to your new project so it get's pulled in.

Your EventHandler class may look something like this:

public class SpacialIndexingEventHandler : ApplicationEventHandler
{
    protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    {
        Umbraco.Core.Services.ContentService.Publishing += ContentService_Publishing;
    }

    private void ContentService_Publishing(Umbraco.Core.Publishing.IPublishingStrategy sender, Umbraco.Core.Events.PublishEventArgs<IContent> e)
    {
        // For each published node, perform the necessary indexing.
        string nodeTypeAlias = "ArticlePage";
        foreach (var node in e.PublishedEntities.Where(a => a.ContentType.Alias == nodeTypeAlias))
        {
            // Index this

        }
    }
}

If you wanted to do the indexing whenever Umbraco's indexing triggers, use this instead:

public class SpacialDataIndexingEventHandler : ApplicationEventHandler
{
    protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
    {
        // connect to the GatheringNodeData event of the provider you're interested in:
        foreach(var provider in ExamineManager.Instance.IndexProviderCollection.AsEnumerable<BaseIndexProvider>()) {
            if (provider.Name.StartsWith("External")) {
                provider.GatheringNodeData += provider_GatheringNodeData;
                break;
            }
        }
    }

    void provider_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
    {
        if (e.IndexType == IndexTypes.Content)
        {
            // Get the Node from the ContentService:
            var node = ApplicationContext.Current.Services.ContentService.GetById(e.NodeId);
            // Do your spacial indexing here;
        }
    }
}
Robert Foster
  • 2,317
  • 18
  • 28