Problems, need help? Have a tip or advice? Post it here.
11 posts Page 1 of 2
HI,
What I am trying to achieve is that, creating a search form along with other dropdown values.

Explanation:
I do have search inputs like this:
input type text = for keywords to search
dropdown = for the category to search under
dropdown = for location to search under

I have achieved performing filter search based on dropdown values ( as taught in 'filter search' tips and trick). however, implementing a search with keywords is giving me a hard time.

pages tag look like this:
Code: Select all
<cms:pages masterpage=k_user_template  custom_field="user_type=ABC | <cms:show filter_string />" limit='30' paginate='1'>

where 'user_type' is hardcoded and 'filter_string' is coming from dropdowns and giving output like this:
category=cat1 | location=australia
filter_string has not implement the keyword functionality yet.

currently i have separate form for dropdowns and keyword but can be merged together. filter dropdown is separate from search input. user can search only with using dropdown filters altogether.
Trials:
I have tried implementing :
custom_field=search_string : even hardcoded string didn't work ( I don't know why!)
custom_field="user_type=ABC | <cms:show filter_string /> | <cms:show search_string />"

I tried forming a search_string and using it in custom_field like this: custom_field="k_page_name=search_string"
but its is giving me error that k_page_name is not defined in user template

code snippets: search form
Code: Select all
<cms:capture into='e_search'>
  <cms:form name="e_search" anchor='0'>
    <cms:if k_success>
      <cms:if frm_search!='' >
        <cms:set search_string=frm_search  scope='global'/>
      </cms:if>
    </cms:if>
    <cms:input type="text" name='search' placeholder="Search..." />
    <button type="submit"><i data-feather="search"></i></button>
  </cms:form>
</cms:capture>


code snippets: dropdown form
Code: Select all
<cms:capture into='e_filter'>
<cms:form name="filter" anchor='0'>
<cms:if k_success>
  <cms:if frm_category!='-' >
    <cms:set filter_string="<cms:concat filter_string ' | category=' frm_category/>"  scope='global'/>
  </cms:if>
 
  <cms:if frm_location!='-' >
    <cms:set filter_string="<cms:concat filter_string ' | location=' frm_location />"  scope='global'/>
  </cms:if>

</cms:if>


    <cms:input type="dropdown"
          opt_values="Select category=-<cms:pages masterpage='category.php'>| <cms:show k_page_title/>=<cms:show k_page_name  /></cms:pages>"
          opt_selected='-'
   name="category" />



      <cms:input type="dropdown"
      opt_values="Select Location=-<cms:pages masterpage='location.php'>| <cms:show k_page_title/>=<cms:show k_page_name  /></cms:pages>"
      opt_selected='-'
      name="location"  />

  <div >
    <button type='submit' class="btn-primary">Apply Filter</button>
  </div>
</cms:form>
</cms:capture>


Alternate Approach:
Can I use custom_field property in 'search' tag? so that I can use keywords property to search keyword along with the custom_field.

Another Question:
How can I search for a specific editable field of type text/textarea?Like:
I have an editable textarea with some content in it. I want the search keyword to search only within that textarea? either using through pages tag or search tag?


any help is appreciated!
thanks
But why are you trying to mix up Search and Filter? Search is a fulltext search and only works on all editables (not excluded by admin via parameter searchable='0') and Filter works by selecting pages where certain editables contain a value.

If you still need to perform a search on a certain limited set of editables and find if they has some keyword in content, then it must be a custom SQL query. For example, when I needed to find all pages, where k_page_title contained words with a certain letter, I had to write a custom function for that. Also, custom_field by design and by name don't work with system fields.
I want to create an advanced search form where users can type the keyword and choose category and location and search results to contain the keyword along with chosen location and category.

ok, I understood, custom_field work only with user-defined fields.

or can we do something like this:
user fill the form with keyword, location, and category and then we search from keyword first then filter out the result based on location and category?

How do i approach this?
And the keyword must be found where on page? In title only or everywhere?
@trendoman
yea! such keyword can be found anywhere in the given template, not necessarily in the title. like the normal search tag!
And why search tag is so strict? like : page name is 'mypagename' and if keyword is 'mypage' it won't show in result!
jabeer wrote: @trendoman
yea! such keyword can be found anywhere in the given template, not necessarily in the title. like the normal search tag!
And why search tag is so strict? like : page name is 'mypagename' and if keyword is 'mypage' it won't show in result!

This is not possible out of the box. If you interested why, it is because <cms:search> does not take any usual for <cms:pages> hints, like 'custom_field' or 'id' or 'page_name' etc. The database query it builds can be looked at by adding param return_sql='1' and you'll see that there are no provisions for the usual suspects, even for 'start_on' 'stop_before', none. This renders Search pretty universal one shot gives it all approach.

If I had been tasked with such thing, I would try to code it via 2 possible routes being: (1) there is an event alter_page_tag_query_ex that allows to intervene into a search query before it is sent to database. I would try to inject a list of ids of pages that match my other criteria set by antecedent <cms:pages> tag. I really don't want now to write more on this, because you must know PHP and SQL here (2) perform a search with a vry large limit set via 'limit' param to avoid pagination and get list of ids of pages with a search excerpt for each of them. Then run the filtering by <cms:pages> with supplied list of ids obtained from search. Matching ids would then be the target subset which I would display with their search excerpts. This does not require PHP or SQL, but a solid understanding of arrays is required.

As you can see there is no easy solution for the boundaries that you have just set. Maybe if you restructure the concept of search in your website you could avoid all this. It is often not really required in small websites anyway, but only in larger webapps.
option 2 seems feasible.
if I can approach it like:
search the keyword and store all ids(k_page_id) in a variable like this: search_id="14,152,45,13,48"

then use cms:pages tag to iterate through these ids with the given filter in custom_field property. and show the result based on pages tag

Can you provide more light on this?
thanks
Of course. You don't want to store ids as a comma separated string per se, but instead it is required to use an array to also store search result (excerpt with highlighted words) along each id. Use this 'array' concept - viewtopic.php?f=5&t=10892 You can of course build a separate variable to have a string of ids for the subsequent <cms:pages>.

This is all help I want to provide.
I won't need search specific variables like excerpts etc.
Will store only ids as comma separated variable and then use this variable in pages tag like this
Code: Select all
<cms:pages masterpage=k_user_template id=id_string custom_field=filter_string>

this will fetch the pages search by the search tag

any caveat to this approach?
thanks!
Yes, this approach is very time consuming if the number of pages is large, because fulltext search is going to perform unconstrained on all pages of all included templates.

Please note, that one doesn't need to be a genius to actually code a quick extension to <cms:search> that allows ids to be included to query like this <cms:search ... id=my_ids >..</cms:search>. I have actually tried it with the $FUNCS->add_event_listener( "alter_page_tag_query" ... ) and it works perfectly! So, I hope you have a good satisfying result with the second approach, and I will surely stick to the first one.
11 posts Page 1 of 2
cron