Copied to clipboard

Flag this post as spam?

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


  • Mus'ab 157 posts 384 karma points notactivated
    Nov 05, 2019 @ 10:01
    Mus'ab
    0

    How to make Date Picker property indexing as date time instead of text?

    Hi I want to write an examine search that return files between tow dates come from property value so i tried to use range query here is my code :

     var searcher = indx.GetSearcher();
    ISearchResults results = null;
    results = searcher.CreateQuery()
    .Field("path", Umbraco.Media(124111).Path.MultipleCharacterWildcard()).And()
    .Field("__NodeTypeAlias", "File").And()
    .RangeQuery<DateTime>("fileDate".Split(','),Convert.ToDateTime("04/06/2017"),DateTime.Now)
    .Execute();
    

    but i faced this error :

    enter image description here

  • Nik 1512 posts 6680 karma points MVP 5x c-trib
    Nov 05, 2019 @ 10:04
    Nik
    100

    Hey Mus'ab,

    I did an article about this here:

    https://www.justnik.me/blog/indexing-sort-able-dates-in-umbraco-version-8

    Have a read of that and see if it helps. But basically you need to hook into start up and indexing events to manipulate the indexes.

    Nik

  • Thomas 157 posts 332 karma points
    Dec 15, 2020 @ 10:01
    Thomas
    0

    Hi Nik. I am facing the same issue. I follow yours instructions to create a custom index in order to do it as you mention and also to remove the time and keep only the date. The problem with that is that the index is not getting refreshed OnOublished or UnPublished event. Any suggestions with that? Because i don't want to ask the users every time the publish an article to rebuild the index manually.

  • Nik 1512 posts 6680 karma points MVP 5x c-trib
    Dec 15, 2020 @ 10:14
    Nik
    0

    Hi Thomas,

    Do you mean a custom index or a custom field on the External Index?

    If you mean a custom index, you need to make sure you register the Index Creator, the Index Populate, and the ValueSetBuilder as well.

    All parts work together to populate the index. If that's still not working to update the index, you might need to hook into Published and Unpublished events to trigger the correct update methods on your index.

    I've not done much with completely custom indexes so if that's where the issue lies a bit of investigation would be needed. Might be worth a dedicated question on here :-)

    Nik

  • Thomas 157 posts 332 karma points
    Dec 15, 2020 @ 10:19
    Thomas
    0

    To be more specific. I have a DateTime Picker on a DocumentType. Unfortunately ExternalIndex indexes the field as fulltext. That is not helpful at all because i cannot sort with this field and i cannot query for either a specific date or range of days. So i decided to follow yours very helpful article in order to create a custom index. Everything is fine and works as expected except the onPublish and OnUnpublish events. The index is not getting refreshed as the ExternalIndex. Also i don't want overload the events with rebuilding the index because of performance issues. Any suggestions on how to do that?

    I would like to mention that i was searching to send you an email yesterday for the same reason but unfortunately i couldn't find it, so thanks god i found you here, both articles for the custom index and for the default values were extremely helpful.

  • Nik 1512 posts 6680 karma points MVP 5x c-trib
    Dec 15, 2020 @ 10:30
    Nik
    0

    I'm available on Twitter (@hotchillicode) and on Slack if you want to share code so I can see what's going on. I've not had this issue with the code examples I've shared, they seem to update the indexes correctly so curious to see the difference as it seems a bit odd :-)

    The approach in the article uses the standard Umbraco examine events to update values etc so there is no reason it shouldn't work which seems a bit odd.

  • Mus'ab 157 posts 384 karma points notactivated
    Nov 06, 2019 @ 07:29
    Mus'ab
    0

    thx a million

Please Sign in or register to post replies

Write your reply to:

Draft