Article search class
Phproberto\Joomla\Entity\Content\Search\ArticleSearch
Allows to easily search articles.
Index
Usage
To start using the article search you have to load the phproberto_library
and add the use statement like:
use Phproberto\Joomla\Entity\Content\Search\ArticleSearch;
// Start searching!
$searcher = new ArticleSearch(['filter.language' => 'es-ES', 'list.limit' => 5]);
$articles = $searcher->search();
// You can do it in one line!
$articles = ArticleSearch::instance(['filter.language' => 'es-ES', 'list.limit' => 5])->search();
Filters
Filters are ways to fine tune your search to retrieve exactly the data that you want.
filter.access
Allows to search articles only available for specific view levels.
Expected Value:
integer
: Single View level identifier.integer[]
: Array of view levels identifiers.
Examples:
use Phproberto\Joomla\Entity\Content\Search\ArticleSearch;
// Search only visible articles for Public view level (id: 1)
$articles = ArticleSearch::instance(['filter.access' => 1]);
// Search only visible articles for Public or Registered view levels
$articles = ArticleSearch::instance(['filter.access' => [1, 2]]);
filter.active_language
When this filter is enabled only articles of the active language will be returned.
Expected Value:
boolean
: True to to enable it.
Examples:
use Phproberto\Joomla\Entity\Content\Search\ArticleSearch;
$articles = ArticleSearch::instance(['filter.active_language' => true]);
filter.active_user_access
When this filter is enabled only articles that have a view level viewable by the active language will be returned. You will usually use this in all your frontend stuff.
Expected Value:
boolean
: True to to enable it.
Examples:
use Phproberto\Joomla\Entity\Content\Search\ArticleSearch;
$articles = ArticleSearch::instance(['filter.active_user_access' => true]);
filter.author_id
Return only articles created by a specific user.
Expected Value:
integer
: Single identifier.integer[]
: Array of identifiers.
Examples:
use Phproberto\Joomla\Entity\Content\Search\ArticleSearch;
// Return only articles created by user with ID 42
$articles = ArticleSearch::instance(['filter.author_id' => 42]);
// Return only articles created by user with ID 42 or 50
$articles = ArticleSearch::instance(['filter.author_id' => [42, 50]]);
filter.category_id
Return only articles assigned to a specific category.
Expected Value:
integer
: Single identifier.integer[]
: Array of identifiers.
Examples:
use Phproberto\Joomla\Entity\Content\Search\ArticleSearch;
// Return only articles assigned to category with ID 8
$articles = ArticleSearch::instance(['filter.category_id' => 8]);
// Return only articles assigned to category with ID 8 or 14
$articles = ArticleSearch::instance(['filter.category_id' => [8, 14]]);
filter.editor_id
Return only articles edited by a specific user.
Expected Value:
integer
: Single identifier.integer[]
: Array of identifiers.
Examples:
use Phproberto\Joomla\Entity\Content\Search\ArticleSearch;
// Return only articles edited by user with ID 42
$articles = ArticleSearch::instance(['filter.editor_id' => 42]);
// Return only articles edited by user with ID 42 or 50
$articles = ArticleSearch::instance(['filter.editor_id' => [42, 50]]);
filter.featured
Return only articles in the specifiec featured status.
Expected Value:
integer
: Single status identifier.integer[]
: Array of status identifiers.
Examples:
use Phproberto\Joomla\Entity\Content\Search\ArticleSearch;
// Return only articles that are featured
$articles = ArticleSearch::instance(['filter.featured' => 1]);
// Return only articles that are not featured
$articles = ArticleSearch::instance(['filter.featured' => 0]);
filter.id
Return only articles with one or more specific ids.
Expected Value:
integer
: Single identifier.integer[]
: Array of identifiers.
Examples:
use Phproberto\Joomla\Entity\Content\Search\ArticleSearch;
// Return only article with ID 11
$articles = ArticleSearch::instance(['filter.id' => 11]);
// Return only article with ID 11 or 12
$articles = ArticleSearch::instance(['filter.id' => [11, 12]]);
filter.language
Return only articles from one or more specified languages.
Expected Value:
string
: Single language tag.string[]
: Array of language tags.
Examples:
use Phproberto\Joomla\Entity\Content\Search\ArticleSearch;
// Return only articles in english
$articles = ArticleSearch::instance(['filter.language' => 'en-GB']);
// Return only articles in english or spanish
$articles = ArticleSearch::instance(['filter.language' => ['en-GB', 'es-ES']]);
filter.not_author_id
Return only articles created by users distinct than specified.
Expected Value:
integer
: Single identifier.integer[]
: Array of identifiers.
Examples:
use Phproberto\Joomla\Entity\Content\Search\ArticleSearch;
// Return only articles created by any user except user with ID 42
$articles = ArticleSearch::instance(['filter.not_author_id' => 42]);
// Return only articles created by any user except user with ID 42 or 50
$articles = ArticleSearch::instance(['filter.not_author_id' => [42, 50]]);
filter.not_category_id
Return only articles assigned to a category different than the specified ones.
Expected Value:
integer
: Single identifier.integer[]
: Array of identifiers.
Examples:
use Phproberto\Joomla\Entity\Content\Search\ArticleSearch;
// Return only articles assigned to any category with ID not equal to 8
$articles = ArticleSearch::instance(['filter.not_category_id' => 8]);
// Return only articles assigned to any category with ID not equal to 8 or 14
$articles = ArticleSearch::instance(['filter.not_category_id' => [8, 14]]);
filter.not_id
Return only articles with IDs distinct than the specified ones.
Expected Value:
integer
: Single identifier.integer[]
: Array of identifiers.
Examples:
use Phproberto\Joomla\Entity\Content\Search\ArticleSearch;
// Return only articles with with ID distinct than 11
$articles = ArticleSearch::instance(['filter.not_id' => 11]);
// Return only articles with with ID distinct than 11 or 12
$articles = ArticleSearch::instance(['filter.not_id' => [11, 12]]);
filter.not_language
Return only articles assigned to a language with tag distinct that the specified ones.
Expected Value:
string
: Single language tag.string[]
: Array of language tags.
Examples:
use Phproberto\Joomla\Entity\Content\Search\ArticleSearch;
// Return only articles that are not in english
$articles = ArticleSearch::instance(['filter.not_language' => 'en-GB']);
// Return only articles that are not in english or spanish
$articles = ArticleSearch::instance(['filter.not_language' => ['en-GB', 'es-ES']]);
filter.not_state
Return only articles with a state different than the specified.
Expected Value:
integer
: Single status identifier.integer[]
: Array of status identifiers.
Examples:
use Phproberto\Joomla\Entity\Content\Search\ArticleSearch;
// Return only articles that are not in published state
$articles = ArticleSearch::instance(['filter.not_state' => 1]);
// Return only articles that are not in unpublished state
$articles = ArticleSearch::instance(['filter.not_state' => 0]);
filter.search
Return only articles with columns like specified value.
It will search for the string in these columns:
title
. Article titlealias
. Article alias
Expected Value:
string
: String to search.
Examples:
use Phproberto\Joomla\Entity\Content\Search\ArticleSearch;
$articles = ArticleSearch::instance(['filter.search' => 'My title']);
$articles = ArticleSearch::instance(['filter.search' => 'my-alias']);
filter.state
Return only articles in specified state.
Expected Value:
integer
: Single status identifier.integer[]
: Array of status identifiers.
Examples:
use Phproberto\Joomla\Entity\Content\Search\ArticleSearch;
// Return only articles that are published
$articles = ArticleSearch::instance(['filter.state' => 1]);
// Return only articles that are unpublished
$articles = ArticleSearch::instance(['filter.state' => 0]);
filter.tag_id
Return only articles with a one or more tags assigned.
Expected Value:
integer
: Single identifier.integer[]
: Array of identifiers.
Examples:
use Phproberto\Joomla\Entity\Content\Search\ArticleSearch;
// Return only articles with tag with ID 7 assigned
$articles = ArticleSearch::instance(['filter.tag_id' => 7]);
// Return only articles with tag with ID 7 or 33 assigned
$articles = ArticleSearch::instance(['filter.tag_id' => [7, 33]]);
Search modifiers
These modifiers do not filter data but tell the search how many items to return, which order to apply, etc.
list.direction
Tells the search if it has to order items ascendently(ASC
) or descendently(DESC
).
Expected Value:
string
:ASC
orDESC
.
Examples:
use Phproberto\Joomla\Entity\Content\Search\ArticleSearch;
// Return articles ordered by title in descending order
$articles = ArticleSearch::instance(['list.ordering' => 's.title', 'list.direction' => 'DESC']);
list.limit
Tells the search how many items return.
Expected Value:
integer
: Number of items.
Examples:
use Phproberto\Joomla\Entity\Content\Search\ArticleSearch;
// Return only 5 articles
$articles = ArticleSearch::instance(['list.limit' => 5]);
list.ordering
Tells the search the column that will be used for ordering.
Expected Value:
string
: Column.
Examples:
use Phproberto\Joomla\Entity\Content\Search\ArticleSearch;
// Return articles ordered by title in descending order
$articles = ArticleSearch::instance(['list.ordering' => 'c.title', 'list.direction' => 'DESC']);
list.start
Tells the search the column that returns values from specific result. It’s usally used for pagination: return 5 items from result 5
Expected Value:
integer
: First result returned.
Examples:
use Phproberto\Joomla\Entity\Content\Search\ArticleSearch;
// Return only results from 5 to 10
$articles = ArticleSearch::instance(['list.start' => 5, 'list.limit' => 5]);