Using Site Search

Contents

Webvanta includes a built-in search engine that indexes all of your site's database content to provide high-quality search results.

You can configure which item types are included in the search, and to which pages the search results link. You can also modify the search results page just like any other page.

The search index is updated about once per hour, so there is a small delay between when you change content or settings and when the results reflect those changes.

What Is Searched

By default, all Knowledgebase content (articles, blog posts, events, books, and so forth) is searched, as are all custom item types. If you want to exclude a custom item type from the search, check the box labeled "Private" in the custom item type definition. (Note: currently, only the 'standard' fields in custom item types are searched, so if you add custom fields they are not searched.)

This search function searches your database, not your site's pages. Site content that is placed directly in editable regions of pages or in templates is not searched.

Displaying the Search box

Your starter site includes a snippet named "kb_inline_search_box" that you can include anywhere you want to display a search box. The code is as follows:

<form action="/search" id="searchbox" method="post">
<div>
  <input class="fieldSkybox" id="search_text" name="search_text" type="text" />
  <input class="searchButton" src="/webvanta/img/template/1.0/button-search.gif" type="image" value="search" alt="Search" />
</div>
</form>

You can change the search button to a different graphic or make changes to the corresponding CSS to change the visual appearance of the search box.

Displaying Search Results

The search results are displayed on a special page that has the slug of "search_results" and is set to the page type "Search".

Advanced feature: If you want to have multiple search results pages, invoked by different search forms, you can specify the slug for the search results page by adding a hidden field to the search form, called "search_results", and giving it the value of the search results page path (e.g. "/mysearchresults").

At its most basic, the search results can all be displayed on a single page:

<w:kb:item search="true">
<h1>Search Results for "<w:search_query />" (<w:search_total_found />)</h1>
<ul>
  <w:each search="true">
    <li>
      <a href='<w:path url="default"/>'><w:name /></a><br />
      <p><w:description /></p>
    </li>
  </w:each>
</ul>
</w:kb:item>

This code uses the standard item iterator, with the search option that causes it to display the search results. (We show the unpaginated version here to start with the simplest example, but you should generally use the paginated version described below.)

Note that this code uses two special bits of WebvantaScript that provide access to information about the results:

<w:search_query /> Displays the search text entered
<w:search_total_found />) Displays the number of results

Pagination

The example above is acceptable if your site's database is small (a few dozen items) and you don't expect it to grow. But if you have, or expect to have, 50 or more items, you should include pagination for the search results. (The unpaginated list will be slow to generate if you have more than a few dozen results, and it will be truncated at 200 results.)

Here's an example of a search results page with pagination:

<w:kb:item:paginate search="true" page="auto" limit="25" sort="updated_at DESC">
  <h1>Search Results for "<w:search_query />" (<w:search_total_found />)</h1>
  <w:pagination_widget />
  <ul>
  <w:each>
    <li>
      (<w:type_label />, <w:updated_at format="%b %e, %Y" />) <a href='<w:path url="default"/>' target='_blank'><w:name /></a><br />
      <p><w:description format="strip_tags" truncate='120' /></p>
    </li>
  </w:each>
  </ul>
  <w:pagination_widget search="true" />
</w:kb:item:paginate>

A few notes on the code here:

  • The limit parameter on the w:kb:item:paginate statement sets the number of items displayed per page
  • <w:type:label /> shows the item type for each result
  • The "strip_tags" option on the w:description statement removes any HTML markup, which is necessary when truncating the length to ensure that there is no broken markup

Item Pages

The search results page links each item in the results to an item page that is appropriate for that item. For example, articles may be displayed on one item page, while project profiles are displayed on another.

You determine which pages are used for each type through the following settings:

  • For standard item types, such as articles, blog posts, links, books, and events, enter the slug for the appropriate item page in the View Path field of the item type (Database Setup > Item Types, then click the pencil next to an item type)
  • For custom item types, enter the slug for the appropriate item page in the View Path field of the custom item type definition form.

Advanced Search

Currently, advanced search, in which you can specify the search using multiple fields, with values or ranges for each field upon which you want to search, is not available as part of the standard Webvanta platform. Because of the uniqueness of each site's needs, we provide advanced search as a custom feature, which has a $500 setup fee. Contact us if you need this.


Add Your Comments

(not published)