I
I
itemashabanov2021-12-23 10:42:35
1C-Bitrix
itemashabanov, 2021-12-23 10:42:35

How to select such elements through GetList() that satisfy all filters at the same time?

Hello. There is an array $search of the type ["errors", "x23", "280", "pt3009"], you need to select those elements in which all these searched values ​​exist simultaneously. Thus, array("=PROPERTY_TAGS" => $search) selects all elements that contain at least one of the searched values. Is it possible by means of GetList(). As I understand it, the complex logic LOGIC => AND is not that?! Tried to do like this:

[
    ["LOGIC" => "AND"],
    ["PROPERTY_TAGS" => "ошибки"],
    ["PROPERTY_TAGS" => "х23"],
    ["PROPERTY_TAGS" => "280"],
    ["PROPERTY_TAGS" => "пт3009"],
  ]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
itemashabanov, 2021-12-23
@itemashabanov

foreach($search as $s) {
  $arSearch[] = array("ID" => CIBlockElement::SubQuery("ID", array("IBLOCK_ID" => 118, "PROPERTY_TAGS" => $s)));
}
$arSearch["PROPERTY_MODELS_AND_PROD_ID"] = $arResult["MODEL_OR_PROD"];
$GLOBALS['tagsFilter'] = $arSearch;

UPDATED:
Still, this method does not work correctly: if you pass several existing tags to an array, and then add a couple of tags that are not in these elements, the database starts to be godlessly dumb.
For such a task, it is better to use the following:
$query = "SELECT IBLOCK_ELEMENT_ID, count(VALUE) cnt from b_iblock_element_prop_m118 where IBLOCK_PROPERTY_ID='2510' AND VALUE in ('".implode("','",$search)."') group by IBLOCK_ELEMENT_ID having cnt=".count($search);
$result = $DB->Query($query);
while($arElement = $result->GetNext()) {
  $arSearch[] = $arElement['IBLOCK_ELEMENT_ID'];
}

In b_iblock_element_prop_m118 118 is the ID of the infoblock, in IBLOCK_PROPERTY_ID='2510' 2510 is the ID of the required property.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question