LiveWhale sites auto-generate sitemaps and robots.txt files to help external search engines find your content. However, we also have built-in tools for allowing visitors to search on your own calendar or website.
Setting up search
In LiveWhale Calendar, search is likely already set up for you: simply including <xphp var="lw_calendar_search" />
in your calendar template will place the search box wherever you like, and LWC does the rest.
In LiveWhale CMS, search is more fully customizable and uses widgets with a search
argument to return various results. You can setup a new site search in two parts:
-
A search form that targets a specific page (in this case, /search)
1
2
3
4
5<form action="/search" method="get">
<label for="search_input" class="lw_sr_only">Search Site</label>
<input id="search_input" type="text" name="q" placeholder="Search">
<button type="submit">Search</button>
</form>(Or a more complex one that uses QuickAccess…)
1
2
3
4
5
6<form action="/search" method="get">
<label for="search_input" class="lw_sr_only">Search Site</label>
<input id="search_input" class="lw_qa lw_qa_page" data-qa-url="/_ingredients/includes/quickaccess.php" data-qa-none-found="No quick links match your search term." data-qa-more-results-msg="View all results" data-qa-more-results-url="/search/?q=" data-qa-force-select="false" type="text" name="q" placeholder="Search">
<button type="submit">Search</button>
<div class="qa_results qa_noquery qa_mouse qa_blur"></div>
</form> -
On that page, widgets that display search results for the “q” GET variable (or whatever you named your search input in the previous step)
1
2
3
4
5
6
7
8
9
10<h2>Search results for '<xphp var="q" type="GET"/>'</h2>
<widget id="123_pages">
<arg id="search"><xphp var="q" type="GET"/></arg>
</widget>
<widget id="456_news">
<arg id="search"><xphp var="q" type="GET"/></arg>
</widget>
<widget id="789_profiles">
<arg id="search"><xphp var="q" type="GET"/></arg>
</widget>(You can also get more complex by using widget filters and fallbacks…)
1
2
3
4
5
6
7
8
9<widget id="123_pages">
<!– show matches for title/keywords if exist –>
<arg id="search"><xphp var="q" type="GET"/></arg>
<arg id="filter_mode">any</arg>
<arg id="filter" name="short_title" action="matches"><xphp var="q" type="GET"/></arg>
<arg id="filter" name="ga_keywords" action="matches"><xphp var="q" type="GET"/></arg>
<arg id="filter" name="keywords" action="matches"><xphp var="q" type="GET"/></arg>
<arg id="fallback"><arg id="filter"></arg></arg><!– otherwise, clear the filter and fallback on just a widget search –>
</widget> -
In LiveWhale 2.0+, you can also include results from QuickAccess, using a widget:
1
2
3
4
5
6
7
8<h2>Search results for '<xphp var="q" type="GET"/>'</h2>
<widget type="quickaccess">
<arg id="header">Top Links</arg>
<arg id="search"><xphp var="q" type="GET"/></arg>
</widget>
<widget id="123_pages">
<arg id="search"><xphp var="q" type="GET"/></arg>
</widget>(Note: This only shows links from the QuickAccess manager in the Toolbox—if you setup QuickAccess to pull from other widgets or sources, those will need to be added separately to your search results page if you want them included.)
How LiveWhale calculates search results
When LiveWhale returns search results, it’s not searching across the whole database—that would be resource-intensive and time-consuming. Rather, any time you create or edit content, LiveWhale indexes it—saving a distilled version of weighted keywords that can be more quickly scanned when you search. Here’s how that works:
- Each content type (story, event, etc.) is configured to designate some fields as having a high indexing weight (e.g., title, keywords, URL) and other fields as having a low weight (e.g. description).
- Custom fields are automatically included in search indexing at a low weight.
- Special content, such as PHP code, HTML comments, long lists of
<ul>
list links, navigations, JavaScript, etc. are excluded from indexing to prevent unnecessary noise. - Widget output is excluded from indexing except in special circumstances where
<arg id="allow_indexing">true</arg>
is set. Widgets with inline header args will have their header text indexed. - Any content within a
<title>
,<h1>
, or<h2>
tag is indexed with a high weight, as is any content within<p class="intro">
or<div class="intro">
. - Common stop words (e.g., a, an, the, our, we) are excluded from indexed content. (If you’re curious, the complete list is at /livewhale/core/modules/search/includes/stopwords.php.)
- Special phrases like a person’s name (both Jane Smith and Smith, Jane) or the title of a department are additionally indexed as a complete phrase for high weighting as an exact phrase match.
- Content is indexed with variants in order to allow misspelled search terms to match the desired content.
More about search queries
- Searching supports modifiers like +, -, wildcards, and quoted phrases.
- Searching supports fulltext searches (the default) and strict matching (exact or partial matches against content title only). You can manually enable strict mode with
<arg id="search_mode">strict</arg>
(or/search_mode/strict
in the REST API) if you want to search only across titles. - Search terms with less than 3 characters, as well as common stop words, are not supported in fulltext searches and therefore individually handled in strict mode (i.e. against title).
- When searching for events, certain terms such as day/week/month are excluded.
- Search terms will automatically match certain spelling variants (singular vs. plural, misspellings).
- Search results are weighted and sorted according to several rules involving: weight of indexed content, relative strength of exact or partial matches against title, relative strength of match against content url, nature of content (i.e. “homepage”, “department of”, etc. considered high weight). Results are returned according to a cumulative relevance score, taking into account all these rules.
If your question is “How can I get this particular content to be more highly-ranked?”, try including your preferred keywords in the title, summary/intro, URL, or h1/h2 tags. In LiveWhale CMS, you can also consider adding it to QuickAccess results or tweaking the settings of your search results widgets to add additional filtering.