Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

setup_search_chunks()

Description

Allow $fetchrows as supplied to do_search() to support an integer or array. If integer then search will recieve the number of rows with no offset.
If array then search will receive the number of rows to return and an offset allowing for chunking of results.
$chunk_offset[0] is the offset of the first row to return. $chunk_offset[1] is the number of rows to return in the batch. $chunk_offset[0] will normally be 0 in the first search,
increasing by $chunk_offset[1] for each search, generated by an external looping structure. This allows for batches of $chunk_offset[1] search results up to the total size of the search.
For an example {@see pages/csv_export_results_metadata.php}. This approach can be used to avoid particularly large searches exceeding the PHP memory_limit when processing the data in ps_query().

Parameters

ColumnTypeDefaultDescription
$fetchrows int|array $fetchrows value passed from do_search() / search_special(). See details above.
&$chunk_offset ?int
&$search_chunk_size: ?int
$chunk_offset int Starting position for offset. Default is 0 if none supplied i.e. $fetchrows is int.
$search_chunk_size int Number of rows to return.

Return

void

Location

include/search_functions.php lines 3607 to 3619

Definition

 
function setup_search_chunks($fetchrows, ?int &$chunk_offset, ?int &$search_chunk_size): void
    
{
    if (
is_array($fetchrows) && isset($fetchrows[0]) && isset($fetchrows[1]))
        {
        
$chunk_offset max((int)$fetchrows[0],0);
        
$search_chunk_size = (int)$fetchrows[1];
        }
    else
        {
        
$chunk_offset 0;
        
$search_chunk_size = (int)$fetchrows;
        }
    }

This article was last updated 17th November 2024 15:35 Europe/London time based on the source file dated 8th November 2024 11:45 Europe/London time.