Problems, need help? Have a tip or advice? Post it here.
2 posts Page 1 of 1
Hello KK,
I tried to use the couch search tag like this:
Code: Select all
<cms:search masterpage='products.php' folder=folder_name_from_querystring keywords=keyword_from_query_string >
   .......
</cms:search>


BUT I realised it's not possible from the documentation I read so I decided to find a way around using PHP and couch query tag. I will like you to see if I used the right approach or there could be a simpler approach

My solution
1. I passed the folder name and the keyword through a query string
Code: Select all
http://localhost/dotmatrix/?folder=phones-wearables&keyword=apple


2. I used the following approach to get the ids of the parent folder and it's subfolders into a variable
Code: Select all
<cms:capture into='product_folder_ids' >
   <cms:folders masterpage="product.php" root='phones-wearables' hierarchical='1'>
      <cms:show k_folder_id />,
   </cms:folders>
</cms:capture>

<cms:php>
   global $CTX;

   $product_folder_ids = "<cms:show product_folder_ids />";
   $product_folder_ids = implode(',',array_filter(explode(',',$product_folder_ids)));

   $CTX->set('product_folder_ids',$product_folder_ids,'global');
</cms:php>

<!-- I outputted the results to make sure I was on track -->
<cms:show product_folder_ids />



3. Lastly I used the couch query tag to get the IDs of the pages from the search like this:
Code: Select all
<cms:capture into='returned_product_ids' >
<cms:query sql="
   SELECT DISTINCT p.id, p.template_id,  page_title AS k_page_title

   FROM <cms:php>echo K_TBL_PAGES;</cms:php> p

   inner join <cms:php>echo K_TBL_TEMPLATES;</cms:php> t
      on p.template_id = t.id

   WHERE (t.name='product.php')
   AND (p.template_id=t.id)

   AND ( p.page_title LIKE '%apple%' )

   AND p.page_folder_id IN (<cms:show product_folder_ids />)

   AND NOT p.publish_date = '0000-00-00 00:00:00'

   AND p.parent_id=0

   ORDER BY p.publish_date desc"                             
                         
   fetch_pages='1'
   limit='3'
   >

   <cms:show k_page_id  /> ,

   </cms:query>
</cms:capture>

<cms:pages masterpage="products.php" id=returned_product_ids >
<cms:show k_page_title /> <br>
</cms:pages>


I hope I did the right thing? Thank you
Interesting topic. Similar discussion in viewtopic.php?f=4&t=12562&start=0#p35312

A couple of notes - 1. You can find ids of all pages in some folder without a custom query or folders tag by using parameter ids_only='1':
Code: Select all
http://example.com/search.php?k=title&fname=myfolder
<cms:pages folder="<cms:gpc 'fname' />" include_subfolders='1' ids_only='1' limit='20000'/>

2. In the end you decided to ditch cms:search tag, that means you lose full-text search, because cms:pages performs filtering by one field, not ranked search in all fields.
2 posts Page 1 of 1
cron