Copied to clipboard

Flag this post as spam?

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


  • sun 403 posts 395 karma points
    Nov 23, 2012 @ 09:05
    sun
    0

    How to get Descendant nodes by Examine?

    I want to get descendant nodes of one node. It the node id is 5678, I think the path of its descendant nodes must include the id 5678, So I use query:

    path:5678

    If path only have 5678, it can return, This can tell us the setting is right. but the path is like -1,****,****,5678,****, So there is nothing returned.

    How to use Examine to get Descendant nodes?

    Please help me.

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Nov 23, 2012 @ 09:20
    Dirk De Grave
    0

    you can't query a node's path as it's comma separated and Examine treats this field as a single "word". you need to add an extra index field in which you store a space separated path, so -1 x y 5678 z instead of the standard -1,x,y,5678,z value.

    Here's a nice post which should get you started: http://our.umbraco.org/forum/developers/extending-umbraco/11667-GatheringNodeData-examine-event

    Hope this helps.

    /Dirk

     

     

     

     

  • sun 403 posts 395 karma points
    Nov 23, 2012 @ 09:24
    sun
    0

    I'd suggest that Examine should add one new analyzer to separate the value by comma/whitespace.

    Who can add this into Whitespace Analyzer?

  • sun 403 posts 395 karma points
    Nov 23, 2012 @ 11:37
    sun
    0

    I have found the way. But I'm not a developer, who can make a CommaAnalyzer for me?

    Thank you.

    http://web.archiveorange.com/archive/v/IfMhiGALwWU1qgDhH4Fy

    Take the comma out of: | <#P: ("_"|"-"|"/"|"."|",") > in the .jj file 

    (around line 92). Keep in mind that this will affect being able to find 

    tokens that where previously indexed with the comma there (obviously). I 

    believe the javacc target in the build file will rebuild...you need to 

    get javacc and put a prop file next to the build file called 

    build.properties that contains: javacc.home=c:/javacc (or wherever you 

    put javacc).

     

    Also, you could consider trying to pre-process the strings (replace the 

    comma with a space or something).

     

    - Mark

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Nov 23, 2012 @ 13:22
    Ismail Mayat
    0

    mark,

    try multiple wildcard query path:5678* in the examine code it would be query.MultipleCharacterWildcard() this is a string extension method to be found in Examine.LuceneEngine.SearchCriteria namespace it definately works. in the past i have used gatheringnodedata and stripped out the , however wilcard does work.

     

     

     

     

     

     

     

  • sun 403 posts 395 karma points
    Nov 23, 2012 @ 13:38
    sun
    0

    But if I have some nodes , their id: 5678,56781,56782,56783,56784,.......

    All above Id will be matched.

    I have searched that SimpleAnalyzer can use whitespace or punctuation to tokenize field. But after I set analyzer as Lucene.Net.Analysis.SimpleAnalyzer

    I found it useless.

  • sun 403 posts 395 karma points
    Nov 23, 2012 @ 14:20
    sun
    0

    SimpleAnalyzer will remove number, So it's useful. Now I think some one should modify it let it don't remove number, then it should OK.

  • Ismail Mayat 4511 posts 10091 karma points MVP 2x admin c-trib
    Nov 23, 2012 @ 14:56
    Ismail Mayat
    0

    No they won't. The query is saying where path contains a given parent. I am doing this currently where i need to get all children of a particular parent.

  • sun 403 posts 395 karma points
    Nov 23, 2012 @ 15:47
    sun
    0

    Now, I try to modify WhitespaceAnalyzer to NotNumberAnalyzer, I changed all Whitespace to NotNumber, then, I change the following line:

    return !System.Char.IsWhitespace(c);

    to:

    return System.Char.IsDigit(c);

    It seems that All I need to do is this. But it won't work. sadly.

  • Eric Schrepel 161 posts 226 karma points
    Dec 15, 2014 @ 21:26
    Eric Schrepel
    0

    (Update: added the @using and inherits statements up top)

    We have a 50-node set of documents that we wanted to limit search results to. Using Ismail's answer, we made the following code which works great. We included the full path up to the parent node we're searching (descendants of 20154) because it seemed we'd have to turn on "enableLeadingWildcards" in the examine.config or something and weren't sure how that'd affect performance. Plus we don't want leading wildcards allowed for most searches.

    Our code:

    @inherits Umbraco.Web.Mvc.UmbracoTemplatePage
    @using Examine
    @using Examine.LuceneEngine.SearchCriteria;
    @using Examine.SearchCriteria;
    @using UmbracoExamine;    
    @{
        var searchString = Request["search"];
        var programParent = "-1,1051,1064,14416,20154*";
    
        if (!String.IsNullOrEmpty(searchString))
        {
            var searchProvider = ExamineManager.Instance.DefaultSearchProvider.Name;
            var searcher = ExamineManager.Instance.SearchProviderCollection[searchProvider];
            var searchCriteria = searcher.CreateSearchCriteria(BooleanOperation.And);
    
            var query = searchCriteria.Field("path",programParent.MultipleCharacterWildcard()).And().GroupedOr(new string[] { "pageSubtitle", "pageContent" }, searchString).Compile();
    
            foreach (var c in searcher.Search(query))
            {
                <h4>
                    <a href="@umbraco.library.NiceUrl(c.Id)">@c.Fields["pageSubtitle"]</a>
                </h4>
                @* Display a bit of the page content *@
                var snippet = c.Fields["pageContent"];
                if (snippet.Length > 240)
                {
                    snippet = snippet.Substring(0, 240) + "...";
                }
                <p>@Html.Raw(snippet)</p>
    
            }
        }
    }
    
  • sun 403 posts 395 karma points
    Dec 16, 2014 @ 01:23
    sun
    0

    thanks

Please Sign in or register to post replies

Write your reply to:

Draft