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.
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.
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.
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
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.
(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>
}
}
}
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.
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
I'd suggest that Examine should add one new analyzer to separate the value by comma/whitespace.
Who can add this into Whitespace Analyzer?
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
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.
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.
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.
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.
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.
(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:
thanks
is working on a reply...