Jump to content

$page->matches and $pages->find inconsistency


Zeka
 Share

Recommended Posts

Hi.

I can't figurate out is it a bug or I miss something 

$selector = '(template=catalog_category|product), (id=1430|1530|1443|1528|1442|1441|1440|1527|1529|1439|1438|1437|1436|1531|1523|1522|1435|1433|1434)';
$some_pages = $pages->find($selector);
$some_pages->has('id=1417') // true

Then on the page with ID 1417

$page->matches($selector) // false

As you can see that the page with ID 1417 is found by the selector, but do not match it.

Link to comment
Share on other sites

54 minutes ago, Zeka said:

It's not the first time when I met that something works with memory and not DB. Maybe the dumb question, but is there some way to determine it?

It's in the selectors docs (admittedly, in the fine print at the bottom of the relevant section):

Quote

Please note: OR-groups work with database-driven find operations, but not with in-memory filtering (where they are less useful). OR-groups also require ProcessWire 2.5 or newer.

 

  • Like 2
Link to comment
Share on other sites

@Zeka There is many inconsistencies between in-memory and DB. Things being case sensitive etc. I'm recently seeing the inconsistency throw people more and more. As the API is the same - I think it's hard to know what's going to be DB and what's going to be in-memory.

I think there are things that can be done to bring in-memory searches to bring it inline with DB searches. 

For now this should work:

<?php
	$validation = [];
	preg_match_all('/\(([^\)]+)\)/' $selector, $matches);
	foreach($matches[1] as $match) {	
		$validation[] = $page->matches($match);
	}
	if(in_array(true, $validation)) {
		// Page Matches one OR Group.
	}
?>

I haven't tested it, but it should work, might require a little tweaking. 

Or

<?php
	$validation = false;
	preg_match_all('/\(([^\)]+)\)/' $selector, $matches);
	foreach($matches[1] as $match) {
		if(!$validation) {
			$validation = $page->matches($match);
		}
	}
	if($validation) {
		// Page Matches one OR Group.
	}
?>

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...