Copied to clipboard

Flag this post as spam?

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


  • Carlos Casalicchio 176 posts 736 karma points
    Feb 02, 2017 @ 17:44
    Carlos Casalicchio
    0

    Lucene PrefetchList Picker with Raw Query with multiple properties

    Is it possible to filter the Lucene PrefetchList Picker with multiple properties, such as found in the Lucene documentation?

    title:"The Right Way" AND text:go
    

    Reference: Lucene Keyword matching

    I'm trying to filter two properties but when I add the "AND" to the raw query, the Prefetch List disappears.

  • Dave Woestenborghs 3504 posts 12135 karma points MVP 9x admin c-trib
    Feb 04, 2017 @ 12:21
    Dave Woestenborghs
    1

    Hi Carlos,

    Can you post your exact query instead of the one copied from the Lucene docs.

    That makes it more easy to spot issues.

    Dave

  • Carlos Casalicchio 176 posts 736 karma points
    Feb 04, 2017 @ 20:39
    Carlos Casalicchio
    0

    Here's the raw query

    Thing_highlight_:1 AND umbracoNaviHide:0
    

    enter image description here

    My goal is to also add a verification for highlight date like this

    AND Thing_highlight_until_ > DateTime.Now
    

    But no point in going that far, until I get the first two working..

    I have also checked to make sure all nodes have Thing_highlight_ and umbracoNaviHide and yet as soon as I add umbracoNaviHide the whole List disappears.

    Does it have issues if I use underscore?

  • Ian 178 posts 752 karma points
    Feb 05, 2017 @ 00:49
    Ian
    1

    You may have already confirmed this but when you say you checked the node has umbracoNaviHide have you checked this property is being indexed. What results are returned if you use the same query in luke the utility for testing lucene? I think you could also test the query in the umbraco backoffice in the dashboard

  • Carlos Casalicchio 176 posts 736 karma points
    Feb 06, 2017 @ 20:12
    Carlos Casalicchio
    0

    Thanks @Ian , after trying Luke, I've noticed that saving and publishing wasn't actually recording the umbracoNaviHide Property. After setting umbracoNaviHide to 1 then back to 0, Luke picked it up. And, so did the Prefetch List.

    Now it showed up. enter image description here

    My issue now: Is it possible to filter by Date?

    Background: Articles and News (DocumentTypes) have an Expire Date (when it stops showing up as a new item), done with the Thing_highlight_until_ property.

    I need to have only the items that are still valid (not expired) to show up in the Prefetch List.

    Is that possible?

  • Ian 178 posts 752 karma points
    Feb 07, 2017 @ 08:55
    Ian
    0

    Yes i m sure you can.index dates though i would say the purpose of lucence is as a text search. I havent used umbraco since leaving my employer, so the best i can do is say have a look at this https://our.umbraco.org/forum/developers/extending-umbraco/28796-Examine-Searching-for-Events-that-fall-between-a-given-date.

    I would also say at this point is the lucene.picker really the best for you when the .net picker would allow you to write a very simple class with some linq in it to do your filtering on properties and dates

  • Carlos Casalicchio 176 posts 736 karma points
    Feb 07, 2017 @ 16:44
    Carlos Casalicchio
    101

    Ian,

    I have implemented the list using .NET. Thanks!

    In addition, since I haven't found much of code samples for DotNet Prefetch Lists, I'm posting my code here, maybe it will serve as a reference for someone else.

    using nuPickers.Shared.DotNetDataSource;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Umbraco.Web;
    using Umbraco.Web.Models;
    
    public class Home_Slider : IDotNetDataSource
    {
    
        UmbracoHelper helper = new UmbracoHelper(UmbracoContext.Current);
    
        IEnumerable<KeyValuePair<string, string>> IDotNetDataSource.GetEditorDataItems(int contextId)
        {
    
            List<KeyValuePair<string, string>> list = new List<KeyValuePair<string, string>>();
            DynamicPublishedContent node = helper.Content(contextId);
            var children = node.Descendants().ToList().Where(x => x.GetPropertyValue<int>("Thing_highlight_") == 1 && x.GetPropertyValue<int>("umbracoNaviHide") == 0 && x.GetPropertyValue<DateTime>("Thing_highlight_until_") > DateTime.Now);
    
            foreach (var child in children) list.Add(new KeyValuePair<string, string>(child.Id.ToString(), child.Name));
            return list;
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft