h4r4ld Posted November 28, 2015 Share Posted November 28, 2015 Hi, I need to get all pages from a template where a searchstring matches any field of the page. $result = $pages->find('template=documentHolder, status=hidden, *=$string'); I know i could do something like $result = $pages->find('template=documentHolder, status=hidden, (field1=$string), (field2=$string), (field3=$string)'); But is there a way to do so without writing down every field the template has? Maybe something like a subselector? Best, Harri Link to comment Share on other sites More sharing options...
LostKobrakai Posted November 28, 2015 Share Posted November 28, 2015 You could just ask the template to give you all fields it does posses: $selector = "..." . $template->fields->implode("|", "name") . "*=$string"; If you can specify all field beforehand you could use FieldtypeCache and add all necessary fields to it. After that you can just search the cache field instead of all other fields. 3 Link to comment Share on other sites More sharing options...
Tom. Posted November 28, 2015 Share Posted November 28, 2015 For what reason would you want to do that? It sounds terribly inefficient. You want every field for the matching template or every field? (edit: Completely misread your post, sorry) You can also do field1|field2|field3=$string, however if you are absolutely set on every field I think you can do. $f = $fields->find("template=documentHolder"); $results = $pages->find("template=documentHolder, status=hidden, $f=$string"); But I'm not absolutely sure, I'm just guessing here after using ProcessWire for a couple of months. edit: LostKobrakai beat me to it His answer will be correct as he is way better than me at this ProcessWire stuff. 1 Link to comment Share on other sites More sharing options...
h4r4ld Posted November 28, 2015 Author Share Posted November 28, 2015 Thanks, exactly what I was looking for. If you can specify all field beforehand you could use FieldtypeCache and add all necessary fields to it. After that you can just search the cache field instead of all other fields. Can you provide some documentation on this? I didn't find anything related? Link to comment Share on other sites More sharing options...
LostKobrakai Posted November 28, 2015 Share Posted November 28, 2015 https://processwire.com/talk/topic/5513-fieldtype-cache-please-elaborate/ 1 Link to comment Share on other sites More sharing options...
h4r4ld Posted November 30, 2015 Author Share Posted November 30, 2015 Ok, that's what I found myself beside this : http://www.flamingruby.com/blog/processwire-caching-explained/ But is there any official documentation? I just recrawled the processwire site to find something without any result. Link to comment Share on other sites More sharing options...
LostKobrakai Posted November 30, 2015 Share Posted November 30, 2015 I doubt there's any official documentation, but there's actually not much more to know about. It combines the string contents of each specified field when the page is saved and stores it encoded in json in the database. The same does happen when a page is loaded to populate the runtime accessable fielddata. If you then search the field and the keyword is somewhere in the json blob, than it's somewhere in your other fields, too. Besides that it's handled just like any other field as well. If you've any further questions just ask them here. 1 Link to comment Share on other sites More sharing options...
h4r4ld Posted November 30, 2015 Author Share Posted November 30, 2015 That would fit quiet well and is what I expected it to do, I just don't found information like: Is this cachefield generated automatically or on demand? If on demand, what do I have to do? Can I select fields which should be in or is it all fields of a template/page? Usage is exactly like a "normal" field in a selector? Link to comment Share on other sites More sharing options...
LostKobrakai Posted November 30, 2015 Share Posted November 30, 2015 Just create one of those fields and most of those will be answered already by the descriptions/notes in the field editing. Essentially you don't have to worry about anything, create the field, add it to a template, save the page once or regenerate the cache by using the option in the field editing interface and add it like any other field to your selector. Now you can essentially forget it's even there. 1 Link to comment Share on other sites More sharing options...
h4r4ld Posted November 30, 2015 Author Share Posted November 30, 2015 I don't see any cache fieldtype? Link to comment Share on other sites More sharing options...
SiNNuT Posted November 30, 2015 Share Posted November 30, 2015 You should probably first install it via Modules->Core, under Fieldtype, -> Cache 1 Link to comment Share on other sites More sharing options...
arjen Posted November 30, 2015 Share Posted November 30, 2015 2 Link to comment Share on other sites More sharing options...
h4r4ld Posted November 30, 2015 Author Share Posted November 30, 2015 You should probably first install it via Modules->Core, under Fieldtype, -> Cache Thanks, that's what I was missing! Link to comment Share on other sites More sharing options...
h4r4ld Posted December 1, 2015 Author Share Posted December 1, 2015 Ok, so I made a cache field like with autojoin on. If I'm right I should be able to do something like $allDocuments = $pages->count("doccache%=".$input->post->request) echo "There are " . $allDocuments . " docs containing your request"; Well, I don't get any results while using request that should match. I tried to add new document pages and regenerated the cache, but that ain't helped. Where's my mistake? Link to comment Share on other sites More sharing options...
Tom. Posted December 2, 2015 Share Posted December 2, 2015 (edited) Ok, so I made a cache field like (img) with autojoin on. If I'm right I should be able to do something like $allDocuments = $pages->count("doccache%=".$input->post->request) echo "There are " . $allDocuments . " docs containing your request"; Well, I don't get any results while using request that should match. I tried to add new document pages and regenerated the cache, but that ain't helped.Where's my mistake? I believe you should be using $allDocuments = $pages->find("doccache%={$input->post->request}"); echo "There are $allDocuments->count() documents containing your request." Edited December 2, 2015 by LostKobrakai stripped image from quote Link to comment Share on other sites More sharing options...
LostKobrakai Posted December 2, 2015 Share Posted December 2, 2015 @Tom. That's actually the same in outcome, just a magnitute worse from the performance standpoint. $pages->count() does let mysql do the counting, whereas your code does first load all found pages to memory and then count them with php. 1 Link to comment Share on other sites More sharing options...
h4r4ld Posted December 2, 2015 Author Share Posted December 2, 2015 Yep, not working with that either. Link to comment Share on other sites More sharing options...
LostKobrakai Posted December 2, 2015 Share Posted December 2, 2015 Would it be possible for you to check the db if the data is actually stored? The table would be field_YourCacheFieldName. Additionally, could you replace the submitted string with a static one, to be sure that's not the root of the issue. Link to comment Share on other sites More sharing options...
h4r4ld Posted December 2, 2015 Author Share Posted December 2, 2015 Gosh, I found it. The template is a hidden page and so I need to specifiy this in the selector. Link to comment Share on other sites More sharing options...
Tom. Posted December 3, 2015 Share Posted December 3, 2015 @Tom. That's actually the same in outcome, just a magnitute worse from the performance standpoint. $pages->count() does let mysql do the counting, whereas your code does first load all found pages to memory and then count them with php. Thank you very much for that Lost, my apologies. I didn't know you could do a selector inside a count. You learn something new every day Link to comment Share on other sites More sharing options...
LostKobrakai Posted December 3, 2015 Share Posted December 3, 2015 I didn't know you could do a selector inside a count. It depends: $pages->count() does work with a selector supplied, whereas $pages->find("some=Pages")->count() doesn't use any parameters, because pages are already loaded to a PageArray. 1 Link to comment Share on other sites More sharing options...
h4r4ld Posted December 11, 2015 Author Share Posted December 11, 2015 I retake my old topic, because it somehow fits from the title. I want to add a dropdowninput field where the dropdown is filled by all given fieldvalues from one field of a template. I just need every value once, so I could do this with some php but I was wondering if PW has a function for that? Link to comment Share on other sites More sharing options...
LostKobrakai Posted December 11, 2015 Share Posted December 11, 2015 $values = array_unique($pages->find("template=…")->explode("myField")); 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now