Examine search - searching and returning documents that don't have a template.
Hi there,
I am trying to configure my search to only return pages that actually have a template. Here is the structure - the nodes with a single * at the beginning/end do not have a template so cannot be rendered, however if picked up in a search I'd like their parent page (with a double **) to be returned:
Home
Working for Us
Human Resources
FAQs: Employees
**Sickness Absence**
*Sickness Absence*
*Does the policy apply to me?*
*If I am unwell and unable what do I do?*
*Do I need to speak to my manager?*
**Annual Leave**
*Annual Leave*
*Do I need to book in advance*
*Does the policy apply to me?*
Finance
Staff Development
**FAQs:**
*Learning and Development*
*How much does it cost*
*What support can I access?*
*How do I obtain information on the course?*
My basic search of model.SearchResults = Umbraco.TypedSearch(query); is correctly finding the articles. The problem is that some of the articles don’t actually exists as pages, so I’d like the page returned in the result to be the parent of the result page (or, in some cases, the parent of the parent)
At present, I don’t want to exclude any doc types from my search, nor do I think using umbracoNaviHide will do the job as I don’t want to exclude any pages.
Is there a solution to what I am looking for here (e.g. Is there any way to check for something like Page.HasTemplate == false?) My C#/.Net skills are pretty good so I hopefully shouldn’t have any problem writing a detailed query in code if needs be, just finding it hard to work out the best way to achieve this in Umbraco. If it helps I can provide the full doc types of my structure above.
Another alternative is to actually give the pages without a template a template - but have the template perform a redirect to the parent page. That way when the template appears in the search when you click it you get the parent page.
It appears that the results of an Umbraco.TypedSearch (IPublishedContent) do indeed have a TemplateId property. If TemplateId == 0, then no template exists.
var themodel = new SearchModel { Query = query };
if (!string.IsNullOrEmpty(query))
{
themodel.SearchResults = Umbraco.TypedSearch(query);
if (themodel.SearchResults != null)
foreach (var result in themodel.SearchResults)
{
if (result.TemplateId > 0)
{
If no template exists, then get the parent node
else if (result.Parent.TemplateId > 0)
May not be the most elaborate solution, but seems to do the job for me.
Examine search - searching and returning documents that don't have a template.
Hi there, I am trying to configure my search to only return pages that actually have a template. Here is the structure - the nodes with a single * at the beginning/end do not have a template so cannot be rendered, however if picked up in a search I'd like their parent page (with a double **) to be returned:
My basic search of model.SearchResults = Umbraco.TypedSearch(query); is correctly finding the articles. The problem is that some of the articles don’t actually exists as pages, so I’d like the page returned in the result to be the parent of the result page (or, in some cases, the parent of the parent)
At present, I don’t want to exclude any doc types from my search, nor do I think using umbracoNaviHide will do the job as I don’t want to exclude any pages.
Is there a solution to what I am looking for here (e.g. Is there any way to check for something like Page.HasTemplate == false?) My C#/.Net skills are pretty good so I hopefully shouldn’t have any problem writing a detailed query in code if needs be, just finding it hard to work out the best way to achieve this in Umbraco. If it helps I can provide the full doc types of my structure above.
Thanks in advance
You can probably use the GatheringNodeData event to get the parent node and index that. See an example:
http://staheri.com/my-blog/2015/march/custom-examine-indexing-using-umbraco-cache/
Another alternative is to actually give the pages without a template a template - but have the template perform a redirect to the parent page. That way when the template appears in the search when you click it you get the parent page.
It appears that the results of an Umbraco.TypedSearch (IPublishedContent) do indeed have a TemplateId property. If TemplateId == 0, then no template exists.
If no template exists, then get the parent node
May not be the most elaborate solution, but seems to do the job for me.
is working on a reply...