Create a Solr search form on any page
Create a topic that you can include, for instance SearchForm, and write:
<div class="solrSearch">
<form name="searchform" class='solrSearchForm' action='%SCRIPTURLPATH{"view"}%/%SYSTEMWEB%/SolrSearch'>
<input type="hidden" name="filter" value="web:%BASEWEB%" />
<input type='hidden' name='web' value='%BASEWEB%' />
<div class='foswikiFormSteps'>
<div class='foswikiFormStep'>
<table class='foswikiNullTable'>
<tr>
<td>
<input type='text' class='foswikiInputField jqFocus solrSearchField' autocomplete='off' name='search' size='60' value='%URLPARAM{"search" encode="entity"}%' />
</td>
<td>
%BUTTON{"%MAKETEXT{"Search"}%" type="submit" title="%MAKETEXT{"submit the query"}%"}%
</td>
</tr>
</table>
</div>
</div>
</form>
</div>
%JQREQUIRE{"metadata, autocomplete, focus, serialscroll"}%
%ADDTOZONE{
"head"
id="SOLRPLUGIN"
require="JQUERYPLUGIN::AUTOCOMPLETE, JQUERYPLUGIN::FOCUS, JQUERYPLUGIN::METADATA"
text="<link rel='stylesheet' href='%PUBURLPATH%/%SYSTEMWEB%/SolrPlugin/solrplugin.css' type='text/css' media='all' />"
}%
%ADDTOZONE{
"script"
id="SOLRPLUGIN"
require="JQUERYPLUGIN::AUTOCOMPLETE, JQUERYPLUGIN::FOCUS, JQUERYPLUGIN::METADATA"
text="<script type='text/javascript' src='%PUBURLPATH%/%SYSTEMWEB%/SolrPlugin/solrplugin.js'></script>"
}%
This form is configured to search in the current web. For default site-wide search, delete the hidden field
filter
.
--
ArthurClemens - 16 Jun 2011
SolrPlugin already comes with a search interface that can be called on any page by applying the
System.SorSearchViewTemplate
to it using the
template
url parameter.
This in effect implements the facetted search solr is famous for.
See this
screenshot.
To call the search interface use
<a href="%SCRIPTURLPATH{"view"}%/%WEB%/%TOPIC%?template=SolrSearchView>Search</a>
To replace the standard WebSearch (as well as WebChanges and SiteChanges) interface with a SolrSearch use
AutoTemplatePlugin (as a drop-in replacement for your AutoViewTemplatePlugin) and add
$Foswiki::cfg{Plugins}{AutoTemplatePlugin}{ViewTemplateRules} = {
...
'WebChanges' => 'WebChangesView',
'SiteChanges' => 'SiteChangesView',
'WebSearch' => 'SolrSearchView',
...
};
to your Foswiki configuration.
--
MichaelDaum - 30 May 2012