Copied to clipboard

Flag this post as spam?

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


  • Robert J. Bullock 386 posts 405 karma points
    Apr 23, 2015 @ 22:40
    Robert J. Bullock
    0

    Custom Examine Indexer: Add Field As Date?

    Ok, I have a custom indexer built and it works but the data (from Archetype) is stored as text. How can I specify that the field should be type of date? I don't see anywhere to specify the type when adding a field:

    nodeData.Fields.Add(string.Format("archetype-{0}-{1}", fieldset.Alias, index), value);

  • TikTakToe 60 posts 102 karma points
    Apr 23, 2015 @ 22:51
    TikTakToe
    0

    hi

    not sure if i understand what you're asking, but if i'm storing dates in the index, i found you have to store them in lucene friendly fashion eg 20150315, then you can run lucene queries like so

    (lucenceFriendlyCreatedDate:[20150315 TO 20150316]) 
    

    and in my node gathering event, i just add them like:

    e.Fields.Add("lucenceFriendlyCreatedDate", currentItem.CreateDate.ToString("yyyyMMdd"));
    

    Hope that helps!

    cheers

    ian

  • Pawel Bres 39 posts 160 karma points c-trib
    Apr 24, 2015 @ 09:28
    Pawel Bres
    0

    Hi Robert, you could also try to set the type of the field in ExamineIndex.config:

    <IndexSet SetName="YourIndexSetName" IndexPath="~/App_Data/TEMP/ExamineIndexes/YourIndex/">
        <IndexUserFields>
          ...
          <add Name="yourDateField" Type="DATETIME"/>
        </IndexUserFields>
    </IndexSet>
    

    Cheers!

  • Robert J. Bullock 386 posts 405 karma points
    Apr 24, 2015 @ 16:30
    Robert J. Bullock
    0

    Thanks, Pawel. That's good to know but it wouldn't work in this case as the field names are dynamic/variable.

  • Pawel Bres 39 posts 160 karma points c-trib
    Apr 24, 2015 @ 16:52
    Pawel Bres
    0

    So I think best option is to keep same formating when injecting and searching dates. When format is the same, with same number of characters, it is just about string comparing during search so there is no need to set specific type of indexed field,

    e.g. I'm using formating string like this:

    yyyy-MM-ddTHH:mm:ss
    

    and I think it is the default format returned by Date Picker with Time property editor

Please Sign in or register to post replies

Write your reply to:

Draft