Adding a search page

This uses the integrated WebHare search engine called ‘Consilio’.

Create the folder pages/search/.

Add to this folder the file search.siteprl.xml with the following content:

<siteprofile xmlns="http://www.webhare.net/xmlns/publisher/siteprofile">
<filetype namespace="http://examplesite.webhare.com/xmlns/types/searchpage" kind="virtualfile" title="Search page">
<dynamicexecution webpageobjectname="search.whlib#SearchPage" />
<robots xmlns="http://www.webhare.net/xmlns/consilio" noindex="true" nofollow="true"/>
</filetype>

<!-- Consilio catalog, name MUST start with <modulename>:
Change for your own site the folder attribute in the contentsource (site::<your-site-name>)
-->
<index xmlns="http://www.webhare.net/xmlns/consilio" name="examples:examplesite">
<contentsource type="publisher:webhare" folder="site::example-site" />
</index>
</siteprofile>

Add file search.whlib to the folder with the following content:

<?wh
LOADLIB "wh::witty.whlib";
LOADLIB "mod::consilio/lib/api.whlib";
LOADLIB "mod::publisher/lib/webdesign.whlib";
LOADLIB "mod::system/lib/webserver.whlib";

PUBLIC OBJECTTYPE SearchPage EXTEND DynamicPageBase
<
UPDATE PUBLIC MACRO PrepareForRendering(OBJECT webcontext)
{
INSERT "searchpage" INTO webcontext->htmlclasses AT END;
}

UPDATE PUBLIC MACRO RunBody(OBJECT webcontext)
{
STRING words := GetWebVariable("words");
RECORD results := RunConsilioSearch("modulename:websitename", CQParseUserQuery(words), [ summary_length := 150 ]);

EmbedWittyComponent( this->pagefolder || "search.witty:search", CELL[...results, words] );
}

>;

Next add the file search.witty to the folder with the following content:

[component search]
<form action="./" method="get">
<input type="search" value="[words]" name="words" placeholder="Search for..." />
<button type="submit">Search</button>
</form>

<div class="results">
[if totalcount]
[totalcount] item(s) found for '[words]'.
[elseif words]
No items found for '[words]'.
[else]
No search term given
[/if]

[if results]
<ul class="searchresults">
[forevery results]
<li>
<a href="[objectid]">
<b class="title">[if title][title][else]<i>No title</i>[/if]</b>
[if summary]
<span class="summary">[summary]</span>
[/if]
</a>
</li>
[/forevery]
</ul>
[/if]
</div>

[/component]

To make the consilio-search engine to create summaries of just the content of a page, add html comments, in the main witty template around the [contents] macro else the summary will also contain the navigation and footer content.

<!--wh_consilio_content-->
[contents]
<!--/wh_consilio_content-->

Add to the main siteprofile ( <webdesignname>.siteprl.xml ) directly after the existing applysiteprofile rule(s):

<applysiteprofile path="pages/search/search.siteprl.xml" />

Finally, create in the website a new file of type ‘Search page’. The filetype will not be visible immediately, you’ll need to enable “Show all types’. In this case that’s probably okay as you don’t need site users to be able to create multiple search pages. But if you want to enable users to select the Search page type, add the following code to the site profilel:

<apply>
<to type="all" />
<allowfiletype typedef="http://examplesite.webhare.com/xmlns/types/searchpage" />
</apply>

For styling add ‘search.css’ (or .scss) to the folder and add to main scss file definition (<webdesignname>.scss )

@import "./pages/search/search.css";

and put your styling for the search page in the search.css file.