Problems, need help? Have a tip or advice? Post it here.
6 posts Page 1 of 1
Hi there! Have searched the forum and documentation to no avail, and have also tried various things that simply do not work (including what I thought was a fairly simple answer on this forum!)

Quick explanation of the site I have - there are lots of template pages, and the cloned pages can be 'tagged' with certain steps in a process. For each of these template pages there can be a cloned page called 'Overview' which provides an overview of all the other pages, and allows users to filter pages by the aforementioned tags by clicking various steps within the overview. This is pertinent because, as one would expect, the overview pages contain a lot of 'keywords' one might search for, but absolutely no relevant information about those keywords.

Whenever I use the search function for any relevant word, multiple Overview pages are in the results because they all contain these keywords. I would really REALLY like to exclude these pages from the search results. Note: for the additional functionality of the website to work, these pages must be page_name 'overview'. This, therefore, is a reliable filter!

My search page currently looks like this:
Code: Select all
<div class="col-xl-12 py-sm-2" id="searchpage">
    <div class="col-12"><h1> Search results: </h1></div>
    <div class="row" id="searchresults">
        <cms:search limit='10' >
            <cms:if k_paginated_top >
                <div class="col-12">
                    <cms:if k_paginator_required >Page <cms:show k_current_page /> of <cms:show k_total_pages /><br></cms:if>
                    <cms:show k_total_records /> Pages Found - displaying: <cms:show k_record_from />-<cms:show k_record_to />
                </div>
            </cms:if>
            <div class="col-xl-3 col-lg-4 col-md-6 my-2">
                <div class="card shadow searchresult">
                    <h3 class="card-header"><a href="<cms:show k_page_link />"><cms:show k_search_title /></a></h3>
                    <div class="card-body">
                        <p class="card-text"><cms:show k_search_excerpt /></p>
                    </div>
                </div>
            </div>
            <cms:paginator />
        </cms:search>
    </div>
</div>

What I wanted to do was amend the search to exclude page_name 'overview'. So I tried this:

Code: Select all
<cms:search limit='10' page_name='NOT overview' >

This did not work. So I did more digging, and found that this can be done when using the 'pages' tag. The write-up for the search tag suggests that most of the functionality of the pages tag is also available within the search tag. I also tried

Code: Select all
<cms:search limit='10' id='NOT 27' >

just to test whether I could exclude a given page, but page id 27 still came up in the results. I must therefore assume I am going about this the wrong way.

Help please?

Thank you

Anthony
Anthony, did you also see this topic? viewtopic.php?f=4&t=12562&start=0
My own research shows that you are wrong and tag <cms:search> does not support param id.
Easy to test this assumption by checking an SQL query generated for the search.

I had to create a special code involving php handling situations where search must be limited to certain ids - it also applies to your situation because you can have such list of valid ids (those without 'overview' in name) prebuilt with <cms:query>. Code is for sale and is not on forum, but I provided an explanation in the topic linked above on how to create the code in php for other people to know where to look.

In short, CouchCMS does not support yet filtering out pages by partial match with tag <pages> i.e. exclude pages that contain 'overview' in page name, also Couch does not support search being limited to certain pages or have certain pages excluded from search - the control is on template level, not page level.
That said, I know that constraints are often not needed if functionality can be redistributed across templates - maybe you can restructure your app to avoid such mix of pages and consequent issues.
Thanks trendoman

I chose CouchCMS because it's free, and this is an entirely non-profit project that I am working on. Best of luck selling your add-on (perhaps, if you have many for sale, you could provide a catalogue of these so that we could all see what add-ons we might be willing to part with some money for!)

In the end, I have gone for a rather sloppy fix:

Firstly, I have removed as much text from the 'overview' pages as possible, so that they are extremely unlikely to come up in a search.

Secondly, I have amended my code so that if a result has the name 'overview' it is simply not output as anything on screen. This works fine, except that
a) it counts towards the 'limit' which means that whichever page of results it should be on actually displays fewer results than it should;
b) the number of search results reported as having been found is higher than the amount of results shown, and;
c) it may cause a blank page of results if that page would only have had 'overview' pages on it.

My amended code looks like this:
Code: Select all
<div class="col-xl-12 py-sm-2" id="searchpage">
    <div class="col-12"><h1> Search results: </h1></div>
    <div class="row" id="searchresults">
        <cms:search limit='10'>
            <cms:if k_paginated_top >
                <div class="col-12">
                    <cms:if k_paginator_required >Page <cms:show k_current_page /> of <cms:show k_total_pages /><br></cms:if>
                    <cms:show k_total_records /> Pages Found - displaying: <cms:show k_record_from />-<cms:show k_record_to />
                </div>
            </cms:if>
            <cms:if k_page_name != 'overview'>
            <div class="col-xl-3 col-lg-4 col-md-6 my-2">
                <div class="card shadow searchresult">
                    <h3 class="card-header"><a href="<cms:show k_page_link />"><cms:show k_search_title /></a></h3>
                    <div class="card-body">
                        <p class="card-text"><cms:show k_search_excerpt /></p>
                        <p class="card-text"><cms:show k_page_title /><cms:show k_page_id /><cms:show k_page_name /></p>
                    </div>
                </div>
            </div>
            </cms:if>
            <cms:paginator />
        </cms:search>
    </div>
</div>


I tried to fix the numbers problem by trying to count the number of excluded results - I tried a <cms:else /><cms:incr overviewcount 1> kind of thing - and then introduced a <cms:decr k_total_records overviewcount /> but to no avail. I will simply have to hope people don't pay too much attention to the number of results reported compared to the number of results on screen.
Thanks Anthony :)

I chose CouchCMS because it had a nice gallery concept - I quickly integrated a dynamic gallery to our simple hand-made website and that was it. I enjoyed tutorials so much that I said to myself I can learn that too. It gradually become my inspiration and source of wide knowledge about everything web. Right now I am hugely investing into study OOP PHP.

CouchCMS was not free for me since the beginning - I poured into myself countless coffee over the years.

Your numbers problem (only in part with on-screen results) is quickly solved by javascript - count not-hidden divs on screen.
Hi trendoman

I appreciate your meaning, and in much the same way this non-profit project has not been free for me either! Web hosting, domain registration, time spent coding, troubleshooting, meetings and yes, of course, coffee!! :D

Thanks for the idea of a javascript solution - however, unless I'm much mistaken, the 'limit' portion of the search tag is handled server side prior to output to the DOM, so I would not be able to amend this, therefore javascript would only be able to reduce the displayed number of 'results' and 'results per page' and would therefore only achieve a partial fix. Unless there is some way to actually handle the php side, and return '10' results which are 'NOT overview', I think it will suffice to leave it as it is - I would hate for 11 results to come out, 2 of them to be hidden, java fixes the numbers, and I end up with a user seeing:

9 results found
displaying results 1 to 9
*shows 8 results*
<< prev | 1 | 2 | next >>

I just know this would lead to several emails back and forth trying to explain what the heck was going on!

Thanks again!

Anthony
Server-side issue, as you correctly noted, is not mitigated completely by frontend's javascript. Ask a friend to help with SQL query - there is not much to be changed - then server will correctly fetch what's necessary with <cms:query>.

Meanwhile consider "infinite" scroll for search results without showing paginated numbers - only a button 'load more'.
6 posts Page 1 of 1