Copied to clipboard

Flag this post as spam?

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


  • pantryfight 60 posts 84 karma points
    May 13, 2016 @ 02:05
    pantryfight
    0

    Lucene picker syntax question

    Hi folks, I'm using a Lucene picker to select items of a specific document type. Using Lucene instead of XPath so that I can select from unpublished nodes as well as those in the publish cache.

    Just wondering if its possible with RawQuery to exclude the current node from the selection.

    IE. My Raw query is "+nodeTypeAlias:MyDocumentType"

    All of my nodes are of type "MyDocumentType", so I'd like to be able to populate my nuPickers list with all items of type "MyDocumentType" except for the node I'm currently editing.

    I was able to do it in an XPath picker with "//MyDocumentType[not(@id=$ancestorOrSelf/@id)]" Is this possible with lucene?

  • Veronica Burd 76 posts 201 karma points
    May 13, 2016 @ 07:26
    Veronica Burd
    2

    There is an enhancement ticket #103 from 2015 on the nuPicker github for this. However, I don't think its been implemented.

    Ver

  • pantryfight 60 posts 84 karma points
    May 14, 2016 @ 00:07
    pantryfight
    0

    Hmm if not with a Lucene picker then how about with a dotnet picker? Haven't looked into them yet but assuming I can use it to populate the list using ContentService. Can I work out what my current node is from there so I can exclude it?

  • pantryfight 60 posts 84 karma points
    May 14, 2016 @ 01:29
    pantryfight
    1

    Ok so answered my own question.. looks like the ContextID passed into DotNetDataSource is the current node ID. yay!

    public class MyDocumentTypeProvider : IDotNetDataSource
    {
        IEnumerable<KeyValuePair<string, string>> IDotNetDataSource.GetEditorDataItems(int contextId)
        {
            var cs = ApplicationContext.Current.Services.ContentService;
            var cts = ApplicationContext.Current.Services.ContentTypeService; 
            var myDocumentType = cts.GetContentType("MyDocumentType");
    
            if(myDocumentType != null)
            {
                var items = cs.GetContentOfContentType(myDocumentType.Id).Where(x => x.Id != contextId);
                if (items != null && items.Any()) {
                    foreach (var item in items)
                    {
                        yield return new KeyValuePair<string, string>(item.Id.ToString(), item.Name);
                    }
                }
            }
            yield break;
        }
    }
    
Please Sign in or register to post replies

Write your reply to:

Draft