Sign in to follow this  
activestate

Searching fot term in repeater.

Recommended Posts

Hi,
I'm having problems with seatching for a value in repeater.
One of pages have attached repeater called 'insight_repeater'.
This repeater has h1_tag (text field) and i'm trying to search for repeater items that contains 'lor' phrase.

And right now i'm trying to do simple search, looking for phrase 'lor'. I've tried many approaches, but nothins seems to work, so i want to ask what i'm doing wrong here:

<?php $query = $page->get("insight_repeater")->find('h1_tag~=Lor'); ?>

Thanks for help.
 

Share this post


Link to post
Share on other sites
3 minutes ago, kixe said:

Hi @kixe !

Thanks for fast reply, but what is the difference between those two as both uses $pages ? (not $page and $pages).
get() will get repeater from current page, and find() will search in whole project ?
Cheers.

 

Share this post


Link to post
Share on other sites

I've just checked this.
first case returns:
noticee: trying to get property on non object in...

and the second returns nothing ...
I'm using latests dev version.

Cheers.

Recently, i see that my code is actually working, but if h1_tag contains "Lorem" i'm only able to make this work if i'll type:

<?php $query = $page->get("insight_repeater")->find('h1_tag~=Lorem'); ?> and not Lor. Is there any workaround ?

Share this post


Link to post
Share on other sites

One strange thing is:

This page, that containes insight_repeater also have h1_tag, and this query will return page's h1_tag instead of repeater's h1_tag:


 

<?php $query = $pages->find("insight_repeater.h1_tag~=Lorem"); ?>

 

Share this post


Link to post
Share on other sites
3 hours ago, activestate said:

<?php $query = $page->get("insight_repeater")->find('h1_tag~=Lorem'); ?> and not Lor. Is there any workaround ?

Welcome to the forums @activestate

Have a read here about selectors, specifically about MySQL and short words.

Quote

The *= and ~= rely upon MySQL fulltext indexes, which only index words of at least a certain length (configurable, but typically 4 characters). They also don't index common English words called stopwords. So while it's preferable to use *= and ~= for their speed, if you aren't getting the results you need, you should consider using %= instead (if you can handle the speed hit).

 

Please use code blocks (@see the <> icon) around your code.

  • Like 3
  • Thanks 1

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By burning
      Hi All, maybe a really stupid question, but is there a way to sort repeater items on -created?
      Like $page->social_activity('limit=10,sort=created'), with 'social_activity' as the repeater field?
      Tried this but it didnt work 😞 
      Any help appreciated! 
    • By verdeandrea
      Hello girls and guys,
      i just saw that if I use a selector on a textarea, for example 
      $pages->find('body%=notes') it also find that key in html classes and attributes. For example it will find
      <p class="text-notes">Lorem ipsum dolor sit amet cosectetur.</p> Is there a way to avoid this anche check only the texts without the html tags?
      Thanks!
    • By theoretic
      Hello there! And thanks for Processwire.
      Got one more interesting question. One of my templates called goods has two repeaters. The first one is variants, each item containing possible sizes, colors and so on. The second one is available_variants, each item should contain a region and a variant which should be selectable from the list of variants.
      So the task is to get items of one repeater from inside the page reference field which is the part of another repeater, both repeater belonging to the same page.
      Processwire gives some options for retrieving selectable pages in this case. We can use:
      Parent. Not an option because we need dynamic parent being in fact the current page which contains both repeaters. Template. Not an option again because we need to select repeater items not only by template but also by page id which is dynamic. Custom find. Could be a solution but have no idea how to substitute the current page id into ID query. Selector string. It's almost what we need, but again i have no idea how to substitute something like "parent={$parent->id}" in this case. Custom PHP code. This needs to be placed inside site/ready.php and should contain a hook which finds pages using all the power of PW API. Think that the last option is the solution, but could not get the result i need.
      The simplest possible way seems to use $event->arguments('page')->variants. But it returns nothing. Tried different selectors like "template=repeater_variants, parent=".$event->arguments('page')->id , but still no result.
      Will be grateful for any help. Thanks in advance!
    • By ivineets
      Hi,
      Whenever I try to create a repeater field on my website, I get following error:
      General error: 3161 Storage engine MyISAM is disabled (Table creation is disallowed).
      If I still continue, it creates the field but doesn't allow storing any kind of data. How do I resolve this?  Is there any alternative to repeatable content that I can use?
       
      Thanks for your time.
       
       
    • By ethanbeyer
      Hello,
      I recently posted in this topic, but I decided to start my own thread because while I believe my issue is related to the one in that thread, they are not exactly the same:
       
      I have created a custom User Template in the method outlined in the docs. I am creating a directory, so it made sense that every page in the directory was a Directory Member, so they could log in and edit their own information while also keeping the entire directory protected behind a login wall.
      So the new user type is created: "directory-member".
      I then created two new roles: "member" and "directory-admin":
      The "member" only has the ability to View directory-member pages, and "profile-edit", which allows them to manage their own information. The "directory-admin" has the ability to edit any directory-member pages, and administer users. Some Directory Members are both, but all have at least the "member" role.
      The first hint that something was wrong was when I was testing a "member" user and I could not add a new item to a repeater on that profile. The url for the profile edit (this will be important shortly) is site.dev/admin/profile. The repeater is set up to load new items through AJAX. If this option is turned off, the rest of this issue is no longer completely valid. But as I have found what I believe to be a pretty large issue in the Processwire codebase, I thought it worth bringing up.
      See, every page (even a user) has a $page->editUrl() method, and it returns a URL like this: site.dev/admin/access/users/edit/?id=2096. That's all good and fine for users that have page-edit permissions, but if they don't, that link will resolve to the admin's equivalent of a 404.
      So the way that Processwire currently gets around this is by creating a specific editing area for a user to interact with only their profile: /admin/profile. And that works pretty nicely, except for the fact that nowhere is editUrl() ever made aware of the difference. editUrl() is not hookable, and whether or not a page is editable is based on the PagePermissions module.
      On top of that, there are several core modules that hardcode a search-and-replace (see InputfieldRepeater.module:627) where the editing screen is for Users. This doesn't allow for a huge degree of flexibility that is offered in other places throughout Processwire. If line 627 of InputfieldRepeater is changed from this:
      $editorUrl = str_replace('/access/users/edit/', '/page/edit/', $editorUrl); to this:
      $editorUrl = str_replace('/access/users/edit/', '/profile/', $editorUrl); ...the AJAX repeaters work. It's maddening!
      As is brought up in the thread I attached above, a lot of the features of page editing are missing within /admin/profile/, and it just makes for an altogether strange editing experience. A user who has "page-edit" permissions for templates other than directory-member, but does have "profile-edit" permissions, will see their user in the Page List, but cannot edit their Page unless they hover over the wrench and click the "Profile" link. It just seems - off.
      I think what this hinges on for me is that the editUrl() of the user should be "/admin/profile/" if that user is logged in (and their page should be editable from the Page List), or the "/admin/access/users/edit/" url; regardless of the URL, both links should resolve to the Page Edit screen, as the Profile Edit screen seems to be a unnecessarily neutered version of Page Edit.