Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • kukuwka 75 posts 96 karma points
    Mar 24, 2011 @ 09:50
    kukuwka
    0

    Adding IndexUserFields to index without GatheringNodeData

    Hi,

    How can I add custom fields to index without the use of GatheringNodeData.

    Is there another way?

    Thanks,

    kukuwka

  • Rich Green 2246 posts 4008 karma points
    Mar 24, 2011 @ 09:56
    Rich Green
    0

    Hi Kukuwka,

    Yes, you can define which fields get indexed using your ExamineIndex.config file

    For example:

      <IndexAttributeFields>
                   
    <add Name="id" />
                   
    <add Name="nodeName" />
                   
    <add Name="nodeTypeAlias" />
           
    </IndexAttributeFields>
           
    <IndexUserFields>
                   
    <add Name="metaTitle" />
                   
    <add Name="metaDescription" />
                   
    <add Name="metaKeywords" />
                   
    <add Name="metaTags" />
           
    </IndexUserFields>

    Rich

  • kukuwka 75 posts 96 karma points
    Mar 24, 2011 @ 10:21
    kukuwka
    0

    Hi,

    Thank you for quick reply.

    How can I add "Published" property to index?

  • DetonatorB 17 posts 40 karma points
    Jan 11, 2013 @ 22:17
    DetonatorB
    0

    Lookin' for the same thing under 4.11.1

    In the GatheringNodeData event, we cannot get the proper document.published value yet if we are currently publishing the document. Aparrantly, that value has not been set yet.
    The database hasn't been updated yet, so reading the db is no option.
    The UmbracoContext is null because we are on another thread (indexing thread) so that's no go.

    You can reproduce this behavior by adding a new document and publishing it for the first time.
    In both the GatheringNodeData event and the DocumentWriting event the document's 'published' property is false.

    Any ideas as to get 'published' in Examine/Lucene properly?

    I want to be able to decide to search for published/unpublished documents by raw query, like I could in the days before Examine.

    TIA

  • DetonatorB 17 posts 40 karma points
    Jan 12, 2013 @ 14:17
    DetonatorB
    0

    Oh my lord.

    After quite some hours (well, days actually) of research I now know more of the innards of umbraco and examine than I cared for.
    Anyway, although inefficient, I believe a solution is to reindex the node after publishing.
    I am using umbraco 4.11.1

    Goal

    Get the "Published" state into examine/lucene to be able to selectively search published and/or unpublished documents.
    (So the examine setting in the .config file will not do)

    Oh and I hate modding the umbraco core or examine core.
    And so should you.

    Problem

    The straight forward solution will not work:
    Hook into the GatheringNodeData or DocumentWriting event and add a custom field like so:

    doc.Add(new Field("published", d.Published, Field.Store.YES, Field.Index.ANALYZED));

    However, that does not work for the first time a document is published.
    (Replicate this problem: Create a document, publish it and after the first publish, published is still false (use LUKE to check))

    The problem is, that examine hooks to umbraco at the Document_save event for indexing.
    But at that time, the document hasn't officially been published yet (it's saved first, then published).
    So, the Publish property of the document is still false when it is being indexed and when the GatheringNodeData and DocumentWriting events are raised.
    And there is- AFAIK - no way to determine if we are publishing or just saving in those events. We cannot even hack and probe the HttpContext or control tree to figure that out.
    So - reindex after publish did the trick for me:

    Solution

    1) Add the custom field as described above.

    2) additionally, hook into the umbraco event system and re-index:

    public class DocumentEventHandler : ApplicationBase
        {

         public void Document_AfterPublish(Document sender, PublishEventArgs e)
            {
                var contentIndexer = ExamineManager.Instance.IndexProviderCollection[MyIndexerName] as UmbracoContentIndexer;
                contentIndexer.ReIndexNode(sender.ToXDocument(false).Root, IndexTypes.Content);
            }

    }

    and:

    * Change MyIndexerName to the name of your indexer (as a string)
    * You may have to add references to Examine.dll and UmbracoExamine.dll and add some namespaces:

    using Examine;
    using UmbracoExamine;

     

    HTH anyone

Please Sign in or register to post replies

Write your reply to:

Draft