AdvantageCMS.Core.Common.BaseClasses Namespace
Build With Advantage

Adding Search to Your Site

Building an index makes your content searchable. It does not, on its own, put a search box on your site. Two pieces are needed:

  • A search box, normally in the site header so it appears on every page.
  • A results page — an ordinary site page carrying the search results module.

BWA ships both. The default theme unpacks a working search box and a ready-made results module when a site is created, so in most cases this is a matter of placing the module on a page rather than building anything.

How the Two Pieces Connect


  1. A visitor types a query into the search box and presses Enter, or clicks the search button.
  2. The box sends them to the results page, passing the query in the URL.
  3. The results module on that page reads the query, searches the index for the current domain and language, and renders what it finds.

The search box is configured with the address of the results page. If you move or rename the results page, update the box to match, or searching will lead nowhere.

Note Note

Because the query travels in the URL, a results page can be linked to directly with a query already in it — useful for "see all results for…" links elsewhere on the site.

Setting Up the Results Page


  1. Create an ordinary page where the results should appear. The default theme expects one at /Search.
  2. Place the search results module on it, as you would any other module.
  3. Confirm the search box points at that page.
  4. Build the index if you have not already, then search from the live site.
Note Note

The results module renders nothing at all when the page is opened without a query. That is expected — the page is only meaningful when arrived at from a search. Give it a heading or introduction of its own if you want it to look deliberate when reached directly.

What the Default Results Module Provides


Out of the box, without any development work:

Feature

Behaviour

List and grid views

Two buttons let the visitor switch between a single-column list and a card grid. Both are supplied.

Category filtering

A tree of content categories beside the results, each showing how many results carry it. Ticking categories narrows the list.

Paging

Results are paged, and the page number is kept in the address so the browser's Back button behaves properly.

Result summaries

Each result shows its title, a summary drawn from the indexed page, the date it was indexed, and a link through to it.

Query echoed in the banner

The module tells the page what was searched for, so the banner can display "You searched for: …" without any extra configuration.

Note Note

Only categories actually present in the current results appear in the filter tree, and the counts reflect that result set. A category nobody has applied to a page will never show up here — see Content, Location and Security Categories.

Filtering and Paging Happen in the Browser


The module fetches the whole result set once, then filters and pages it in the visitor's browser. Switching views, ticking a category, and moving between pages are all instant, with no round trip to the server.

That is the right trade for typical sites, but it is worth knowing when tuning a large one: a query matching a very large number of pages sends all of them to the browser at once. If your site is big enough for that to matter, narrow what gets indexed rather than expecting the results page to cope — see Controlling Which Pages Are Indexed.

Customising the Results


The module is intended to be customised. How a result looks is defined by two templates held in the module itself — one for the list view, one for the grid view — each a block of ordinary markup with placeholders substituted per result:

Placeholder

Replaced with

{title}

The indexed page's title

{summary}

The generated summary for the result

{url}

The address of the page

{date}

The date the page was last indexed

{buttonText}

The label on the link through to the page

Restyling results, changing what each one shows, or adding a third view is a matter of editing those templates. This is theme work rather than something a content author does, but it does not require touching the search code — only the markup.

Caution note Caution

The default module does not filter results by security group. Applying security groups to results is development work that has to be added to the results module deliberately. See Content, Location and Security Categories.

Keep the Results Page Out of the Index


The supplied module wraps its own markup in ignore markers, so the crawler does not index the results page's furniture — its filter labels, view buttons and template markup.

This matters more than it first appears. Without it, the search page itself becomes a page full of search-related words, and starts turning up in its own results. If you build a results page of your own, wrap it the same way. See Controlling Indexing from Page Markup.

The Search Box


The supplied search box does more than collect text. As the visitor types it offers suggestions drawn from the index and from previous popular searches, showing how many results each would return, and pressing Enter runs the search.

Its suggestions come from the index for the current domain and language, which has two consequences worth knowing:

  • Suggestion quality improves as the index matures. A freshly built index suggests less than an established one.
  • Terms the engine does not recognise can be suggested against unless they are listed under Custom Words. See Custom Words and Stop Lists.
Important note Important

If the search box appears on the site reading Search is disabled and will not accept input, the index has not been built for that domain and language. The box checks for an index before enabling itself, so this is the expected appearance on a site where search is configured but never built, and on a newly restored environment whose index files did not come across. Build the index and it enables itself. See Enabling Search and Building the Index.

Where the Supplied Files Live


Both pieces are part of the site theme, unpacked when the site is created:

Piece

Location in the theme

Search box

Controls\Navigation\Search.ascx

Results module

Modules\Site\SearchResult.ascx

Because they are unpacked into the site rather than locked in the platform, they can be edited freely — and a site created some time ago has the version of them that shipped then, not the current one.

Note Note

Both resolve the index location through the platform rather than by a configured path, so a correctly configured domain needs no path setting here. Do not hard-code an index path into a customised results page; it will break the moment a second language or domain is added.

See Also


Reference

Search
Enabling Search and Building the Index
Content, Location and Security Categories
Custom Words and Stop Lists
Controlling Indexing from Page Markup
Extending the Indexer