Copied to clipboard

Flag this post as spam?

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


  • Kristoffer Eriksen 185 posts 465 karma points
    Nov 16, 2011 @ 20:26
    Kristoffer Eriksen
    1

    Examine range createDate

    Hey Umbraco People

    I've been struggling with some range-search on createDate.

    <!-- Imagebank Indexset -->
      <IndexSet SetName="ImagebankIndexSet" IndexPath="~/App_Data/TEMP/ExamineIndexes/Imagebank/" IndexParentId="1817">
        <IndexAttributeFields>
          <add Name="id" />
          <add Name="nodeName"/>
          <add Name="nodeTypeAlias" />
          <add Name="createDate"/>
        </IndexAttributeFields>
        <IndexUserFields>
          <add Name="productName"/>
          <add Name="mediaDescription"/>
          <add Name="produktType"/>
          <add Name="mediaSupplier"/>
          <add Name="mediaType"/>
          <add Name="mediaWidth"/>
          <add Name="mediaHeigth"/>
        </IndexUserFields>
        <IncludeNodeTypes>
          <add Name="image_imagebank" />
        </IncludeNodeTypes>
        <ExcludeNodeTypes />
      </IndexSet>

    And with this search

    ISearchCriteria query = searchCriteria
                        .Range("createDate", fromDate, toDate)
                        .Compile();

    Where fromDate and toDate is two DateTime values.

    It loos like the date is indexed, and it is probaly "just" some formatting issues.

    But I'm nt sure how to fix it

     

     

     

  • Kristoffer Eriksen 185 posts 465 karma points
    Nov 17, 2011 @ 13:49
    Kristoffer Eriksen
    0

    Couldn't figure it out, and since I'm returning a list of node, I just do a LINQ search before returning the list.

    result = from nodes in
                             from searchResult in searchResults
                             orderby searchResult.Score descending
                             select new Node(searchResult.Id)
                         where nodes.CreateDate.Date >= fromDate.Date
                         where nodes.CreateDate.Date <= toDate.Date
                         select nodes;
  • Kristoffer Eriksen 185 posts 465 karma points
    Nov 17, 2011 @ 16:44
    Kristoffer Eriksen
    0

    A former collegue of mine, just pointed out the obvious fail, in my above date-filtering.

    When the imagelibrary reaches a couple of thousands entrys, which it will, i might have to run the LINQ filtering an a couple of hundred nodes.

    It would be much faster, if I could do the filtering in the searchquery instead. Whichs bring me back to my original question.

     

    Anyone with a helping hand ?

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Nov 17, 2011 @ 16:56
    Ismail Mayat
    2

    kristofer,

    I have had this issue before the range method when translated to a lucene query converts the format of your date to 20111117122022 the date stored in lucene is in as 2011-11-17T12:20:22 so what I have done is implemented gatheringnode method and inject date in to new field in same format and then queried on that field works a treat.

    Regards

    Ismail

  • Kristoffer Eriksen 185 posts 465 karma points
    Nov 18, 2011 @ 08:44
    Kristoffer Eriksen
    0

    Oh darn...

    { SearchIndexType: , LuceneQuery: __NodeTypeAlias:image_imagebank createDate:[20111102000000000 TO 20111112000000000] }

    So your suggestion is that I implement gatheringnode method, and inject a date into a new field ind the below format 

    20111102000000000 

    And then I do my range on that field, instead of the createDate standard field.

     

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Nov 18, 2011 @ 09:34
    Ismail Mayat
    0

    Kristoffer,

    Exactly!

    Regards

     

    Ismail

  • Kristoffer Eriksen 185 posts 465 karma points
    Nov 18, 2011 @ 10:38
    Kristoffer Eriksen
    2

    Since my createDate is ONLY used for this search, I've just edited the createDate content, before inserting it

    using System;
    using Examine;
    using Examine.Providers;
    using umbraco.BusinessLogic;

    namespace Project.Events
    {
        public class ExamineEvents : ApplicationBase
        {
            public ExamineEvents()
            {
                BaseIndexProvider indexer = ExamineManager.Instance.IndexProviderCollection["ImagebankIndexer"];
                indexer.GatheringNodeData += indexer_GatheringNodeData;
            }

            private void indexer_GatheringNodeData(object sender, IndexingNodeDataEventArgs e)
            {
                e.Fields["createDate"] = DateTime.Parse(e.Fields["createDate"]).ToString("yyyyMMdd000000000");
            }
        }
    }

     

    Works like a charm

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Nov 18, 2011 @ 10:45
    Ismail Mayat
    0

    Kristoffer,

    Only issue you will have is if you need to display the create date on front end in your search results eg you want to display date dd/MM/yyyy if you try to parse that date you will get incorrect date becuase the format does not have - or / or : to separate out the different elements. However if you dont want to display the create date then its all good.

    Regards

    Ismail

     

  • Kristoffer Eriksen 185 posts 465 karma points
    Nov 18, 2011 @ 10:58
    Kristoffer Eriksen
    0

    I've thought of that, but all I use the createDate for, in this solution, is in the searchfiltering.

    So for the time being, it works as it should.... And I've gained alot more knowledgee.... win-win :-)

  • Dirk Seefeld 126 posts 665 karma points
    Jan 27, 2012 @ 13:06
    Dirk Seefeld
    1

    By the way - if someone needs hours and minutes the dateformat has to be: "yyyyMMddHHmm00000"

    KR
    Dirk

Please Sign in or register to post replies

Write your reply to:

Draft