Code snippet: How to restore partial matching in Document Library Pro search
Document Library Pro (4.0 and later) uses an indexed search system which is designed to make searches faster, especially on larger websites. The indexed search matches the beginning of each indexed word or token. For example, if your table contains:
- Information about Glass
- Form for Glass
Searching for "form" with the indexed search will find "Form for Glass", because "form" is a complete token. However, it will not find "Information about Glass", because "form" appears in the middle of the "Information" token.
If you need the search to match a term anywhere within the data, you can disable the indexed search and restore the default WordPress search behavior by adding the following code to your website. If you're unsure how to use it, then read our article about code snippets:
add_filter( 'document_library_pro_use_indexed_search', '__return_false' );
This switches Document Library Pro back to the standard WordPress search instead of using the indexed search. As a result, searches can match text anywhere within a value.
Performance
The indexed search was introduced to improve search performance, so disabling it can make searches slower. This is more likely to be noticeable on websites with a large number of documents or a lot of searchable data. For smaller websites, the difference may be minimal.