Posts by hus_hmd

    get_filtered_listing() should render the template for you. So you don't need to render it inside my_sample_listing().


    Take it one step at a time and iterate on your changes. You've added get_filtered_listing() and you can see the database query it's making in your debug message. I'm assuming you have some rows in the table perch3_my_sample_things.


    The next step for you would be to check what get_filtered_listing() returns. You're assigning what it returns to the variable $filtered_things. Inspect what this variable holds. Is it what you expect?



    This may help:

    If you enable debug mode, what does the debug message say?


    You can add marks to the debug message so it's easier to spot the relevant lines:


    PHP
    1. PerchUtil::mark('Start');
    2. $Things = new MySample_Things($API);
    3. $filtered_things = $Things->get_filtered_listing($opts);
    4. PerchUtil::mark('End');


    You can refer to first-party apps like the Blog app to see how they handle the filtered listing. Though they may include code that isn't relevant to your app.

    You can either write your own database queries (check the database API reference) or you can use PerchFactory's get_filtered_listing().


    A simplified version of what your code could be:


    PHP
    1. $Things = new MySample_Things($API);
    2. $filtered_things = $Things->get_filtered_listing($opts);

    Hello Stephen Meehan


    I would use perch_content_custom() to output all the project meta tags:


    PHP
    1. perch_content_custom('Projects', [
    2. 'page' => '/projects/index.php',
    3. 'template' => '_core/_core-double/projects--meta.html',
    4. 'filter' => 'slug',
    5. 'match' => 'eq',
    6. 'value' => perch_get('s'),
    7. 'count' => 1,
    8. ]);


    And you can rely on conditional tags inside the template for the check you're currently performing in PHP.

    ---

    Back to your code. PHP's isset() checks whether a variable has been set (i.e. has a value). If seo_description has some white space (or an empty string) then isset() would return true.

    Hello,


    Adding the editable attribute to a slug tag allows us to edit the slug:


    HTML
    1. <perch:content id="name" type="text" label="Name" title required>
    2. <perch:content id="slug" type="slug" for="name" label="URL segment" editable>


    However, the field accepts non-URL friendly characters. It would be nice if the editor isn't able to enter any non-URL friendly characters in this case.


    I think it makes sense to have some front-end validation or input patterns/mask to ensure the editor only enters URL-safe slugs. One less thing for the editor to remember, one less thing for the developer to teach the editor and one less thing that can go wrong (broken URL).


    Even though I agree that if the site maintainer isn't tech-savvy enough to customise the URL slug, it's probably better for everyone not make the slug editable. However, some sites have more than one maintainer/editor (especially multi-lingual sites) and some may be more tech-savvy than others.

    You can add page resources (e.g. Javascript, CSS) wherever your custom field type is used by adding the add_page_resources() function to your class.


    I'd probably load the JS library as well as a custom script to apply the mask to the fields based on attributes on the <input>:


    PHP
    1. public function add_page_resources() {
    2. $Perch = Perch::fetch();
    3. $Perch->add_javascript(PERCH_LOGINPATH . "/addons/fieldtypes/maskedinput/assets/vendor/imask.js");
    4. $Perch->add_javascript(PERCH_LOGINPATH . "/addons/fieldtypes/maskedinput/assets/js/app.js");
    5. }


    Assuming your <input> is something like this:


    HTML
    1. <input type="text" data-masked-input="+{7}(000)000-00-00">



    You can apply the masks like so:


    JavaScript
    1. var maskedInputs = document.querySelectorAll('[data-masked-input]');
    2. maskedInputs.forEach(element => {
    3. var maskOptions = {
    4. mask: element.dataset.maskedInput
    5. };
    6. var mask = new IMask(element, maskOptions);
    7. });

    dunc - Your input is very much appreciated.


    I decided to test the approach of creating a database table with the filterable fields and querying it instead of using perch_collection().

    The results so far are very encouraging. Tested some of the queries that used to take a few seconds; with the new approach they now take a fraction of a second. I'm yet to test some of the more complex queries, but it seems this approach will get me the results I'm looking for.


    I'm not ruling out using something like Elasticsearch (for search at least), but I may test it at a later stage.



    Thanks drewm, dunc

    Sounds reasonable. So it seems this means I'd have to get the fields I want to push into Elasticsearch from itemJSON:


    PHP
    1. $API->on('region.index', function(PerchSystemEvent $Event){
    2. $fields = json_decode($Event->subject->itemJSON());
    3. // do stuff
    4. });


    I guess I can also use the same method to populate each item into a database table (with each filterable field as a column) and query that table when looking up items. Would your recommendation still be to use something like Elasticsearch? (I'm feeling an "it depends" answer coming :S)

    Hello,


    I have a Runway installation. The collection_index table has over 900,000 rows now. I'm only indexing the fields that I need for filtering/sorting.


    So I have some performance issues. Particularly with perch_collection(). Pages that perform simple filtering with perch_collection() and get visited more frequently are fast to load though, so I'm assuming that's the result of SQL caching.


    There are currently ~2300 items for all Collections. The site integrates with an external source to import new items and update existing ones which happens frequently. So the table keeps growing.


    Although I'm trying to avoid this, but I may also have to import 20k+ archived items.

    I'm trying to study what I can do to improve the performance here. Should I reach for something like Elasticsearch and use its queries instead of perch_collection()? Or should I perhaps build my own app so my database tables would have columns for each field I need for filtering/sorting (and fewer rows)? Is there something else I should be considering?