Copied to clipboard

Flag this post as spam?

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


  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Mar 23, 2011 @ 16:08
    Morten Bock
    0

    Adding custom fields to Examine index

    Hi all.

    I am trying to set up Examine search on a multilingual site, and the approach I am taking is to add language details to the index, using the GatheringNodeData event. So what I have set up is this:

      <IndexSet SetName="MyIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/MyIndex/">
        <IndexAttributeFields>
          <add Name="id" />
          <add Name="nodeName" />
          <add Name="updateDate" />
          <add Name="path" />
          <add Name="nodeTypeAlias" />
          <add Name="parentID" />
        </IndexAttributeFields>
        <IndexUserFields>
          <add Name="title"/>
          <add Name="description"/>
          <add Name="bodytext"/>
        </IndexUserFields>
        <IncludeNodeTypes>
          <add Name="ContentPage"/>
        </IncludeNodeTypes>
        <ExcludeNodeTypes />
      </IndexSet>

    I have then created my handler to add my custom field:

    public class ContentSearchIndexerEvents : ApplicationBase
    {
    
        public ContentSearchIndexerEvents()
        {
            var indexer = ExamineManager.Instance.IndexProviderCollection["MyIndexer"];
            indexer.GatheringNodeData += GatheringNodeDataHandler;
        }
    
        void GatheringNodeDataHandler(object sender, IndexingNodeDataEventArgs e)
        {
            INode languageNode = GetLanguageForNode(siteprofileNode); //External method
            e.Fields.Add("searchableLanguage", languageNode.Name.ToLower());
        }
    }

    But when I do my search, added "searchableLanguage" field, does not show up in the Fields collection. Is there anything more I need to do here? I debugged through the code, and my event gets hit when I publish a node.

    Any hints appreciated.

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Mar 23, 2011 @ 18:02
    Ismail Mayat
    0

    Morten,

    The languageNode Name() that field alias needs to be in the indexuserfields for all the language versions easiest bet would be to leave Indeuserfields blank in the configuration so that all fields are indexed see if that fixes the problem.

    Regards

    Ismail

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Mar 23, 2011 @ 18:33
    Morten Bock
    0

    Just tried leaving it blank, but it seems to give me the same results as before. Not quite sure what the heck is going on.

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Mar 23, 2011 @ 18:34
    Ismail Mayat
    0

    what do you see when you view the index with luke is the field there?

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Mar 23, 2011 @ 18:38
    Morten Bock
    0

    Not familiar with Luke. Only seen it mentined a few places. Do I just point to a file (in that cas which one?)

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Mar 23, 2011 @ 18:50
    Ismail Mayat
    1

    You point it index directory and it will allow you to view and search it

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Mar 23, 2011 @ 19:17
    Morten Bock
    0

    Ok, now I got it opened with Luke, and it seems that the fields do exist, at least on the newly created docuements, but they do not show up when I loop the fields in Examine like this:

    foreach (KeyValuePair<string, string> keyValuePair in searchResult.Fields)
    {
        description += string.Format("[{0}:{1}]{2}", keyValuePair.Key, keyValuePair.Value, Environment.NewLine);
    }
    
    So this raises two new questions:
    1: Why are the fields not showing up in list of fields in the code? (And I cannot search them either).
    2: How do I force a re-index of all the existing nodes on my site that do not currently have the fields in the index? I tried a recursive publish, but that does not seem to be enough. A manual puplish on each document however does seem to solve it. But a bit annoying.

     

  • Morten Christensen 596 posts 2773 karma points admin hq c-trib
    Mar 24, 2011 @ 09:27
    Morten Christensen
    1

    Have you tried rebuilding the index using Ismail's examine admin tool?

    http://our.umbraco.org/projects/backoffice-extensions/examine-index-admin

    Its been a great help for me to do a rebuild without having to publish from Umbraco.

    With regards to the fields not showing up: Have you tried doing a search from Luke to see if you get any results there?

    - Morten

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Mar 24, 2011 @ 10:02
    Morten Bock
    0

    Didn't know the tool, but will use that for reindexing.

    I get 83 results if I do a search in luke like this: searchableSiteProfile:denmark

    But this code returns no results from examine:

    ISearchCriteria searchCriteria = ExamineManager.Instance.SearchProviderCollection["MySearcher"].CreateSearchCriteria();
    var query = searchCriteria.Field("searchableSiteProfile", searchTerm.Value);
    ISearchResults searchResults = ExamineManager.Instance.Search(query.Compile());
  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Mar 24, 2011 @ 10:06
    Ismail Mayat
    0

    Morten,

    In your configuration what analyser you using ?  Also in your code after the line

    ISearchResults searchResults = ExamineManager.Instance.Search(query.Compile());

    can you write searchCriteria.ToString() that will display the query examine is running then paste that query and luke and see what you get.

    Regards

    Ismail

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Mar 24, 2011 @ 10:31
    Morten Bock
    0

    Hi Ismail.

    Im using this:

    <add name="MySearcher" type="UmbracoExamine.UmbracoExamineSearcher, UmbracoExamine"
               analyzer="Lucene.Net.Analysis.Standard.StandardAnalyzer, Lucene.Net" />

    The ToString gives me this output: '{ SearchIndexType: , LuceneQuery: +searchableSiteProfile:denmark }'

    Pasting that query to Luke gives me 83 results, but in my code, searchResults.TotalItemCount is 0.

  • Morten Bock 1867 posts 2140 karma points MVP 2x admin c-trib
    Mar 24, 2011 @ 10:39
    Morten Bock
    0

    Facepalm moment!

    I was executing the serach against the default searcher instead of my own searcher. The last line should be:

    ISearchResults searchResults = ExamineManager.Instance.SearchProviderCollection["MySearcher"].Search(query.Compile());

    Thanks for all the help. Now I get the expected results!

Please Sign in or register to post replies

Write your reply to:

Draft