Documentation

View the installation guide, browse the Knowledge Base, read the FAQ, find out about SearchWP's many hooks, get support

Partial matches

Enabling partial matches when applicable on SearchWP’s Advanced settings screen will tell SearchWP to be more lenient when finding search results. This behavior is different than enabling keyword stemming and as a result:

⚠️ This feature should be enabled with caution ⚠️

SearchWP is a token based search system. It will break apart your content into tokens and those tokens are used when performing searches. Tokens are separated by white space and punctuation. Because of the strictness of this approach SearchWP is able to improve both relevance and speed of your WordPress search.

Another byproduct of a tokenized search is sometimes not meeting expectations when certain search terms are submitted. As a result, SearchWP is very extensible and one way to modify SearchWP’s behavior is by enabling partial term matches where applicable.

Partial matches can reduce relevance

Many times customers will enable partial term matching as a preemptive catch-all to prevent possible no results searches. Unfortunately this can introduce some completely unrelated terms (that satisfy a requirement of partial matches) into the algorithm, which can reduce the relevance of the results you’re seeing.

A better initial approach

Because introducing partial matches can have an adverse effect on the overall relevance of search results, it is suggested that you instead monitor your search statistics to determine what visitors are searching for. Pay particular attention to the No Results Searches and add appropriate Synonyms for those failed searches.

This approach will allow you to retain the relevancy of SearchWP’s algorithm, but also solve the issue of misspellings and partial matches on a case-by-case basis.

If on your website there are far too many failed searches and it is not feasible to maintain an ever-growing list of Synonyms to combat failed searches, enabling partial matches where applicable may be a better solution.

How partial matching works

Please review the following KB article: How Partial Matching Works

Hooks

There are a number of filters to customize your partial match implementation:

searchwp_partial_matching_{$engine}
Customize whether partial matching is enabled per engine. For example:

<?php
// Note that 'my_supplemental_engine' is the name of the engine
// This will prevent partial matching for the my_supplemental_engine engine
// but leave partial matching enabled (when the checkbox is ticked) for all others
add_filter( 'searchwp_partial_matching_my_supplemental_engine', '__return_false' );
view raw functions.php hosted with ❤ by GitHub

searchwp_partial_matching_aggressive
By default SearchWP will find partial matches if there is an exact match in the search query. You can change that with this hook like so:

<?php
function searchwp_partial_matching_aggressive( $return, $args ) {
// $args contains information about this request
// - engine
// TODO: customize $return to match whether matching should be aggressive
return $return;
}
add_filter( 'searchwp_partial_matching_aggressive', 'my_searchwp_partial_matching_aggressive', 10, 2 );
view raw functions.php hosted with ❤ by GitHub

searchwp_partial_matches_lenient
Using this hook you can tell SearchWP to NOT find partial matches if there are exact matches in the search query.

<?php
function searchwp_partial_matches_lenient( $return, $args ) {
// $args contains information about this request
// - engine
// TODO: customize $return to match whether matching should be lenient
return $return;
}
add_filter( 'searchwp_partial_matches_lenient', 'my_searchwp_partial_matches_lenient', 10, 2 );
view raw functions.php hosted with ❤ by GitHub

searchwp_partial_matches_force_fuzzy
By default SearchWP will locate partial matches and only if none are found it will perform fuzzy matching to broaden the criteria for partial matches.

<?php
function my_searchwp_partial_matches_force_fuzzy( $return, $args ) {
// $args contains information about this request
// - engine
// TODO: customize $return to match whether fuzzy logic should be forced
// when partial matches are already found
return $return;
}
add_filter( 'searchwp_partial_matches_force_fuzzy', 'my_searchwp_partial_matches_force_fuzzy', 10, 2 );
view raw functions.php hosted with ❤ by GitHub

searchwp_like_min_length
Customize the minimum length of a search term for partial matching to be applied. Default is 4, to customize:

<?php
// Apply LIKE matching for terms 2 or more characters in length.
function searchwp_like_min_length( $length ) {
return 2;
}
add_filter( 'searchwp_like_min_length', 'my_searchwp_like_min_length' );
view raw functions.php hosted with ❤ by GitHub

searchwp_like_stem
Customize whether SearchWP applies LIKE matching to the keyword stem regardless of engine setting. Default is false, to customize:

<?php
// Control whether SearchWP uses the keyword stem when finding LIKE terms.
function my_searchwp_like_stem( $stem, $terms, $engine ) {
// Return true/false (default is false)
}
add_filter( 'searchwp_like_stem', 'my_searchwp_like_stem', 10, 3 )
view raw functions.php hosted with ❤ by GitHub

searchwp_like_wildcard_before
Customize whether SearchWP implements a LIKE wildcard before search terms. Default is true, to disable:

<?php
// Prevent SearchWP LIKE Terms from using a LIKE wildcard before search terms
add_filter( 'searchwp_like_wildcard_before', '__return_false' );
view raw functions.php hosted with ❤ by GitHub

searchwp_like_wildcard_after
Customize whether SearchWP implements a LIKE wildcard after search terms. Default is true, to disable:

<?php
// Prevent SearchWP LIKE Terms from using a LIKE wildcard after search terms.
add_filter( 'searchwp_like_wildcard_after', '__return_false' );
view raw functions.php hosted with ❤ by GitHub

searchwp_like_aggressive
Customize whether SearchWP allows partial matches to be used more than once. Default is false, to enable:

<?php
// Allow partial matches to be recycled during processing
add_filter( 'searchwp_like_aggressive', '__return_true' );
view raw functions.php hosted with ❤ by GitHub

searchwp_fuzzy_min_length
Set the minimum word length to include in fuzzy matches (default is 4)

<?php
function my_fuzzy_word_length()
{
return 5;
}
add_filter( 'searchwp_fuzzy_min_length', 'my_fuzzy_word_length' );
view raw gistfile1.php hosted with ❤ by GitHub

searchwp_fuzzy_threshold
Beyond basic fuzzy matching, SearchWP will apply some primitive spell checking to submitted terms. This filter lets you specify what minimum percentage should be used to constitute a valid match. Must be 0 – 100. (default is 70)

<?php
function my_fuzzy_threshold()
{
return 85;
}
add_filter( 'searchwp_fuzzy_threshold', 'my_fuzzy_threshold' );
view raw gistfile1.php hosted with ❤ by GitHub

searchwp_fuzzy_digit_threshold
Set the maximum percentage of digits in search term to perform spell checking (default is 10)

<?php
function myChangeDigitThreshold()
{
return 15; // 15% maximum threshold
}
add_filter( 'searchwp_fuzzy_digit_threshold', 'myChangeDigitThreshold' );
view raw gistfile1.php hosted with ❤ by GitHub
Fix keyword search on your site. No coding required!

Now you can utilize all of the content that's gone unrecognized by native WordPress keyword search instantly with SearchWP

Get SearchWP