我目前正在使用UmbracoExamine来满足我的项目的所有搜索需求,并且我正在试图弄清楚查询参数".ParentId“到底做了什么。
我希望能用它来查找parentID中的所有子节点,但我似乎无法让它工作。
基本上,如果搜索字符串包含的是。"C#编程“,它应该找到所有该类别的文章。这只是一个例子。
提前谢谢你!
发布于 2016-03-21 14:34:11
当你说它应该找到所有“那个类别的”文章时,我假设你有一个类似于下面的结构?
-- Programming
----Begin Java Programming
----Java Installation on Linux
----Basics of C# Programming
----What is SDLC
----Advanced C# Programming
-- Sports
----Baseball basics如果是这样,那么我也假设您希望列出"programming“下的所有文章,而不仅仅是那些包含"C#编程”的文章?
您需要做的是从查询中循环遍历SearchResults,然后从那里找到父节点。
IPublishedContent node = new UmbracoHelper(UmbracoContext.Current).TypedContent(item.Fields["id"].ToString());
IPublishedContent parentNode = node.Parent;一旦您有了父节点,您就可以获得所有的子节点以及一些子节点,这取决于文档类型和您想要做的事情
IEnumerable<IPublishedContent> allChildren = parentNode.Children;
IEnumerable<IPublishedContent> specificChildren = parentNode.Children.Where(x => x.DocumentTypeAlias.Equals("aliasOfSomeDocType"));下面的示例代码
//Fetching what eva searchterm some bloke is throwin' our way
string q = Request.QueryString["search"].Trim();
//Fetching our SearchProvider by giving it the name of our searchprovider
Examine.Providers.BaseSearchProvider Searcher = Examine.ExamineManager.Instance.SearchProviderCollection["SiteSearchSearcher"];
// control what fields are used for searching and the relevance
var searchCriteria = Searcher.CreateSearchCriteria(Examine.SearchCriteria.BooleanOperation.Or);
var query = searchCriteria.GroupedOr(new string[] { "nodeName", "introductionTitle", "paragraphOne", "leftContent", "..."}, q.Fuzzy()).Compile();
//Searching and ordering the result by score, and we only want to get the results that has a minimum of 0.05(scale is up to 1.)
IEnumerable<SearchResult> searchResults = Searcher.Search(query).OrderByDescending(x => x.Score).TakeWhile(x => x.Score > 0.05f);
//Printing the results
foreach (SearchResult item in searchResults)
{
//get the parent node
IPublishedContent node = new UmbracoHelper(UmbracoContext.Current).TypedContent(item.Fields["id"].ToString());
IPublishedContent parentNode = node.Parent;
//if you wish to check for a particular document type you can include this
if (item.Fields["nodeTypeAlias"] == "SubPage")
{
}
}https://stackoverflow.com/questions/36125107
复制相似问题