public function index($s, $i) { $this->searchResults = Searchable::doSearch($s, 'nl', $i); $this->searchQuery = $s; $this->searchIncludes = $i; $this->render('searchresults'); }
/** * Add a site search form to all controllers that links to the * results controller. * * @return Form */ public function SearchForm() { // If we have setup objects to search if (count(Searchable::getObjects())) { $searchText = ""; if ($this->owner->request && $this->owner->request->getVar('Search')) { $searchText = $this->owner->request->getVar('Search'); } $fields = FieldList::create(TextField::create('Search', false, $searchText)->setAttribute("placeholder", _t('Searchable.Search', 'Search'))); $actions = FieldList::create(FormAction::create('results', _t('Searchable.Go', 'Go'))); $template_class = Searchable::config()->template_class; $results_page = new $template_class(); $form = Form::create($this->owner, 'SearchForm', $fields, $actions)->setFormMethod('get')->setFormAction($results_page->Link())->disableSecurityToken(); $this->owner->extend("updateSearchForm", $form); return $form; } }
/** * Remove an entry from the index * * @param Searchable $item Model to remove * @return Search return this instance for method chaining */ public function remove($item) { // now we have the identifier, find it $hits = $this->find('uid:' . $item->get_unique_identifier()); if (sizeof($hits) == 0) { Kohana::log("error", "No index entry found for id " . $item->get_unique_identifier()); } else { if (sizeof($hits) > 1) { Kohana::log("error", "Non-unique Identifier - More than one record was returned"); } } if (sizeof($hits) > 0) { $this->open_index()->delete($hits[0]->id); } // return this so we can have chainable methods return $this; }
* CoOrg is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * You should have received a copy of the GNU Affero General Public License * along with CoOrg. If not, see <http://www.gnu.org/licenses/>. */ $fooSearch = new stdClass; $fooSearch->title = 'Foos'; $fooSearch->module = 'search'; $fooSearch->file = 'foo-search-results.html.tpl'; Searchable::registerSearch('SearchFoo', $fooSearch); class SearchControllerTest extends CoOrgControllerTest { const dataset = 'search.dataset.xml'; public function setUp() { parent::setUp(); $bar = new SearchBar; $bar->title = 'Bar Title'; $bar->someOtherPrimary = 'The Primary'; $bar->body = 'Lorem Ipsum'; $bar->language = 'en';
/** * Return DataList of the results using $_REQUEST to get search info * Wraps around {@link searchEngine()}. * * Results also checks to see if there is a custom filter set in * configuration and adds it. * * @param $classname Name of the object we will be filtering * @param $columns an array of the column names we will be sorting * @param $query the current search query * * @return SS_List */ static function Results($classname, $columns, $keywords, $limit = 0) { $cols_string = implode('","', $columns); $custom_filters = Searchable::config()->custom_filters; $filter = array(); foreach ($columns as $col) { $filter["{$col}:PartialMatch"] = $keywords; } $results = $classname::get()->filterAny($filter); if (is_array($custom_filters) && array_key_exists($classname, $custom_filters) && is_array($custom_filters[$classname])) { $results = $results->filter($custom_filters[$classname]); } if ($limit) { $results = $results->limit($limit); } foreach ($results as $result) { if (!$result->canView() || isset($result->ShowInSearch) && !$result->ShowInSearch) { $results->remove($result); } } return $results; }
protected function deleteIndexQueryString($all) { $q = parent::deleteIndexQueryString($all); if (!$all) $q .= ' AND (NOT field = \'tag\')'; return $q; }
public function configure($widgetParams, $orient) { $this->includeSearch = $widgetParams['includes'] ? $widgetParams['includes'] : array(); $this->allIncludes = Searchable::searches(); return $this->renderConfigure('widgets/search-configure'); }
/** * Return DataList of the results using $_REQUEST to get search info * Wraps around {@link searchEngine()}. * * Results also checks to see if there is a custom filter set in * configuration and adds it. * * @param $classname Name of the object we will be filtering * @param $columns an array of the column names we will be sorting * @param $query the current search query * * @return SS_List */ public static function Results($classname, $columns, $keywords, $limit = 0) { $cols_string = implode('","', $columns); $custom_filters = Searchable::config()->custom_filters; $results = ArrayList::create(); $filter = array(); foreach ($columns as $col) { $filter["{$col}:PartialMatch"] = $keywords; } $search = $classname::get()->filterAny($filter); if (is_array($custom_filters) && array_key_exists($classname, $custom_filters) && is_array($custom_filters[$classname])) { $search = $search->filter($custom_filters[$classname]); } $searchable = new Searchable(); if ($searchable->hasMethod('filterResultsByCallback')) { $search = $searchable->filterResultsByCallback($search, $classname); } if ($limit) { $search = $search->limit($limit); } foreach ($search as $result) { if ($result->canView() || isset($result->ShowInSearch) && $result->ShowInSearch) { $results->add($result); } } return $results; }
<?php $pageSearch = new stdClass; $pageSearch->title = t('Content'); $pageSearch->module = 'page'; $pageSearch->file = 'search-results.html.tpl'; Searchable::registerSearch('Page', $pageSearch); ?>
public function object() { $classname = $this->request->param("ID"); $classes_to_search = Searchable::getObjects(); foreach ($classes_to_search as $object) { if ($object["ClassName"] == $classname) { $cols = $object["Columns"]; } } $keywords = $this->getQuery(); $this->customise(array("MetaTitle" => _t('Searchable.SearchResultsFor', "Search Results for '{query}'", 'This is the title used for viewing the results of a search', array('query' => $this->getQuery())), "Results" => PaginatedList::create(Searchable::Results($classname, $cols, $keywords), $this->request)->setPageLength(Searchable::config()->page_length))); $this->extend("onBeforeObject"); return $this->renderWith(array("SearchResults_{$classname}", "SearchResults_object", "SearchResults", "Page")); }