本文整理汇总了PHP中SearchForm::getResults方法的典型用法代码示例。如果您正苦于以下问题:PHP SearchForm::getResults方法的具体用法?PHP SearchForm::getResults怎么用?PHP SearchForm::getResults使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SearchForm
的用法示例。
在下文中一共展示了SearchForm::getResults方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: SearchForm
function testPublishedPagesMatchedByTitleInDefaultLanguage()
{
$sf = new SearchForm($this->mockController, 'SearchForm');
$publishedPage = $this->objFromFixture('SiteTree', 'publishedPage');
$publishedPage->publish('Stage', 'Live');
$translatedPublishedPage = $publishedPage->createTranslation('de_DE');
$translatedPublishedPage->Title = 'translatedPublishedPage';
$translatedPublishedPage->Content = 'German content';
$translatedPublishedPage->write();
$translatedPublishedPage->publish('Stage', 'Live');
$this->waitUntilIndexingFinished();
// Translatable::set_current_locale() can't be used because the context
// from the holder is not present here - we set the language explicitly
// through a pseudo GET variable in getResults()
$lang = 'en_US';
$results = $sf->getResults(null, array('Search' => 'content', 'locale' => $lang));
$this->assertContains($publishedPage->ID, $results->column('ID'), 'Published pages are found by searchform in default language');
$this->assertNotContains($translatedPublishedPage->ID, $results->column('ID'), 'Published pages in another language are not found when searching in default language');
$lang = 'de_DE';
$results = $sf->getResults(null, array('Search' => 'content', 'locale' => $lang));
$this->assertNotContains($publishedPage->ID, $results->column('ID'), 'Published pages in default language are not found when searching in another language');
$actual = $results->column('ID');
array_walk($actual, 'intval');
$this->assertContains((int) $translatedPublishedPage->ID, $actual, 'Published pages in another language are found when searching in this language');
}
示例2: testDisabledShowInSearchFlagNotIncluded
function testDisabledShowInSearchFlagNotIncluded()
{
$sf = new SearchForm($this->mockController, 'SearchForm');
$page = $this->objFromFixture('SiteTree', 'dontShowInSearchPage');
$results = $sf->getResults(null, array('Search' => 'dontShowInSearchPage'));
$this->assertNotContains($page->ID, $results->column('ID'), 'Page with "Show in Search" disabled doesnt show');
}
示例3: modulesearchformresults
/**
* Process and render search results.
*
* @param array $data The raw request data submitted by user
* @param SearchForm $form The form instance that was submitted
* @param SS_HTTPRequest $request Request generated for this action
*/
function modulesearchformresults($data, $form, $request)
{
$data = array('Results' => $form->getResults(), 'Query' => $form->getSearchQuery(), 'Title' => _t('SearchForm.SearchResults', 'Search Results'));
//search tags
//search authors
if ($data["Results"]) {
foreach ($data["Results"] as $key => $resultItem) {
if (!$resultItem instanceof ModuleProduct) {
$data["Results"]->remove($resultItem);
}
}
} else {
$data["Results"] = new ArrayList();
}
$search = Convert::raw2sql($data["Query"]);
if (strlen($search) > 2) {
$additionalProducts = ModuleProduct::get()->filterAny(array("Code:PartialMatch" => $search, "MenuTitle:PartialMatch" => $search));
if ($additionalProducts) {
foreach ($additionalProducts as $moduleProduct) {
$data["Results"]->push($moduleProduct);
}
}
$tags = EcommerceProductTag::get()->filterAny(array("Title:PartialMatch" => $search, "Synonyms:PartialMatch" => $search, "Explanation:PartialMatch" => $search));
if ($tags->count()) {
foreach ($tags as $tag) {
$rows = DB::query("SELECT ProductID FROM EcommerceProductTag_Products WHERE EcommerceProductTagID = " . $tag->ID);
if ($rows) {
foreach ($rows as $row) {
$item = ModuleProduct::get()->byID($row["ProductID"]);
if ($item) {
$data["Results"]->push($item);
}
}
}
}
}
$authors = Member::get()->filterAny(array("ScreenName:PartialMatch" => $search, "FirstName:PartialMatch" => $search, "Surname:PartialMatch" => $search));
if ($authors->count()) {
foreach ($authors as $author) {
$rows = DB::query("SELECT \"ModuleProductID\" FROM \"ModuleProduct_Authors\" WHERE \"MemberID\" = " . $author->ID);
if ($rows) {
foreach ($rows as $row) {
$item = ModuleProduct::get()->byID($row["ModuleProductID"]);
if ($item) {
$data["Results"]->push($item);
}
}
}
}
}
}
if ($data["Results"] && $data["Results"] instanceof DataObjectSet) {
$data["Results"]->removeDuplicates();
}
if (Director::is_ajax()) {
return Convert::array2json(array("ModuleProducts" => $data["Results"]->column("ID")));
}
return $this->customise(array("Products" => $data["Results"]));
}
示例4: SearchForm
function testSearchTitleAndContentWithSpecialCharacters()
{
$sf = new SearchForm($this->mockController, 'SearchForm');
$pageWithSpecialChars = $this->objFromFixture('SiteTree', 'pageWithSpecialChars');
$pageWithSpecialChars->publish('Stage', 'Live');
$results = $sf->getResults(null, array('Search' => 'Brötchen'));
$this->assertContains($pageWithSpecialChars->ID, $results->column('ID'), 'Published pages with umlauts in title are found');
$results = $sf->getResults(null, array('Search' => 'Bäcker'));
$this->assertContains($pageWithSpecialChars->ID, $results->column('ID'), 'Published pages with htmlencoded umlauts in content are found');
}
示例5: testSearchTitleAndContentWithSpecialCharacters
public function testSearchTitleAndContentWithSpecialCharacters()
{
if (!$this->checkFulltextSupport()) {
return;
}
if (class_exists('PostgreSQLDatabase') && DB::get_conn() instanceof PostgreSQLDatabase) {
$this->markTestSkipped("PostgreSQLDatabase doesn't support entity-encoded searches");
}
$sf = new SearchForm($this->mockController, 'SearchForm');
$pageWithSpecialChars = $this->objFromFixture('SiteTree', 'pageWithSpecialChars');
$pageWithSpecialChars->publish('Stage', 'Live');
$results = $sf->getResults(null, array('Search' => 'Brötchen'));
$this->assertContains($pageWithSpecialChars->ID, $results->column('ID'), 'Published pages with umlauts in title are found');
$results = $sf->getResults(null, array('Search' => 'Bäcker'));
$this->assertContains($pageWithSpecialChars->ID, $results->column('ID'), 'Published pages with htmlencoded umlauts in content are found');
}
示例6: results
/**
* Process and render search results. This has been hacked a bit to load
* products into the list (if they exists). Will need to come up with a more
* elegant solution to dealing with complex searches of objects though.
*
* @param array $data The raw request data submitted by user
* @param SearchForm $form The form instance that was submitted
* @param SS_HTTPRequest $request Request generated for this action
*/
public function results($data, $form, $request)
{
$results = $form->getResults();
// For the moment this will also need to be added to your
// Page_Controller::results() method (until a more elegant solution can
// be found
if (class_exists("Product")) {
$products = Product::get()->filterAny(array("Title:PartialMatch" => $data["Search"], "StockID" => $data["Search"], "Content:PartialMatch" => $data["Search"]));
$results->merge($products);
}
$results = $results->sort("Title", "ASC");
$data = array('Results' => PaginatedList::create($results, $this->request), 'Query' => $form->getSearchQuery(), 'Title' => _t('SearchForm.SearchResults', 'Search Results'));
return $this->owner->customise($data)->renderWith(array('Page_results', 'SearchResults', 'Page'));
}
示例7: results
/**
* Process and render search results.
*
* @param array $data The raw request data submitted by user
* @param SearchForm $form The form instance that was submitted
* @param SS_HTTPRequest $request Request generated for this action
*/
public function results($data, $form, $request)
{
$data = array('Results' => $form->getResults(), 'Query' => $form->getSearchQuery(), 'Title' => _t('SearchForm.SearchResults', 'Search Results'));
return $this->owner->customise($data)->renderWith(array('Page_results', 'Page'));
}
示例8: results
/**
* Gets the results from the given query.
*
* Appends to the usual results the matches on the GtkdocSection
* instances on the following order:
*
* 1. GtkdocSections with matches in 'Title'
* 2. GtkdocSections with matches in 'MetaDescription'
* 3. GtkdocSections with matches in 'Content'
*
* Eventual duplicates are dropped from the list.
*
* @param array $data The raw data submitted by user
* @param SearchForm $form The form instance
* @param SS_HTTPRequest $request Request for this action
*/
public function results($data, $form, $request)
{
$keywords = $data['Search'];
// Populate the first matches in the usual way
$matches = $form->getResults()->toArray();
// Get the list of GtkdocSection with matching title...
$context = singleton('GtkdocSection')->getDefaultSearchContext();
$gtkdoc_matches = $context->getResults(array('Title' => $keywords))->toArray();
// ...and add to them the list of GtkdocSection with matching
// description and matching content, skipping the duplicates...
self::merge($gtkdoc_matches, $context->getResults(array('MetaDescription' => $keywords))->toArray());
self::merge($gtkdoc_matches, $context->getResults(array('Content' => $keywords))->toArray());
// Append the GtkdocSection matches to the original ones
$matches = array_merge($matches, $gtkdoc_matches);
$results = new PaginatedList(new ArrayList($matches));
$results->setPageLength(10);
$results->setLimitItems(true);
$results->setPageStart($request->getVar('start'));
$data = array('Results' => $results, 'Query' => $form->getSearchQuery(), 'Title' => _t('SearchForm.SearchResults', 'Search Results'));
return $this->owner->customise($data)->renderWith(array('Page_results', 'Page'));
}
示例9: results
/**
* Overrides the ContentControllerSearchExtension and adds snippets to results.
*
* @param array $data
* @param SearchForm $form
* @param SS_HTTPRequest $request
* @return HTMLText
*/
function results($data, $form, $request)
{
$result = null;
$results = $form->getResults();
$query = $form->getSearchQuery();
// Add context summaries based on the queries.
foreach ($results as $result) {
$contextualTitle = new Text();
$contextualTitle->setValue($result->MenuTitle ? $result->MenuTitle : $result->Title);
$result->ContextualTitle = $contextualTitle->ContextSummary(300, $query);
if (!$result->Content && $result->ClassName == 'File') {
// Fake some content for the files.
$result->ContextualContent = "A file named \"{$result->Name}\" ({$result->Size}).";
} else {
// /(.?)\[embed(.*?)\](.+?)\[\/\s*embed\s*\](.?)/gi
$valueField = $result->obj('Content');
$valueField->setValue(ShortcodeParser::get_active()->parse($valueField->getValue()));
$result->ContextualContent = $valueField->ContextSummary(300, $query);
}
}
$rssLink = HTTP::setGetVar('rss', '1');
// Render the result.
$context = array('Results' => $results, 'Query' => $query, 'Title' => _t('SearchForm.SearchResults', 'Search Results'), 'RSSLink' => $rssLink);
// Choose the delivery method - rss or html.
if (!$this->owner->request->getVar('rss')) {
// Add RSS feed to normal search.
RSSFeed::linkToFeed($rssLink, "Search results for query \"{$query}\".");
$result = $this->owner->customise($context)->renderWith(array('Page_results', 'Page'));
} else {
// De-paginate and reorder. Sort-by-relevancy doesn't make sense in RSS context.
$fullList = $results->getList()->sort('LastEdited', 'DESC');
// Get some descriptive strings
$siteName = SiteConfig::current_site_config()->Title;
$siteTagline = SiteConfig::current_site_config()->Tagline;
if ($siteName) {
$title = "{$siteName} search results for query \"{$query}\".";
} else {
$title = "Search results for query \"{$query}\".";
}
// Generate the feed content.
$rss = new RSSFeed($fullList, $this->owner->request->getURL(), $title, $siteTagline, "Title", "ContextualContent", null);
$rss->setTemplate('Page_results_rss');
$result = $rss->outputToBrowser();
}
return $result;
}
开发者ID:helpfulrobot,项目名称:gdmedia-silverstripe-gdm-extensions,代码行数:54,代码来源:SSGuru_ContentController.php