MediaSearch

The Media Search EVML object allows Theme developers to build functionality for Media Library directories.


<?ev
    // Create a new media search object
    var search = new MediaSearch();
    
    // Get a search string from query parameters
    var phrase = request.param('q', '');
    search.find(phrase);
    
    // Search within the Images Media Library
    search.directory('~/content/images');
    
    // You can paginate the results
    search.limit(25);
    search.requestPagination();
    
    // Iterate across results
    for (var mediapath of search) {
        dump(mediapath);
    }
?>

<!-- Draw pagination -->
<ev:pagination object="search" />


Methods
directory(String:path) MediaSearch

MediaSearch defaults to listing files (not directories) within the Media Library's Image directory ( ~/content/images). You can change the current directory via the directory() method using a Content URI matching any directory within your Media Library.

Returns the original MediaSearch object allowing for method chaining.

find(String:phrase) MediaSearch

Sets a search phrase to match against file names.

Returns the original MediaSearch object.

hasNextPage() Boolean

Returns true if the search has more results to show, or false if not.

hasPreviousPage() Boolean

Returns true if the current page number is greater than one, or false there are no prior results.

hasResults() Boolean

Returns true if the search has one or more results.

hasSortString(String:value) Boolean

Returns true if the search algorithm supports the supplied value as method of sorting results.

isFirstPage() Boolean

Returns true if this is the first page of results.

isLastPage() Boolean

Returns true if this is the last page of results.

length() Number

The number of items within the current result set. This will be less than or equal to the page size.

limit(Number:length) MediaSearch

Sets the result set limit to return in the search.

nextPage() Number | null

Returns the Number of the next page in the results sequence.

Returns Null if there are no further pages.

nextPageUrl() Url | null

Returns the Url of the next page in the results sequence.

Returns Null if there are no further pages.

offset(Number:displacement) MediaSearch

Sets the index from which to search from. Offset is zero indexed.

orderBy(String:order) MediaSearch

Not implemented for this search object. All results are ordered by title only.

page([Number:num]) MediaSearch

Gets or sets the current page number of the search results.

perPage([Number:limit]) MediaSearch

Gets or sets the result set size per page.

phrase() String

The key phrase to find in the search.

previousPage() Number | null

Returns the Number of the previous page in the results sequence.

Returns Null if was no previous page.

previousPageUrl() Url | null

Returns the Url of the previous page in the results sequence.

Returns Null if there was no previous page.

requestPagination()

Automate limit(), sort(), and page() using default query parameters from the Request object.

results() MediaFilePath[]

An Array of MediaFilePath objects.

sort(String:sortstring)

Alias of orderBy() (above)

total() Number

The total number of results available for the search.

totalPages() Number

The total number of pages available for the search.