Views: 11770
Last Modified: 19.01.2024

Sometimes caching is bad. If we choose to cache a catalog with a multivariate filter in the conditions of dense website traffic, cache generation may exceed 200 MB per minute. Any disc quota limit will be filled fast enough. Problems with cleaning this cache may also occur. Deactivating such cache will reduce the number of writing operations.

Do not be afraid of creating indexes. It is impossible to say which indexes must be created in each particular case by default; each specific situation must be examined without fail. The tool Analyze indexes helps you do that (Settings > Performance > Database indexes > Analyze indexes).

One of the indexes most frequently used is the index by the list-based property. This index is intended for simple infoblocks. b_iblock_element_property - in this table property values are stored. So we index it: property value, its ID, and an element ID. When the list-based property filter is in place, creating such an index actually makes the query of MySQL to said table unnecessary because all of the query fields are available in the index.

Indexes are needed for specific sampling in specific projects. Depending on project architecture and logics, slow queries receive their own indexes, and they need such own indexes; often such indexes are composite.

Type of filtration

In the majority of functions and methods of the module of information blocks with list selection, filters admit different sorting types. Sorting type symbols shall be indicated directly before the name of the field to be sorted.

Types:

  • (empty) – for string fields means mask search (in mask: "%" - an arbitrary number of any symbols, "_" - one arbitrary symbol); for non-string fields the search is "equal".
<?
// find elements in which the name begins with "#"
$res = CIBlockElement::GetList(Array(), Array("NAME"=>"%#"));

// find elements with identifier 100
$res = CIBlockElement::GetList(Array(), Array("ID"=>"100"));
?>
  • "!" - for strings – an expression that does not fall within a mask, or unequal (for other types of fields).
<?
// find elements in which the name does not begin with "#"
$res = CIBlockElement::GetList(Array(), Array("!NAME"=>"#%"));
?>
  • "?" - using the logics, works only for string properties.
<?
// find elements in which the name contains "One" or "Two"
$res = CIBlockElement::GetList(Array(), Array("?NAME"=>"One | Two"));
?>
  • "<" - less;
  • "<=" - less or equal;
  • ">" - more;
  • ">=" - more or equal.
<?
// find elements in which the name begins with "A"
$res = CIBlockElement::GetList(Array(), Array(">=NAME"=>"A", "<NAME"=>"B"));

// find elements with an identifier of more than 100
$res = CIBlockElement::GetList(Array(), Array(">ID"=>"100"));
?>
  • "=" - equal;
  • "!=" - non-equal.
<?
// find elements in which the name is equal to "ELEMENT%1"
$res = CIBlockElement::GetList(Array(), Array("=NAME"=>"ELEMENT%1"));
?>
  • "%" - substring;
  • "!%" - not a substring.
// find elements in which the name contains the sequence "123"
$res = CIBlockElement::GetList(Array(), Array("%NAME"=>"123"));
  • "><" - between;
  • "!><" - not between.

As an argument, these types of filters admit an array ("value FROM", "value TO")

<?
// ind elements in which the name begins between "A" and "B" or between "D" and "E"
$res = CIBlockElement::GetList(Array(), Array("><NAME"=>Array(Array("A", "B"), Array("D", "E"))));

// find elements in which the activity start date is outside the year 2003
$res = CIBlockElement::GetList(Array(),
                               Array("!><DATE_ACTIVE_FROM"=>
                                     Array(date($DB->DateFormatToPHP(CLang::GetDateFormat("FULL")), 
                                                mktime(0,0,0,1,1,2003)),
                                           date($DB->DateFormatToPHP(CLang::GetDateFormat("FULL")), 
                                                mktime(0,0,0,1,1,2004)))));
?>

Some Specific Cases of Sorting

$arFilter = array("PROPERTY_CML2_SCAN_CODE"=>false ) - is used to select all elements with an empty property; 
$arFilter = array("PROPERTY_CML2_SCAN_CODE"=>"" ) - is used to select all elements;  
$arFilter = array("PROPERTY_CML2_SCAN_CODE"=>"qwe" ) - during element sorting, the exact match of a property with the preset string is checked; 
$arFilter = array("?PROPERTY_CML2_SCAN_CODE"=>"qwe" ) - during element sorting, the availability of preset substring in a property is checked;
$arFilter = array("!PROPERTY_CML2_SCAN_CODE"=>false ) - is used to select only elements with a property filled in; 
$arFilter = array("!PROPERTY_CML2_SCAN_CODE"=>"qwe" ) - during element sorting, the absence of the exact match with the preset string is checked; 
$arFilter = array("!?PROPERTY_CML2_SCAN_CODE"=>"qwe" ) - during element sorting, the absence of the preset substring in a property is checked. 

Sorting Set Up to Display Related Elements

Task: Let us assume that there are 2 infoblocks that are interrelated by one of the properties. How should we set up the sorting so that among the infoblock elements only related elements can be displayed?

Solution:

<? 
  $arrFilter = array(); 
  $arrFilter['!PROPERTY_<property_code>'] = false; 
?>

Sorting Set Up Using a "Date/Time" Type of Property

A "Date/time" type of property is stored as string in the format YYYY-MM-DD HH:MI:SS, That is why the value for sorting is formed as follows:

$cat_filter[">"."PROPERTY_available"] = date("Y-m-d");





Courses developed by Bitrix24