Problems, need help? Have a tip or advice? Post it here.
3 posts Page 1 of 1
Hey KK et all,
I'm using the native Couch search functionality and everything works great, except for the fact that at the end of the search excerpt, some date and time is getting outputted via the k_search_excerpt tag, and I'm unsure why that is happening.
I've attached an image of 2 search results and the code snippets.
Image

The following goes in my base.html file, which all templates use.
Code: Select all
<cms:form method="get" action="<cms:link 'search.php' />" anchor='0'>
  <div class="d-flex">
    <cms:input type="text" value="" name="s"  class="form-control" placeholder="Search" />
      <button type="submit" value="Go" name='submit' class="btn"><img src="assets/images/icons/search.svg" alt="" class="icon-search-header"></button>
  </div>
</cms:form>           


The following goes in the search.php template
Code: Select all
<cms:extends 'base.html' />
<cms:block 'content' >
  <div class="container">
    <cms:block 'page_title'><div class="heading-title mt-5">Search results for <span><cms:search /><cms:show k_search_query /></span></div></cms:block>
    <cms:search limit='10'>
      <cms:if k_paginated_top>
      <div class="font-family-sans-serif pb-4">
        <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="pb-4">
        <h2 class='font-size-xl'><a href="<cms:show k_page_link />"><cms:show k_search_title /></a></h2>
       
        <cms:show k_search_excerpt />
      </div>     
     
      <cms:paginator />
     
      <cms:no_results>
      <div class="font-family-sans-serif pb-4">
        Search query <strong><cms:show k_search_query /></strong> produced 0 results.
      </div>
     
      </cms:no_results>
    </cms:search>
  </div> <!-- /.container -->
</cms:block>
I don't think there is any problem in the code you posted.

What seems to be happening is that the templates the search results are coming from likely have a type 'datetime' editable region and its data is being included in the results.

Please check if that is so.
If yes, you can stop this from happening by adding searchable='0' to those editable regions' definitions (making sure to visit the modified templates as super-admin for the change to persist).

Unfortunately, the change will apply only to the pages that are created from this point onwards - the search data for existing pages is already present in the database. To create that data anew, you'll have to visit each page in admin-panel, make some dummy change and click 'save'. This save process will regenerate the search data and this time it should skip the non-searchable regions.

Hope this helps.
@KK. Thanks! I understand now, and it works! This is just local testing for a site I'm working on, so not an issue at all. I didn't know about the searchable="0" options, which is a nice to have if you just need a couple of editable fields to not be searched in a template. Thanks again :)
3 posts Page 1 of 1
cron