jose-mdz / Fragment

A super productive CMS
GNU General Public License v3.0
2 stars 2 forks source link

Page::search behavior of filters should behave different #19

Open jose-mdz opened 7 years ago

jose-mdz commented 7 years ago

This is kind of a biggie. The behavior of Page::search may need to be radically changed.

Case & Point: Retrieve pages about smartphones and smartwatches looks like this:

<?php
  // Get pages about smartphones and pages about smartwatches
  $result = Page::search(array(
    'filters' => array(
       array('gadget', 'smartphone')
       array('gadget', 'smartwatch')
    )
  ));

Which is the equivalent of saying something like:

WHERE 
  page.gadget  ==  'smartphone' OR page.gadget  ==  'smartwatch'

But what happens when we want the effect of writing:

WHERE 
  page.gadget  ==  'smartphone' AND page.gadget  ==  'smartwatch'

This is where it gets confusing. The code to achieve this in a search, looks like this:

<?php
  // Get pages about smartphones of brand apple
  $result = Page::search(array(
    'filters' => array(
       array(
         'group' => array(
           array('gadget', 'smartphone')
         )
       ),
       array(
         'group' => array(
           array('brand', 'apple')
         )
       ),
    )
  ));

This may be due to a bad programming & testing. Though, this needs fix, in order to work like the following case:

Proposed Solution

To achieve A OR B I'm assuming this is a less frequently used kind of search, so it's the one needing more syntax writing.

<?php
  // Get pages about smartphones or pages  about smartwatches
  $result = Page::search(array(
    'filters' => array(
       array(
         'group' => array(
           array('gadget', 'smartphone'),
           array('gadget', 'smartwatch')
         )
       )
    )
  ));

To achieve A AND B Since this is the more used kind of filtering, it's the more natural one.

<?php
  // Get pages about smartphones and pages about smartwatches
  $result = Page::search(array(
    'filters' => array(
       array('gadget', 'smartphone')
       array('gadget', 'smartwatch')
    )
  ));

The problem with this change is backwards compatibility. I'm assuming this is still possible because the short size of the ecosystem of Fragment Installs.

jose-mdz commented 7 years ago

Tip : Use of operator INTERSECT in mysql