I added a more detailed explanation of the function on MivaScript.com
My testing shows miva_array_filter_ref() is approximately twice as fast as miva_array_filter(), when filtering test data of about 2500 records. In either case, the functions provide a very fast way (as in milliseconds) to loop through any data set. I found it used within Merchant for facet filtering and in other places in the LSK.
Announcement
Collapse
No announcement yet.
Understanding the miva_array_filter()
Collapse
X
-
When I need more info about a particular function, I sometimes search the LSK for a place where the function is used.
Leave a comment:
-
Originally posted by alphabet View PostHi Ray,
I think your best guess is correct.
For me, the example's naming convention is a little confusing as l.method is used in two different places.
I did a bit of testing on 2500 records and miva_array_insert_ref() is more than twice as fast as miva_array_insert() and will undoubtedly use less memory.
The the former's output creates pointers to the original data (so editing one edits the other) while the latter creates a copy of the data.
Either way, the function is a very fast way to see if a value is contained within a data set.
Code:<mvt:assign name="g.filter_count" value="miva_array_filter_ref( l.settings:all_products:products, 1, l.product, 'l.product:price GE 100', l.settings:output )" />
Leave a comment:
-
And thank you for your awesome work maintaining Mivascript.com, I would be lost without it.
Leave a comment:
-
Hi Ray,
I think your best guess is correct.
For me, the example's naming convention is a little confusing as l.method is used in two different places.
Here is an example I use:
Code:<mvt:assign name="g.filter_expression" value="'l.settings:filter_element:sku NE ' $ g.discontinue_prepared" /> <mvt:assign name="g.filter_fts_search_prod_length" value="miva_array_filter( l.settings:fts_search_prod:results, g.start, l.settings:filter_element, g.filter_expression, l.settings:fts_search_prod:results )" />
Leave a comment:
-
Sorry I didn't word the post better.
What does the internal loop and IF expression look like (given the example above)?
I'm trying to make sure I understand the parameters element and filter_expression and will add a clarification to Mivascript.com
This is my best guess/approximation as to what its doing. Is it correct?
Code:<MvFOREACH ITERATOR = "l.method" ARRAY = "l.methods"> <MvIF EXPR="{ l.method:paymentcardtype:id GT 0 }"> <MvASSIGN NAME="l.output_count" VALUE="{ miva_array_insert_ref( l.outout, l.method, -1 ) }"> </MvIF> </MvFOREACH>
Leave a comment:
-
Hi Ray,
It is true that the output array does overwrite the original array.
Do you have an array method:paymentcardtype present or assigned to the page ? If so, my best guess, the expression will filter out any paymentcardtype:id with 0 or -1 results (typically an error response code).
I haven't seen paymentcardtype array used on my OPAY page.
Leave a comment:
-
Understanding the miva_array_filter()
I'm trying to understand the miva_array_filter() function. Ref: http://www.mivascript.com/item/miva_...ilter_ref.html
Syntax: miva_array_filter_ref( array var, offset, element var, filter_expression, output var )
Return value: Count of output array elements.
-- array var = Source array of structures.
-- offset = index in the array to start filtering from.
-- element var = Name of a variable to reference in the filter expression.
-- filter_expression = Text of an expression to execute based on the individual array element.
-- output var = Output array of all structures that tested true in the filter expression.
Given this example:
Code:<MvASSIGN NAME = "l.method_count" VALUE = "{ miva_array_filter( l.methods, 1, l.method, 'l.method:paymentcardtype:id GT 0', l.methods ) }">
I'm unclear what the filter_expression is doing.
So if expressed as a mvt:foreach loop what does the mvt:if statement look like?
Code:<mvt:foreach iterator="item" array="l.methods"> <mvt:if expr="expression"> </mvt:if> </mvt:foreach>
Tags: None
Leave a comment: