Page 1 of 1
Restrict search module to a specific hierarchy of pages
Posted: Wed Mar 26, 2014 6:16 pm
by essexboyracer
I am looking to have an "knowledgebase/FAQ" are on a site - something akin to ZenDesk (without the bells - just a list of categorised help articles).
That bit is fine as I can create the articles under a section header, and populate extra attributes to serve as "tags".
What I can't figure out is how to restrict the search module (or an instance of) to only search through content that is under the knowledgebase section header?
Re: Restrict search module to a specific hierarchy of pages
Posted: Thu Mar 27, 2014 8:00 am
by velden
I don't think you can limit the search to a specific hierarchy.
However, you can make all pages, except for the faq, unsearchable:
Page -> Options tab -> 'This page is searchable'
You can set it as a default for NEW pages: Site Admin -> Page Defaults
Or create a page TEMPLATE for all pages that should NOT be indexed. From Search help:
How do i prevent certain content from being indexed
The search module will not search any "inactive" pages. However on occasion, when you are using the CustomContent module, or other smarty logic to show different content to different groups of users, it may be advisiable to prevent the entire page from being indexed even when it is live. To do this include the following tag anywhere on the page <!-- pageAttribute: NotSearchable --> When the search module sees this tag in the page it will not index any content for that page.
The <!-- pageAttribute: NotSearchable --> tag can be placed in the template as well. if this is done, none of the pages attached to that template will be indexed. Those pages will be re-indexed if the tag is removed
Finally you could customize a search result template so it checks for every result entry if it's a 'faq' page. However, that would be the most inefficient way I guess. But it would make it possible to use Search for the 'faq' as well as for the complete website.
Note that there are modules too (e.g. 'faq' or ListItExtended aka LI2) that could be useful too for a knowledgebase setup. I know that LI2 content is indexed too by search module. In that case you could make a search result template that checks for every result entry whether it's from that specific LI2 module instance or not.
Re: Restrict search module to a specific hierarchy of pages
Posted: Thu Mar 27, 2014 9:10 am
by chandra
Think about the topic this night - maybe it is possible.
Here's my way in theory:
Search modules result page contains a URL. With this it should be possible to get the page alias. With the alias you can check the parent or the root.
Now you can add an if condition in result template. If the parent is the same how in a predefined value, there will be some output. Otherwise there's nothing.
The idea based on the functionality of CGSimpleSmarty module. Hope it make sense for you - can't check this idea by myself in moment.
Re: Restrict search module to a specific hierarchy of pages
Posted: Thu Mar 27, 2014 9:14 am
by chandra
Another way with a better performance could be to create a customised search action.
Re: Restrict search module to a specific hierarchy of pages
Posted: Thu Mar 27, 2014 9:18 am
by velden
chandra wrote:Another way with a better performance could be to create a customised search action.
Explain.
From Help:
(optional) modules="null" - Limit search results to values indexed from the specified (comma separated) list of modules
That would be the most efficient way I think; use e.g. ListitExtended for the knowledge base and limit search to that module.
Re: Restrict search module to a specific hierarchy of pages
Posted: Thu Mar 27, 2014 10:15 am
by uniqu3
velden wrote:
That would be the most efficient way I think; use e.g. ListitExtended for the knowledge base and limit search to that module.
Whereby ListItExtended instance has own search action and capability, therefore no need to use Search module for Knowledge base search, so core Search module can still be used for regular pages.
Re: Restrict search module to a specific hierarchy of pages
Posted: Thu Mar 27, 2014 11:32 am
by chandra
velden wrote:chandra wrote:Another way with a better performance could be to create a customised search action.
Explain.
Search modules result template puts out the title and the page url.
So it should be only a very small step to assign the page alias to Smarty too so it can be used for comparing I've described.
Re: Restrict search module to a specific hierarchy of pages
Posted: Fri May 16, 2014 7:55 pm
by essexboyracer
Its just not cutting the mustard really, is it, or I'm not invested enough.
Re: Restrict search module to a specific hierarchy of pages
Posted: Sat May 17, 2014 5:25 pm
by chandra
My idea isn't a real search limitation but a output filter.
To the first you should make a look here
http://www.i-do-this.com/snippets/Get-a ... age-URL/56
Stay secure CGSimpleSmarty is intalled and the udt from article does exist.
Insert now this search module result template
Code: Select all
<h3>{$searchresultsfor} "{$phrase}"</h3>
{if $itemcount > 0}
<div id="SearchResults">
{foreach from=$results item=entry}
{set_alias url=$entry->url assign='get_alias'}
{$cgsimple->get_root_alias($get_alias),'root_alias'}
{if $root_alias == 'knowledgebase'}
<p>{$entry->title} - <a href="{$entry->url}">{$entry->urltxt}</a> ({$entry->weight}%)</p>
{/if}
{/foreach}
</div>
<p>{$timetaken}: {$timetook}</p>
{else}
<p><strong>{$noresultsfound}</strong></p>
{/if}
Have fun

.