Jump to content
bernhard

RockFinder - Highly Efficient and Flexible SQL Finder Module

Recommended Posts

56 minutes ago, dragan said:

a) I can't get any RF output (arrays, objects) to play nice with PW's pagination / renderPager(). I guess pagination expects a PageArray, not just any kind of array. I know RF was never meant to be used in the frontend, but I tried anyway (and of course, I know building my own pagination with something like Tabulator is quite easy). I just wanted to compare an existing page (how much speed I would gain using RF instead of native PF find).

There's nothing wrong with using RF for the frontend, but you are right, pagination was not on my list. And I don't think we will ever need it for RockFinder, because if you are using pagination, you can use native PW find operations without any performance drawback.

59 minutes ago, dragan said:

url is not recognized. I guess because a PW page URL is not stored inside the DB as-is, but is created when calling the $page->url() method. Am I correct? (PW has to assemble parents(s), page-names etc.)

Exactly, that's why I implemented the callback feature where you can use the PW API to get any properties of your page via PHP: 

 

Share this post


Link to post
Share on other sites

Hi @dragan, I'm doing the same, using Rockfinder on the frontend, building my own pagination. b), 'url': since you know the parent (1041), you could query 'name' instead of 'url', and add it to the known path.

Share this post


Link to post
Share on other sites

Another option could be to build a redirect page, eg mysite.com/?id=1234 that redirects to this page, eg mysite.com/myparent/mypage - then you can easily and efficiently build your links via the ID property.

Share this post


Link to post
Share on other sites

@Lutz True. But maybe I'll have another setup where I need to query pages that live under different parents, and (theoretically) also could have identical page-names.

@bernhard Now that sounds both easy and awesome (plus "safe", in the sense that a page ID is always unique, while page-names aren't - unless they are children under the same parent page).

I've been playing a bit more with RF... pure awesomeness and fun. Together with Lazy Cron, Tabulator.js and RF, a small test-setup runs incredibly fast. (Lazy Cron to store the RF-output - JSON - once a day). Makes me almost sad I currently don't have a real use-case / client-project to use all this...

Share this post


Link to post
Share on other sites
43 minutes ago, dragan said:

@bernhard Now that sounds both easy and awesome (plus "safe", in the sense that a page ID is always unique, while page-names aren't - unless they are children under the same parent page).

Yeah - I've too often had to build complicated RockFinder queries and came up with this quick&easy solution one day and couldn't believe I didn't think of it earlier 😄

45 minutes ago, dragan said:

I've been playing a bit more with RF... pure awesomeness and fun. Together with Lazy Cron, Tabulator.js and RF, a small test-setup runs incredibly fast. (Lazy Cron to store the RF-output - JSON - once a day). Makes me almost sad I currently don't have a real use-case / client-project to use all this...

Don't tell anybody, but I've just started developing RockFinder2 with a new syntax that will be even easier to use and more intuitive and powerful 😉 

  • Like 7
  • Thanks 1

Share this post


Link to post
Share on other sites
19 hours ago, bernhard said:

Don't tell anybody

I won't 🙊🙉🙈

I just realized the "view" link in the RF Tester (zooming glass icon) seems to be hard-coded: it's assuming my PW backend is "admin". This should probably be defined dynamically instead (or at least configurable).

Also, I noticed the div.paginationPageSize is always showing "undefined" o_O

  • Like 1

Share this post


Link to post
Share on other sites
12 minutes ago, dragan said:

I just realized the "view" link in the RF Tester (zooming glass icon) seems to be hard-coded: it's assuming my PW backend is "admin".

Thx, fixed in 1.1.5

12 minutes ago, dragan said:

Also, I noticed the div.paginationPageSize is always showing "undefined" o_O

True, but I won't fix this as it's not critical and I want to focus on RockFinder2 + RockTabulator 🙂 

  • Like 2

Share this post


Link to post
Share on other sites

Is there an efficient way to get the template name or at least the template ID in the RockFinder results? I'm doing a query for all children of a particular page and those children can have different templates and I need to know which template each page has.

Excellent module btw 👍

Share this post


Link to post
Share on other sites

Hi @Marc Thx for that interesting question!

I've pushed a little update so that RockFinder takes a DatabaseQuerySelect object as find() parameter. You can then add your find as a relation to your finder:

NLqnwDt.png

Spoiler

$rf = new RockFinder2();
$rf->find("name=cat-50|dog-50");
$rf->addColumns(['title', 'templates_id']);

$query = new DatabaseQuerySelect();
$query->select('id,name');
$query->from('templates');
$templates = new RockFinder2();
$templates->find($query);
$rf->addRelation('templates', $templates);

db($rf);

 

Relations can be great for options fields or 1:n relationships. In this case we have 1:1 so a join would maybe make more sense (though have in mind that this creates one more row in the main resultset, so if you had 1000 rows that would mean 1000 more data items whereas in the relation it would be only the number of the templates).

You can join ANY sql to your initial finder quite easily. First analyze the query and resulting SQL:

7yp4n2n.png

We need two things:

1) LEFT JOIN the data
2) SELECT the column we need in the base query

UXJOw98.png

Voila 😎

1yq7rX2.png

  • Like 5

Share this post


Link to post
Share on other sites

I would like to try this out so I have just downloaded RockFinder2 from github, however even the simplest test won't work for me:

$rf = new RockFinder2();
$rf->find("parent=1");
$rf->addColumns(["title"]);

Using this on the front end, it generates the error "Uncaught Error: Call to a member function __invoke() on null in /site/modules/RockFinder2/RockFinder2.module.php:746". Also getting this notice: "Trying to get property of non-object in /site/modules/RockFinder2/RockFinder2.module.php on line 801"

RockFinder1 is working properly.

Share this post


Link to post
Share on other sites

Does it work in the backend? Do you have the latest version (git pull)? It looks like $RockFinder2 api variable is not available for you, but it should (the module is autoload).

SOd6fAT.png

  • Like 1

Share this post


Link to post
Share on other sites
16 hours ago, bernhard said:

Does it work in the backend? Do you have the latest version (git pull)? It looks like $RockFinder2 api variable is not available for you, but it should (the module is autoload).

You are correct, RockFinder2 was not available. I installed the module and ignored the TracyDebugger dependency warning. Since it DID successfully install ProcessRockFinder2, I assumed everything was alright. Anyway, I installed the debugger and reinstalled RockFinder2 and now it's up and running. Silly mistake on my part and sorry for bothering you about this!

I got your example of including the template name working, thanks for your help! I hope you won't mind if I ask you another question. The docs for RockFinder2 briefly mention repeaters, and state that columns musts be defined manually. What exactly do you mean by this? Could you provide an example? With RockFinder1 you can do $finder->addField("repeatername", ["fieldname"]) but this is no longer the case with RockFinder2.

Share this post


Link to post
Share on other sites

I haven't had a look into repeaters yet. I'm avoiding them at all for all my projects as they brought up several problems (especially for finding data via RockFinder). I have a lot more control using regular pages for that tasks and using RockGrid / RockTabulator for presentation and as GUI.

Though it should be quite easy to support Repeaters. That's what the concept of relations is for. The column would list the page ids of the repeater pages and the relations would hold the data of those pages (using regular RockFinder2 syntax $repeater->addColumns(['foo', 'bar'])).

If you need further help you can PM me.

  • 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.

  • Similar Content

    • By adrian
      Tracy Debugger for ProcessWire
      The ultimate “swiss army knife” debugging and development tool for the ProcessWire CMF/CMS

       
      Integrates and extends Nette's Tracy debugging tool and adds 35+ custom tools designed for effective ProcessWire debugging and lightning fast development
      The most comprehensive set of instructions and examples is available at: https://adrianbj.github.io/TracyDebugger
      Modules Directory: http://modules.processwire.com/modules/tracy-debugger/
      Github: https://github.com/adrianbj/TracyDebugger
      A big thanks to @tpr for introducing me to Tracy and for the idea for this module and for significant feedback, testing, and feature suggestions.
    • By adrian
      This module allows you to automatically rename file (including image) uploads according to a configurable format
      This module lets you define as many rules as you need to determine how uploaded files will be named and you can have different rules for different pages, templates, fields, and file extensions, or one rule for all uploads. Renaming works for files uploaded via the admin interface and also via the API, including images added from remote URLs.   Github: https://github.com/adrianbj/CustomUploadNames
      Modules Directory: http://modules.processwire.com/modules/process-custom-upload-names/
      Renaming Rules
      The module config allows you to set an unlimited number of Rename Rules. You can define rules to specific fields, templates, pages, and file extensions. If a rule option is left blank, the rule with be applied to all fields/templates/pages/extensions. Leave Filename Format blank to prevent renaming for a specific field/template/page combo, overriding a more general rule. Rules are processed in order, so put more specific rules before more general ones. You can drag to change the order of rules as needed. The following variables can be used in the filename format: $page, $template, $field, and $file. For some of these (eg. $field->description), if they haven't been filled out and saved prior to uploading the image, renaming won't occur on upload, but will happen on page save (could be an issue if image has already been inserted into RTE/HTML field before page save). Some examples: $page->title mysite-{$template->name}-images $field->label $file->description {$page->name}-{$file->filesize}-kb prefix-[Y-m-d_H-i-s]-suffix (anything inside square brackets is is considered to be a PHP date format for the current date/time) randstring[n] (where n is the number of characters you want in the string) ### (custom number mask, eg. 001 if more than one image with same name on a page. This is an enhanced version of the automatic addition of numbers if required) If 'Rename on Save' is checked files will be renamed again each time a page is saved (admin or front-end via API). WARNING: this setting will break any direct links to the old filename, which is particularly relevant for images inserted into RTE/HTML fields. The Filename Format can be defined using plain text and PW $page variable, for example: mysite-{$page->path} You can preserve the uploaded filename for certain rules. This will allow you to set a general renaming rule for your entire site, but then add a rule for a specific page/template/field that does not rename the uploaded file. Just simply build the rule, but leave the Filename Format field empty. You can specify an optional character limit (to nearest whole word) for the length of the filename - useful if you are using $page->path, $path->name etc and have very long page names - eg. news articles, publication titles etc. NOTE - if you are using ProcessWire's webp features, be sure to use the useSrcExt because if you have jpg and png files on the same page and your rename rules result in the same name, you need to maintain the src extension so they are kept as separate files.
      $config->webpOptions = array(     'useSrcExt' => false, // Use source file extension in webp filename? (file.jpg.webp rather than file.webp) ); Acknowledgments
      The module config settings make use of code from Pete's EmailToPage module and the renaming function is based on this code from Ryan: http://processwire.com/talk/topic/3299-ability-to-define-convention-for-image-and-file-upload-names/?p=32623 (also see this post for his thoughts on file renaming and why it is the lazy way out - worth a read before deciding to use this module). 
       
       
      NOTE:
      This should not be needed on most sites, but I work with lots of sites that host PDFs and photos/vectors that are available for download and I have always renamed the files on upload because clients will often upload files with horrible meaningless filenames like:
      Final ReportV6 web version for John Feb 23.PDF

    • By Mike Rockett
      Jumplinks for ProcessWire
      Release: 1.5.56
      Composer: rockett/jumplinks
      Jumplinks is an enhanced version of the original ProcessRedirects by Antti Peisa.
      The Process module manages your permanent and temporary redirects (we'll call these "jumplinks" from now on, unless in reference to redirects from another module), useful for when you're migrating over to ProcessWire from another system/platform. Each jumplink supports wildcards, shortening the time needed to create them.
      Unlike similar modules for other platforms, wildcards in Jumplinks are much easier to work with, as Regular Expressions are not fully exposed. Instead, parameters wrapped in curly braces are used - these are described in the documentation.
      Under Development: 2.0, to be powered by FastRoute
      As of version 1.5.0, Jumplinks requires at least ProcessWire 2.6.1 to run.
      View on GitLab
      Download via the Modules Directory
      Read the docs
      Features
      The most prominent features include:
      Basic jumplinks (from one fixed route to another) Parameter-based wildcards with "Smart" equivalents Mapping Collections (for converting ID-based routes to their named-equivalents without the need to create multiple jumplinks) Destination Selectors (for finding and redirecting to pages containing legacy location information) Timed Activation (activate and/or deactivate jumplinks at specific times) 404-Monitor (for creating jumplinks based on 404 hits) Additionally, the following features may come in handy:
      Stale jumplink management Legacy domain support for slow migrations An importer (from CSV or ProcessRedirects) Feedback & Feature Requests
      I’d love to know what you think of this module. Please provide some feedback on the module as a whole, or even regarding smaller things that make it whole. Also, please feel free to submit feature requests and their use-cases.
      Note: Features requested so far have been added to the to-do list, and will be added to 2.0, and not the current dev/master branches.
      Open Source

      Jumplinks is an open-source project, and is free to use. In fact, Jumplinks will always be open-source, and will always remain free to use. Forever. If you would like to support the development of Jumplinks, please consider making a small donation via PayPal.
      Enjoy! :)
×
×
  • Create New...