Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource 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 3356 to 3368

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 24th May 2024 10:35 Europe/London time based on the source file dated 13th May 2024 14:40 Europe/London time.