Adding a search page

This uses the integrated WebHare search engine ‘Consilio’

Create folder pages/search/

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

<?xml version="1.0" encoding="UTF-8" ?>
<siteprofile xmlns="http://www.webhare.net/xmlns/publisher/siteprofile">
<apply>
<to type="file" />
<prebuiltpage type="dynamic"
tag="modulename:mysearchpage"
library="search.whlib"
webpageobjectname="SearchPage" />
</apply>
<apply>
<to type="file" filetype="http://www.webhare.net/xmlns/publisher/prebuiltpage" prebuiltmasks="modulename:mysearchpage" />
<robots xmlns="http://www.webhare.net/xmlns/consilio" noindex="true" nofollow="true"/> <!-- No need to index search page it self -->
</apply>

<!-- Consilio catalog -->
<index xmlns="http://www.webhare.net/xmlns/consilio" name="modulename:websitename">
<contentsource type="publisher:webhare" folder="site::websitename" />
</index>
</siteprofile>

Add file search.whlib to the folder with 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("webhare_com:example-site", CQParseUserQuery(words), [ summary_length := 150 ]);

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

>;

Next add file search.witty to the folder with 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 ‘prebuilt page’ and select in properties for ‘Prebuilt page’ the tag ‘mysearchpage’.

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.