Jest

Selector error depending on order of selector

Recommended Posts

Posted (edited)

Hi all,

today I've run into some strange error when using selectors. The following selector works fine:

$pages->find('template=TemplateName, (many|of|different|fields*=Searching), (year=Searching), (year>=1941, year<=1960), author*=unknown, publisher*="two, maybe three words"|unknown|"another two, maybe three words", area*=All');

Whereas this one throws an error:

$pages->find('template=TemplateName, (many|of|different|fields*=Searching), (year=Searching), (year>=1941, year<=1960), author*=unknown, publisher*="two, maybe three words"|unknown, area*=All');

The only difference is in publisher field having only two values. The error is Exception: Unknown Selector operator: '' -- was your selector value properly escaped?

 Additional info:

  • ProcessWire 3.0.62
  • All values are sanitized using $sanitizer->selectorValue(string)
  • publisher value usually has commas or parenthesis
  • publisher="one, two"|"three, four" works
  • publisher="one, two"|three|"four, five" works
  • publisher="one, two"|five doesn't work
  • publisher=five works

The only conclusion I can make is the selector fails when the last value of publisher is a single word. Any thoughts?

All help is greatly appreciated!

Jan

Edited by Jest
added PW version

Share this post


Link to post
Share on other sites

I checked the behavior, and i cannot reproduce it with the following code:

$pages->find('template=project, title*="two, maybe three words"|unknown, longtext!=blubb');

 and it works like a charm... (using Dev Version: 3.0.92)

Share this post


Link to post
Share on other sites

That's interesting - your code doesn't work for me.

The same error Exception: Unknown Selector operator: '' -- was your selector value properly escaped? is shown. If I add another value to the title field (title*="two, maybe three words"|unknown|"another unknown") it works until the longtext part. There it shows an error Exception: Field does not exist: longtext. But if I remove the longtext selector and run this:

$pages->find('template=project, title*="two, maybe three words"|unknown');

It still doesn't work.

Is it possible my hosting environment is the reason for this??

Share this post


Link to post
Share on other sites

@Jest does the following works instead?

$pages->find("template=project, title*='two, maybe three words'|unknown");
//or
$pages->find('template=project, title*=\"two, maybe three words\"|unknown');

 

  • Thanks 1

Share this post


Link to post
Share on other sites

Now here's the funny thing: if I wrap the single word value in quotation marks it works.

So this doesn't work

$pages->find('template=project, title*="two, maybe three words"|unknown');

But this does work

$pages->find('template=project, title*="two, maybe three words"|"unknown"');

I've managed to make my code work by checking the number of words in a selector value and if there's only one word I wrap the value in quotation marks.

But it still bugs me why it doesn't work without quotation marks. I'll dig deeper and post the findings, if there will be any.

And thank you guys for your contributions!

Share this post


Link to post
Share on other sites
2 hours ago, Jest said:

There it shows an error Exception: Field does not exist: longtext. But if I remove the longtext selector and run this:

The Field longtext is in my dev installation ;) its just a fieldname created by me

but you can test it with the current dev Version (the dev Version will be the the Master Version in „some“ Weeks (?))

  • Thanks 1

Share this post


Link to post
Share on other sites
6 hours ago, Jest said:

The only conclusion I can make is the selector fails when the last value of publisher is a single word. Any thoughts?

It's a known issue that was fixed in 3.0.80.

  • Like 4
  • Thanks 1

Share this post


Link to post
Share on other sites

@zoeck Yep, I realized why the longtext is causing error... right after I posted the reply :huh: As @BitPoet stated the current dev version fixes this bug, but I'm going to stay on master 3.0.62 since the site will probably be in production sooner than the current dev will become master (and I've found the solution).

@Macrura Thanks for suggestion, the code is cleaner using the selector array but it still doesn't work - as expected due to the bug.

@BitPoet Many thanks for giving me the closure! :rolleyes: Now I'll be finally able to sleep ;)

Share this post


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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By celfred
      Hello,
      I'm facing a weird behavior (to me)... Why are these requests not returning the same values ?

        // Test 01 : not working > returns empty $allPlayers = $pages->find("team=$team"); // Returns the 10 players (1 of them has HP=14, others have HP>15, no players have coma=1) $dangerPlayers = $allPlayers->find("(HP<=15), (coma=1)")->sort("coma, HP"); // Returns nothing ??? // Test 02 : Working as expected $dangerPlayers = $pages->find("parent.name=players, team=$team, (HP<=15), (coma=1)")->sort("coma, HP"); // Returns the low HP player
      If you can explain this to me, I would appreciate because this is causing me a headache right now 🙂 
      Thanks !
    • By j__
      On a site that lists events, I am using a repeater field 'event_time', which contains two Inputfield Time fields 'event_time_start' and 'event_time_end'. Some events take place multiple times, others just once. Here's an example for the data structure:
      event1 title: First Event event_time (1): event_time_start: 08:00 event_time_end: 09:00 event2 title: Second Event event_time (1): event_time_start: 08:00 event_time_end: 09:00 event_time (2): event_time_start: 14:00 event_time_end: 18:00 event3 title: Third Event event_time (1): event_time_start: 07:00 event_time_end: 09:30 First, I'd like to generate a list of all events, sorted by event_time_start, with every repeater item added as an actual event (similar to a SQL JOIN clause). The desired output would be:
      07:00-09:30 Third Event 08:00-09:00 First Event 08:00-09:00 Second Event 14:00-18:00 Second Event A selector like
      $pages->find('template=event,event_time.event_time_start!=,sort=event_time.event_time_start'); would only return each event page once:
      07:00-09:30 Third Event 08:00-09:00 First Event 08:00-09:00 Second Event without
      14:00-18:00 Second Event Is there a possible alteration of the selector to take all different occurrences into account?
      Also I'd like to filter for events taking place in the morning, using a selector like:
      $pages->find('template=event,event_time.event_time_start>=06:00,event_time.event_time_start<=12:00,sort=event_time.event_time_start'); However, this would only return each 'event' page, which then contains also the afternoon version of event2.
      While I have the impression these are rather simple tasks, I struggle finding a selector-based solution to it. In this example on opening times are some similarities, but it does not deal with multiple occurrences. I'd appreciate your ideas to it.
    • By ridgedale
      Reference: PW 3.0.111 and uikit3 based site using the Regular-Master profile.
      I am trying to add a field that provides a dropdown menu but there are no Options or Selector(s) type available - see attached image of field types available.
      The following reference under the docs does not appear to be applicable any more:
      https://processwire.com/api/modules/select-options-fieldtype/
      I can't see how to achieve this. Any assistance would be appreciated.

    • By Eunico Cornelius
      I am trying to filter my $pages with a find($selector method). 
      $matches = $pages->find($selector); and this is an example of what my selector looks like
      $selector = "include=all, title|body~=$q, limit=50"; In this case, it only searches according to the matching exact words.
      For example:we search="art", the result="art times","these art",....
      Is there any way to search based on the alphabet?
      For example: we search="ab", the result="absolutely correct","abstract art",....
    • By gRegor
      I understand from the selectors documentation:
      I have a repeater field `promo_codes` consisting of text field `title` and an integer field `number1`. I'm running a find:
      $page->promo_codes->find('title=gmtest'); The database column collation is `utf8_general_ci` so I would expect this to work, but it only works when I match the case exactly ("GMTEST").
      This is on PW 3.0.42. Any ideas? Is there an exception for finds on repeater fields?