When indexing a field with Examine which is a MNTP (multi node tree picker) and saved as a CSV is there a way to detect this and then 1) strip the commas, and 2) convert the id to the name of the node instead.
Part 1 & 2 i can do. What i'm stuck on is detecting whether a field is of the type MNTP or not.
I'm using v4.11.1. On previous time's i've saved MNTP's as xml and you can look for the name MultiNodePicker in the xml but when saving as a csv there's nothing to look for. Now using Razor we're using CSV.
So i guess i'm asking is there an API somewhere where i can just get the datatype of a field? Might be cool to have it on DynamicNode like
var datatype = Current.GetProperty("service").DatatypeGuid;
I thought I'll add this, this is a part of my startup events class, just add this and it will make examine searching on __path and custom csv fields possible
Search on __luceneFriendlyAncestors to get ancestors or search for __luceneFriendlyArticleSection if you have a property called articleSection
I have also included one for the InternalMemberIndexSet.
You will need to create your own Index set which is using the Lucene.Net.Analysis.Standard.StandardAnalyzer
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Profile;
using umbraco.BusinessLogic;
using umbraco.cms.businesslogic.member;
using Umbraco.Core;
using Umbraco.Core.Logging;
using Umbraco.Core.Services;
using Umbraco.Core.Models;
using Umbraco.Core.Persistence;
using System.IO;
using System.Drawing;
using System.Web.Hosting;
using umbraco;
using System.Collections;
using System.Web.Routing;
using System.Web.Http;
using Examine.LuceneEngine;
using Examine.LuceneEngine.Providers;
using Examine;
public class RegisterStartupEvents : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
// add ancestor indexing
foreach (LuceneIndexer indexer in ExamineManager.Instance.IndexProviderCollection)
{
if (indexer.IndexSetName == "CustomIndexSet")
{
indexer.DocumentWriting += indexer_DocumentWriting;
}
if (indexer.IndexSetName == "InternalMemberIndexSet")
{
indexer.DocumentWriting += indexer_DocumentWritingMember;
}
}
}
protected void indexer_DocumentWriting(object sender, DocumentWritingEventArgs e)
{
var luceneDocument = e.Document;
var p = e.Fields["__Path"];
if (!String.IsNullOrEmpty(p))
{
var newVal = p.Replace(",", " ");
luceneDocument.Add(new Lucene.Net.Documents.Field("__luceneFriendlyAncestors", newVal, Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.ANALYZED));
}
try
{
var q = e.Fields["articleSection"];
if (!String.IsNullOrEmpty(q))
{
var newVal = q.Replace(",", " ");
luceneDocument.Add(new Lucene.Net.Documents.Field("__luceneFriendlyArticleSection", newVal, Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.ANALYZED));
}
}
catch (Exception ex)
{
// LogHelper.Error(GetType(), string.Format("Error adding index field for {0}", e.Fields["nodeName"]), ex);
}
}
protected void indexer_DocumentWritingMember(object sender, DocumentWritingEventArgs e)
{
try
{
var luceneDocument = e.Document;
var p = e.Fields["_contributorType"];
if (p != null)
{
var newVal = p.Replace(",", " ");
luceneDocument.Add(new Lucene.Net.Documents.Field("__luceneFriendlyContributorType", newVal, Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.ANALYZED));
}
}
catch (Exception ex)
{
// LogHelper.Error(GetType(), string.Format("Error adding index field for {0}", e.Fields["nodeName"]), ex);
}
}
}
I am having the same issue but do not know how to look up the node names from within my custom indexer class that derives from BaseUmbracoIndexer. I do not have access to ServiceContext.ContentService.GetById() to look them up.
Examine - indexing MNTP csv values
Hello,
When indexing a field with Examine which is a MNTP (multi node tree picker) and saved as a CSV is there a way to detect this and then 1) strip the commas, and 2) convert the id to the name of the node instead.
Part 1 & 2 i can do. What i'm stuck on is detecting whether a field is of the type MNTP or not.
I'm using v4.11.1. On previous time's i've saved MNTP's as xml and you can look for the name MultiNodePicker in the xml but when saving as a csv there's nothing to look for. Now using Razor we're using CSV.
So i guess i'm asking is there an API somewhere where i can just get the datatype of a field? Might be cool to have it on DynamicNode like
or something like that.
Or has anyone got any other ways of doing this?
Cheers.
Got this working now using the following.
Had to use an array of the MNTP aliases to compare to, not ideal, but is all good.
Hi Rory
I thought I'll add this, this is a part of my startup events class, just add this and it will make examine searching on __path and custom csv fields possible
Search on __luceneFriendlyAncestors to get ancestors or search for __luceneFriendlyArticleSection if you have a property called articleSection
I have also included one for the InternalMemberIndexSet.
You will need to create your own Index set which is using the Lucene.Net.Analysis.Standard.StandardAnalyzer
Please excuse the non relevant using statements
Thanks Peter Rizk
http://www.wiliam.com.au/wiliam-blog/searching-for-all-descendants-of-a-node-with-umbraco-6-and-examine
Rory (?),
I am having the same issue but do not know how to look up the node names from within my custom indexer class that derives from BaseUmbracoIndexer. I do not have access to ServiceContext.ContentService.GetById() to look them up.
Thoughts?
Regards, Alan
is working on a reply...