mirror of
https://github.com/silverstripe/silverstripe-docsviewer
synced 2024-10-22 11:05:56 +02:00
Merge pull request #21 from Martimiz/search-20130107
This commit is contained in:
commit
389269936b
@ -30,6 +30,11 @@ class DocumentationSearch {
|
||||
* @var bool - Is search enabled
|
||||
*/
|
||||
private static $enabled = false;
|
||||
|
||||
/**
|
||||
* @var bool - Is advanced search enabled
|
||||
*/
|
||||
private static $advanced_search_enabled = true;
|
||||
|
||||
/**
|
||||
* @var string - OpenSearch metadata. Please use {@link DocumentationSearch::set_meta_data()}
|
||||
@ -171,6 +176,20 @@ class DocumentationSearch {
|
||||
return self::$enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enable advanced documentation search
|
||||
*/
|
||||
public static function enable_advanced_search($enabled = true) {
|
||||
self::$advanced_search_enabled = ($enabled)? true: false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public static function advanced_search_enabled() {
|
||||
return self::$advanced_search_enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string
|
||||
*/
|
||||
@ -245,8 +264,8 @@ class DocumentationSearch {
|
||||
$data = array(
|
||||
'Results' => null,
|
||||
'Query' => null,
|
||||
'Versions' => DBField::create_field('Text', implode(',', $this->versions)),
|
||||
'Modules' => DBField::create_field('Text', implode(',', $this->modules)),
|
||||
'Versions' => DBField::create_field('Text', implode(', ', $this->versions)),
|
||||
'Modules' => DBField::create_field('Text', implode(', ', $this->modules)),
|
||||
'Title' => _t('DocumentationSearch.SEARCHRESULTS', 'Search Results'),
|
||||
'TotalResults' => null,
|
||||
'TotalPages' => null,
|
||||
|
@ -277,7 +277,7 @@ class DocumentationService {
|
||||
$docs = Director::baseFolder() . '/' . Controller::join_links($entity, 'docs');
|
||||
|
||||
if(is_dir($docs)) {
|
||||
self::register($entity, $docs, '', $entity, true);
|
||||
self::register($entity, $docs, 'current', $entity, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -158,6 +158,8 @@ class DocumentationViewer extends Controller {
|
||||
* @return SS_HTTPResponse
|
||||
*/
|
||||
public function handleRequest(SS_HTTPRequest $request, DataModel $model) {
|
||||
DocumentationService::load_automatic_registration();
|
||||
|
||||
// if we submitted a form, let that pass
|
||||
if(!$request->isGET() || isset($_GET['action_results'])) {
|
||||
return parent::handleRequest($request, $model);
|
||||
@ -168,7 +170,6 @@ class DocumentationViewer extends Controller {
|
||||
$thirdParam = $request->shift();
|
||||
|
||||
$this->Remaining = $request->shift(10);
|
||||
DocumentationService::load_automatic_registration();
|
||||
|
||||
// if no params passed at all then it's the homepage
|
||||
if(!$firstParam && !$secondParam && !$thirdParam) {
|
||||
@ -344,8 +345,7 @@ class DocumentationViewer extends Controller {
|
||||
|
||||
foreach($versions as $key => $version) {
|
||||
$linkingMode = ($currentVersion == $version) ? 'current' : 'link';
|
||||
|
||||
if(!$version) $version = 'Current';
|
||||
|
||||
$output->push(new ArrayData(array(
|
||||
'Title' => $version,
|
||||
'Link' => $this->Link(implode('/',$this->Remaining), $entity->getFolder(), $version),
|
||||
@ -816,10 +816,19 @@ class DocumentationViewer extends Controller {
|
||||
if(!DocumentationSearch::enabled()) return false;
|
||||
$q = ($q = $this->getSearchQuery()) ? $q->NoHTML() : "";
|
||||
|
||||
$entities = $this->getSearchedEntities();
|
||||
$versions = $this->getSearchedVersions();
|
||||
|
||||
$fields = new FieldList(
|
||||
new TextField('Search', _t('DocumentationViewer.SEARCH', 'Search'), $q),
|
||||
new HiddenField('Entities', '', implode(',', array_keys($this->getSearchedEntities()))),
|
||||
new HiddenField('Versions', '', implode(',', $this->getSearchedVersions()))
|
||||
new TextField('Search', _t('DocumentationViewer.SEARCH', 'Search'), $q)
|
||||
);
|
||||
|
||||
if ($entities) $fields->push(
|
||||
new HiddenField('Entities', '', implode(',', array_keys($entities)))
|
||||
);
|
||||
|
||||
if ($versions) $fields->push(
|
||||
new HiddenField('Versions', '', implode(',', $versions))
|
||||
);
|
||||
|
||||
$actions = new FieldList(
|
||||
@ -964,6 +973,17 @@ class DocumentationViewer extends Controller {
|
||||
|
||||
return $form;
|
||||
}
|
||||
|
||||
/**
|
||||
* check if the Advanced SearchForm can be displayed
|
||||
* enabled by default, to disable use:
|
||||
* DocumentationSearch::enable_advanced_search(false);
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function getAdvancedSearchEnabled() {
|
||||
return DocumentationSearch::advanced_search_enabled();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check to see if the currently accessed version is out of date or
|
||||
|
@ -65,6 +65,13 @@ documentation search needs to be updated on the fly
|
||||
|
||||
sake dev/tasks/RebuildLuceneDocsIndex flush=1
|
||||
|
||||
## Advanced Search
|
||||
|
||||
Advanced Search is enabled by default on the searchresults page, allowing you to
|
||||
extend your search over multiple modules and/or versions. Advanced search can
|
||||
be disabled from your _config.php like this:
|
||||
|
||||
DocumentationSearch::enable_advanced_search(false);
|
||||
|
||||
## Using a URL other than /dev/docs/
|
||||
|
||||
|
@ -43,10 +43,13 @@
|
||||
<% end_if %>
|
||||
</div>
|
||||
|
||||
<div id="sidebar-column">
|
||||
<div class="sidebar-box">
|
||||
<h4><% _t('ADVANCEDSEARCH', 'Advanced Search') %></h4>
|
||||
$AdvancedSearchForm
|
||||
<% if AdvancedSearchEnabled %>
|
||||
<div id="sidebar-column">
|
||||
<div class="sidebar-box">
|
||||
<h4><% _t('ADVANCEDSEARCH', 'Advanced Search') %></h4>
|
||||
$AdvancedSearchForm
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end_if %>
|
||||
|
||||
</div>
|
Loading…
Reference in New Issue
Block a user