We use cookies to make your viewing experience better. By accepting you consent, you agree to our Cookie policy

Accept
Improve your Craft CMS skills

Where To Search In Craft CMS

10 min read
Where To Search In Craft CMS

Searching in Craft CMS can be frustrating if you don't know where to look. This guide will enlighten you on maximizing Craft's built-in search capabilities. Learn how content indexing, search settings, syntax, and display templates allow creating robust search experiences. Discover advanced techniques for performance, facets, and personalization. Get actionable insights for unlocking the full potential of search in your Craft CMS projects.

Craft CMS has powerful built-in search capabilities. Indexing content and optimizing queries provides fast, relevant results. Custom display templates and advanced features like synonyms, facets, and personalization enable robust search experiences tailored to your site and users. Mastering search unlocks CMS potential.

How Search Works in Craft CMS

Indexing and Querying Content

Craft CMS indexes all site content in a search index stored in the database so that it can be rapidly retrieved for search queries. When new content is created or updated, Craft CMS will parse the content, extract important keywords and phrases, and add this information into search indexes. These search indexes allow Craft to quickly scan for relevant content when a search query is made, rather than having to scan through all the raw content each time.

The search indexes in Craft CMS contain keywords, phrases, and other identifiers that summarize the core content on the site. When a search query is entered, Craft CMS checks it against the pre-built indexes to find the closest matching content. Things like synonyms and stemming are used to match variants of search queries to indexed content. This provides a fast and accurate search experience for end users.

By pre-indexing all the content upfront, Craft CMS removes the need to scan raw content on every search. This speeds up retrieval times and provides more relevant results. The search architecture is optimized for fast lookups and matching search queries to indexed site content

Architecture and Storage

Craft CMS uses MySQL to store and query search indexes. All site content is parsed and added to search index tables in the MySQL database. This provides a simple way to store, query, and retrieve indexed content using SQL.

Storing search indexes in MySQL allows Craft CMS to relate content to search indexes. Things like entries, categories, tags, and other content types are all related to the search indexes they populate. This allows for filtering and scoping search queries to certain sections or categories of content when searching.

The search architecture is designed for optimizing fast text search and lookups in MySQL. Performance is improved by pre-indexing all content in the database rather than scanning raw content every search. The indexed data is optimized for fast WHERE queries to match search keywords and filters.

Storing search indexes in MySQL provides a simple, relational way to index site content while optimizing for search speed. The tight coupling between content and search indexes enables advanced search functionality in Craft CMS.

How Queries Are Parsed and Matched

When a search query is entered in Craft CMS, it goes through a standardization process to extract key search keywords and phrases. Things like stop words, punctuation, special characters, and noise words are stripped out. The remaining core keywords are then stemmed to their root form.

This normalized version of the search query is then matched against the search indexes to find close matches. Things like stemming and fuzzy matching are used so variant forms of the search keywords can match indexed content. Common misspellings and typos are also accounted for to improve search results.

If the search query contains multi-word phrases, Craft CMS will attempt to match the exact phrase in the search indexes before resorting to individual keywords. This helps surface content that contains the full query phrase. Proximity ranking also helps ensure words that appear next to each other rank higher.

Advanced search syntax and operators can also be parsed from the search query. Things like quotation marks for exact phrase matching, boolean operators like AND/OR, and field limiters allow users to craft precise search queries. Craft CMS parses the query accordingly to return the most relevant results.

In summary, Craft CMS takes a robust approach to parsing, normalizing, and matching user search queries to indexed site content. Multiple techniques like stemming, fuzzy matching, and proximity ranking are used to deliver the best search experience. The search architecture is optimized to take user queries and quickly return the most relevant indexed content.

Configuring Search Settings

Enabling and Disabling Search

The search feature in Craft CMS can be enabled or disabled as needed from the control panel settings. Under Settings -> Search, there is a checkbox to enable or disable the search feature. Unchecking this box will turn off search functionality sitewide.

Disabling search can be useful in certain situations, like when indexing or optimizing the search indexes. It can also be disabled on sites where search is not needed. The search settings page provides an easy way to toggle search on or off.

In addition to the global search setting, individual sections and entry types can also be excluded from search indexes. This allows more granular control over what content gets indexed for search queries. While globally enabling search, specific sections can be excluded if needed.

The search settings page provides a central place to manage the search feature at a global or granular level. Site admins can easily enable, disable, or configure search based on their needs.

Limiting Search to Sections or Entry Types

Craft CMS allows you to restrict search queries to only match content from certain sections or entry types. This is useful for focusing search on specific content types.

In the search settings, each section and entry type has an option to exclude it from search indexes. Checking this box will prevent content from that source being indexed or returned in search results.

Conversely, you can exclude all sections from search indexes, and selectively enable the ones you want indexed. This whitelists only certain sections and entries types to be included in search.

Limiting search indexes to specific content types delivers better search experiences for end users. Queries can be confined to certain sections like blog posts or news articles for example. Excluding unused sections removes irrelevant content from muddying up search results.

The search settings provide granular control to customize which content on the site should be indexed for search and which should be excluded. This filtering of search indexes by section and entry type allows for optimized search experiences.

Managing Reindexing and Optimization

As content on the site changes, search indexes need to be periodically reindexed to keep them in sync. Craft CMS provides tools to reindex content and optimize the search for performance.

The utilities section in the control panel has an option to reindex search indexes. This will rebuild the indexes from scratch using the latest content. The reindexing can be done in segments over time to control server resources.

Search indexing can also be set to occur automatically in a queued jobs. The queue length and resource utilization can be configured based on the size of the site and server capabilities.

Optimizing indexes for high performance searching involves things like adjusting stopwords, managing index fragmentation, and tuning MySQL for search. The complexity depends on factors like index size, query volume, and result accuracy needs.

Monitoring index size, cache efficiency, and query response times can identify optimization opportunities. Things like search keyword analysis and user behavior data provide insights for tuning. The key is balancing fast responses with comprehensive content indexing.

Craft CMS provides the tools for managing the search indexing and optimization process. While automatic background indexing works for most sites, larger or complex projects may require more active tuning and administration for optimal search performance. The control panel offers configurable settings to take greater control over search as needed.

Craft CMS Search Syntax and Operators

Boolean and Advanced Operators

Craft CMS supports standard boolean operators like AND, OR, and NOT for combining search keywords and phrases. These allow creating more precise searches.

For example, "coffee AND tea" finds content mentioning both terms, while "coffee OR tea" returns content mentioning either. NOT excludes certain keywords from results. Boolean logic helps include or exclude specific concepts.

Advanced syntax like quoted phrases for exact matching is also supported. Putting a phrase in quotes like "hot beverage" only returns results containing that exact wording. This is more strict than a normal phrase search.

Escaping special characters with a backslash allows searching for punctuation, symbols, and other literals. For example, "coffee!" would find coffee! including the exclamation point.

Proximity searches like "coffee NEAR tea" can improve relevancy by requiring terms to be within a certain distance in the content. This helps surface documents where the words appear together.

These types of boolean, phrase, and advanced syntax give users more control over search queries in Craft CMS. Precise searches with specific logic and intent are enabled.

Weighting and Keyword Boosting

Behind the scenes, Craft CMS applies algorithms to weight and rank keywords in search indexes and queries. Frequency analysis is used to identify significant terms that appear more often in relevant content.

Keywords that occur many times across documents tend to have high term frequency. Words limited to only a few documents have lower document frequency. High TF-IDF scores can be assigned to keywords with the optimal mix of term and document frequency.

Search rankings are tuned by weighting keywords based on their significance and prevalence across indexed content. More unique and frequent terms are ranked higher in results.

Keyword boosting directly in the search query can also improve rankings of specific terms.

Prefixing a keyword with ^ boosts its weight and increases the ranking of documents containing it.

By analyzing keyword frequencies and allowing boosting, Craft CMS can deliver more relevant results tuned to the site's content profile and search queries.

Special Parameters and Values

Craft CMS search allows passing special parameters to filter, order, and customize query results.

The "search" param specifies the free text keywords to search for. The "relatedTo" param scopes results to certain entries or categories. "orderBy" controls sorting of results.

For example "search=coffee&relatedTo=blog&orderBy=score" searches for coffee in the blog section, ordered by relevance.

Other handy parameters include "locale" to filter by language, "offset" for pagination, and "limit" to limit results. Things like "status" and "type" filter by entry properties.

Common orderBy values are "score" for relevance, "title" for alphabetical, and "date" for recency. relatedTo accepts entry IDs, slugs or UIDs to filter related entries.

These search params provide deep control over Craft CMS search results - filtering, scoping, sorting, and more. They enable building advanced search interfaces and queries tailored to the site content and UI needs.

Displaying and Formatting Search Results

Using Templates to Control Display

Craft CMS gives full control over displaying and formatting search results using templates and template logic. Custom templates can be created to output results in any desired markup.

Within the search results template, the {% for %} tag loops through each result item. Properties like title, summary, URL, and any custom fields can be output within the loop. Conditional logic like {% if %} tags helps customize the display per result type.

Templates provide flexibility to lay out each result item in any HTML markup needed. CSS classes can be conditionally added to enable targeted styling. Keywords within titles and snippets can be highlighted.

Display logic in templates also enables showing things like: result counts, no results messaging, pagination links, and sorting options. All presentation aspects of search can be tailored to the site design.

Craft's templates enable full display control when building custom search interfaces. Any HTML/CSS can be used to achieve unique results formatting that matches the site experience.

Pagination and Limiting Result Quantity

Craft CMS pagination – To paginate long search result sets, the {% paginate %} tag can be used in templates. The "limit" and "offset" parameters handle pagination.

For example, setting limit=10 displays 10 results per page. offset=20 would skip the first 20 results. Pagination links can show Next/Prev buttons to advance pages.

Pagination prevents huge search listings by breaking them into managable pages. Site visitors can click through to see more results.

Limiting results also improves performance. Setting a cap on result quantity with "limit" ensures queries don't overload the browser or server even if thousands of matches exist.

Result limits also focus results to the most relevant matches rather than every possible hit. Combining limits with good ranking and pagination delivers a quality search UX.

Styling Results with HTML and CSS

Search results can be formatted using standard HTML and CSS techniques. Container divs allow styling the overall results and individual result items.

Custom CSS classes can be added to result item templates for flexible styling. Things like highlighting query keywords in bold or specific colors improves skimmability.

Result titles and snippets should use proper heading hierarchy and semantic markup for accessibility. Descriptive CSS class names make styling intuitive (e.g. .result-title or .result-url).

Results can be styled differently depending on the content type for visual distinction. Icons can indicate if a result is a blog post, product, etc. Typography and color schemes should fit the overall site design.

A minimal yet visually engaging results format improves usability. Formatting techniques like spacing, dividers, and containment make the results layout clear. Consistent styling maintains usability across search pages.

With Craft CMS templates and CSS, developers have total control to build search interfaces tailored to the site brand and design system. Any style, layout, and formatting can be implemented to beautifully present results to users.

Advanced Search Capabilities

Implementing Faceted Search

Faceted search allows users to filter results by applying multiple filters. Craft CMS can support faceted search with some custom development work.

Facets are based on indexes of metadata and taxonomy. For example, filters for category, brand, color, price range, etc. Users can progressively refine the results by applying multiple facet filters.

To enable facets in Craft, additional search indexes need to be created that classify content along the desired filter dimensions. These are queried along with the main keyword search to retrieve filtered result sets.

The front-end also needs custom building to display the facets and let users select filters to apply. As filters are added, the query adjusts dynamically using those facet parameters.

While faceted search requires upfront implementation effort, it provides an advanced discovery experience by giving users multiple axes to drill into the content. The indexes and UI must align to the site taxonomy and information architecture.

Synonyms for Improved Relevance

Search relevancy in Craft CMS can be enhanced through synonym matching. A custom synonym list allows mapping semantically similar words.

For example, mapping "smartphone" to "mobile phone" and "cell phone" would allow those terms to be interchangable in search queries. Queries match based on conceptual meaning rather than just literal keywords.

A synonym list should be tailored to the site content and usage context. Ontologies, taxonomies, and analytics insights help identify appropriate synonyms. Too many unnecessary synonyms add noise.

Tools like word embeddings can automatically suggest semantic synonym candidates that are statistically relevant for the domain. Human curation ensures quality synonyms.

Matching synonyms expands the search recall without sacrificing precision. Queries become more flexible by accounting for varied terminology around the same concept. Overall, synonyms improve the user experience by increasing relevant matches.

User Personalization and Saved Searches

For registered users, Craft CMS enables saving search queries along with user accounts. This allows persisting favorite and commonly used searches.

Saved queries can be displayed in the user profile and search interface to provide quick access to personalized searches. Search histories can also inform recommendations.

User preferences like default sorting, result quantities, and facet filters can also be persisted to provide personalized search experiences. Site search evolves based on an individual's search behavior.

On the technical side, user-specific search preferences require custom development. Additional queries, UI elements, and storage logic needs implementation.

However, personalization and saved queries greatly improve search utility for regular users. Customization reduces repetitive searching and facilitates discovery. Over time, search becomes tailored to each user's interests and habits.

Shape April 2022 HR 202
Andy Golpys
- Author

Andy has scaled multiple businesses and is a big believer in Craft CMS as a tool that benefits both Designer, Developer and Client. 

Share
Feedback
Show us some love
Email Us
We usually reply within 72 hours
Agency Directory
Submit your agency
Affiliate Partners
Let's chat