Copied to clipboard

Flag this post as spam?

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


  • Murray Roke 503 posts 966 karma points c-trib
    Feb 03, 2011 @ 03:54
    Murray Roke
    0

    Search non tokenized fields using Examine

    Hi

    I'm picking up someone else's work on a relatively simple Examine implementation where we need to index & search the creatorName field (along with nodeName & bodyText).

    Searching on the 'creatorName' is not working...

    I've used luke to examine the index and it appears the field is populated correctly, however the creatorName field has these flags: I-SV------- wich differs from teh bodyText field which has these flags: ITSV-------

    This shows that bodyCopy is 'tokenised' and creatorName is not.

    Could this be why searches for keywords located in the 'creatorName' field do not work?

    If this is the case, how do I 'tokenize' this field?

    BTW: Here's the relevant bit of code that does the search:

     var criteria = ExamineManager.Instance.SearchProviderCollection["BlogSearcher"].CreateSearchCriteria(IndexTypes.Content);
    var filter = criteria.GroupedOr(new String[] { "nodeName""bodyText""creatorName" }, searchTerm.ToLower())
    .Not().Field("umbracoNaviHide""1").Compile();
    var SearchResults = ExamineManager.Instance.SearchProviderCollection["BlogSearcher"].Search(filter);

    Cheers.

    Murray.

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Feb 03, 2011 @ 10:10
    Ismail Mayat
    1

    Murray,

    You need to implement gatheringnode method and then inject in new field which will store creator data tokenised then it will be searchable see http://our.umbraco.org/forum/using/ui-questions/16888-Examine-Search-Range-Values i have posted some code on how i use gatheringnode method to allow range searching but the principle is the same you need to inject in the creator field as tokensied then search on that.

    Regards

    Ismail

  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Feb 03, 2011 @ 23:48
    Shannon Deminick
    1

    From memory creatorName is set as a'special' field in Examine which is probably not stored tokenized. Ismail is correct, you can either use the gathering node data event or the DocumentWriting event of the LuceneIndexer object.

    Using the DocumentWriting event gives you far more control about what and how Examine puts data into Lucene. Also DocumentWriting event allows you to add additional fields to the Lucene index that aren't defined in your Examine config whereas even if you add additional fields in the GatheringNodeData event and they are not defined in your config, the data will not go in the index.

    Here's an example of using this event and storing new (un-configured fields):

    http://www.farmcode.org/post/2010/08/23/Text-casing-and-Examine.aspx

     

  • Murray Roke 503 posts 966 karma points c-trib
    Feb 04, 2011 @ 02:48
    Murray Roke
    0

    Awesome, I have it working now, thanks guys.

    It appears the version I have does not have DocumentWriting (or I forgot the cast), so I used GatheringNodeData

    Gotchas:

    • remember to add the field as Shannon  mentions... in my example: add "searchableCreatorName" under IndexUserFields in the ExamineIndex.config
    • make sure you ahve th correct 'magic string' in the IndexProviderCollection["BlogIndexer"], I had a typo and took a while to find.

    Hre's my code

        public class BlogApplicationBase : ApplicationBase
    {

    public BlogApplicationBase()
    {
    //Add event handler for 'GatheringNodeData' 
    ExamineManager.Instance.IndexProviderCollection["BlogIndexer"].GatheringNodeData += ExamineEvents_GatheringNodeData;
    }

    /// 
    /// Event handler for GatheringNodeIndex.
    /// This will fire everytime Examine is creating/updating an index for an item
    /// 
    /// "sender">
    /// "e">
    void ExamineEvents_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
    {
    //check if this is 'Content' (as opposed to media, etc...)
    if (e.IndexType == IndexTypes.Content)
    {
    if (e.Node.UmbNodeTypeAlias() == "BlogPost" && e.Node.Attribute("creatorName") != null)
    {
    e.Fields.Add("searchableCreatorName", e.Node.Attribute("creatorName").Value);
    }
    }
    }
    }
  • Shannon Deminick 1526 posts 5272 karma points MVP 3x
    Feb 04, 2011 @ 04:19
    Shannon Deminick
    0

    I HIGHLY recommend upgrading to the latest version of Examine. It has a TON of bug fixes and better extensibility points:

    http://examine.codeplex.com/releases/view/50781

    You are using a beta version of Examine, the RTM is released with Umbraco 4.6

     

  • Hendy Racher 863 posts 3849 karma points MVP 2x admin c-trib
    Feb 04, 2011 @ 18:50
    Hendy Racher
    0

    Hi,

    I've noticed that when adding new fields to the index dynamically (and they've not been added to the IndexUserFields section of ExamineIndex.config) I can see them via LUKE, doesn't this imply that they've been successfully added to the index, or am I missing something ? (using the version of Examine built into Umbraco 4.5.2).

    TIA,

    Hendy

Please Sign in or register to post replies

Write your reply to:

Draft