Jump to content
Zeka

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

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.

Share this post


Link to post
Share on other sites

@LostKobrakai 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? (I guess the answer will be like - read source code 🙂 ).

  • Haha 1

Share this post


Link to post
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

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...