9

Being new to EE I have only used Low Search once before and it was a very basic keyword search. This time it is a search with parameters. Unfortunately, it is return all entries in the channel I'm searching.

Following is my setup - where am I going wrong?

Channel name: events Collection label: Event Collection name: events

Field Weights: Title 3
Event Start Date 3
Event End Date 3
Course Name 2 Event Description 2 Event Location Map 1

Trying to search the following 'events' channel fields:

Play Dates {events_start_date} {events_end_date}

Venue {events_course_name}

Location {events_map_formatted_address}

Event Name {title}

Event Type {events_type}

{exp:low_search:form collection="events" search_mode="all" result_page="events-and-offers/search" form_class="form-horizontal"}
    <div class="left-form">
        <h5>Search by</h5>

        <div class="control-group">
          <label class="control-label" for="inputDates">Play Dates</label>
          <div class="controls">
            <input type="text" id="txtFromDate" name="range:events_date" placeholder="start date" class="datepicker span placeholder">
            <input type="text" id="txtToDate" name="range:events_date" placeholder="end date" class="datepicker span placeholder">
          </div>
        </div>

        <div class="control-group">
          <label class="control-label" for="venue">Venue</label>
          <div class="controls">
            <input type="text" id="venue" name="events_course_name[]" placeholder="venue" class="span placeholder">
          </div>
        </div>

        <div class="control-group">
          <label class="control-label" for="location">Location</label>
          <div class="controls">
            <input type="text" id="location" name="events_map_formatted_address[]" placeholder="postocde" class="span placeholder">
          </div>
        </div>

        <div class="control-group">
          <label class="control-label" for="event-name">Event Name</label>
          <div class="controls">
            <input type="text" id="event-name" name="title[]" placeholder="event name" class="span placeholder">
          </div>
        </div>
    </div>

    <div class="right-form">
        <h5>I am interested in</h5>
        <label class="checkbox">
          <input type="checkbox" name="events_type[]" value="special-events">
          <i class="ss-icon ss-standard ss-star"></i> Special Events </label>
        <label class="checkbox">
          <input type="checkbox" name="events_type[]" value="offers">
          <i class="ss-icon ss-standard ss-dollarsign"></i> Offers </label>
        <button type="submit" class="btn btn-normal btn-success"><i class="ss-icon ss-symbolicons-block">search</i> SUBMIT SEARCH</button>
   </div>
{/exp:low_search:form}

Results page (keeping it basic for testing):

{exp:low_search:results query="{segment_3}" limit="10"}
  {if count ==  1}<ol>{/if}
    <li><a href="{comment_url_title_auto_path}">{title}</a></li>
  {if count == total_results}</ol>{/if}
  {if no_results}No search results{/if}
{/exp:low_search:results}

1 Answer 1

27

Okay, this may take a while, but first, read my Low Search Primer. Now you know searching is simply filtering entries by keyword. Low Search uses its collections and their indexes for high quality keyword filtering. In a Low Search form, you can use an input field with name="keywords" to trigger filtering by keywords.

Keyword filtering

The Keywords filter searches Collections and the index they create, which is a single field that contains all the custom fields you've added weight to, combined. Therefore, you're not searching just the title or a custom field specifically; you're searching through an entry as though it is a single searchable field.

You can be creative with the collections, of course. For example, you could create another collection where you only add weight to the title of a channel, and call it (in your case) 'Event Titles'. When choosing which collection to search in, you can give the user the option to search only 'Event Titles' or 'Events'.

Note that you should only give weight to fields that have meaningful text for keyword searches. A date or a drop-down with 'yes' and 'no' do not make sense for keyword searches.

Native filtering

The channel:entries tag natively provides filters as well, as parameters. For example: status, category or search:my_custom_field. Each of these parameters can be used as input fields or selects in the Low Search form as well, using name="status", name="category" and name="search:my_custom_field", and so on.

Now, as you know, most parameters can take multiple values. If you want to do that in the form, you can use a multiple select field or checkboxes. For example, you could use the channel:categories tag to generate a checkbox list of categories. However, if you name those name="category", like I stated above, it will only return the last one checked/selected. That's just how forms work. To send a list (array) of categories, add square brackets to the name: name="category[]". Now all checked/selected items will be posted, and Low Search will convert those to a pipe-separated list and place that in the category parameter of the channel:entries tag.

The same principle applies to all native parameters. You can even make sure Low Search converts those values to an &-separated list for inclusive parameters, by setting the require_all parameter to the Form tag. For example, require_all="category" will generate a parameter like category="1&2&3".

Ranges

In addition to the Keywords filter, Low Search also lets you filter by Ranges. In your case, you're filtering by date range.

It works similarly to EE's native search:my_custom_field parameter, but uses range:my_custom_field instead. This means you can use an input field like name="range:my_custom_field" as well.

To get the from and to values, you can separate the parameter value with a pipe, for example: range:my_custom_field="1|10", which translates to "my custom field should be between 1 and 10".

You can also split this into 2 fields like this: range-from:my_custom_field="1" range-to:my_custom_field="10". Again, the same principle applies to using this in input fields: name="range-from:my_custom_field" and name="range-to:my_custom_field". See where this is going?

In conclusion

With what I've tried to explain above, you should already notice the tweaks you need to make in your example code.

  • Don't add weight to your start and end date fields. It won't hurt, but it won't do anything.
  • You're using name="range:events_date" for both the dates, which is wrong on 2 accounts. You're probably looking for events that start in the given range, so this would make more sense: name="range-from:events_start_date" and name="range-to:events_start_date"
  • You want to search for the custom fields venue and location specifically. You could, but only using EE's native search parameter, so: name="search:events_course_name" and name="search:events_map_formatted_address". Also note I'm not using [], because the fields are a single value.
  • You want to search for a title specifically. This can't be done with EE's native search parameter, but can be done with Low Search's extended Field Search filter, using search:title="".
  • The checkboxes do need the square brackets, since they both apply to the same field, but again, they're not keywords, so you should use name="search:events_type[]" to trigger the filter. You should also add require_all="search:events_type" to the form tag, so if both checkboxes are ticked, you only get results for A and B, not A or B.

Turned out to be quite an essay, but I hope this helps you grasp the concept of Low Search better.

5
  • thanks you so much, Low. I think I've got it. Just doesn't seem to be working with the dates: j.mp/VAvZTY Commented Dec 5, 2012 at 10:07
  • That could be a number of things. Send me SuperAdmin login creds to hi at gotolow dot com if you want me to take a look.
    – Low
    Commented Dec 5, 2012 at 10:14
  • Is this what you mean by require_all? {exp:low_search:form collection="events" search_mode="all" result_page="events-and-offers/search" form_class="form-horizontal" require_all="search:events_type"} As if both are selected it returns nothing. Commented Dec 5, 2012 at 10:16
  • I do, but it looks like an event is either a special event or an offer, not both. If that's the case, you can remove the require_all parameter.
    – Low
    Commented Dec 5, 2012 at 10:20
  • Low has been awesome! His answer here was very comprehensive but he's also helped me specifically in our install. Commented Dec 5, 2012 at 12:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.