=== Subset Search ===
Contributors: functionform
Tags: search, relevance, search log, did you mean, better search
Requires at least: 6.5
Tested up to: 7.1
Requires PHP: 8.1
Stable tag: 1.6.1
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Replace WordPress search with ranked results from a fast index, with highlighting, did-you-mean and a search log that keeps no visitor data. No ads, no nags.

== Description ==

WordPress's own search finds posts that contain every word somewhere and lists the newest first. Subset Search indexes your content and ranks the results, so the post that's most about what your visitor typed comes first. Your theme's search form and results page keep working as they are.

* **Fast.** A request that isn't a search runs no extra queries. Searches score in the database, so memory use stays flat however many posts match.
* **Quiet.** No ads, upsells or nag notices. Problems show up in Site Health.
* **Private.** The search log keeps the query, the number of results and the time. No IP addresses, user IDs or cookies.
* **Extensible.** Hooks for every step, plus WP-CLI commands and a REST API.

= Ranking =

* Results ranked with BM25, the formula most search engines start from, weighted by where a word appears. A match in the title counts more than one in the content.
* Every word is required by default. When that finds nothing, results that match some of the words are shown, best first.
* Partial words, quoted phrases, synonyms and words without their accents ("cafe" finds "café").
* English stemming, so "booking" finds "bookings" and "booked".
* Field and post type weights you can change without reindexing.

= What's indexed =

* Titles, content (including reusable blocks and block attributes such as image alt text), excerpts, categories, tags and custom taxonomies.
* Custom fields you list, with `%` wildcards. Author names, approved comments and attachment captions if you want them.
* The index updates when you save a post. A full rebuild runs in small steps from the admin screen, WP-Cron or WP-CLI, so it doesn't time out on shared hosting.

= WooCommerce and multilingual sites =

* WooCommerce: product SKUs and attributes are searchable, and products set to "Shop only" or "Hidden" stay out of search results, as do out-of-stock products when your store hides them.
* Polylang and WPML: each post is indexed with its language, and a search finds the posts in the visitor's language.

= Results =

* Excerpts centred on the words that matched, with those words highlighted.
* "Did you mean" suggestions from the words in your index, so a new site gets them too.
* A search form block, and a REST route for themes and headless front ends that build their own results.

= Search log =

* What people searched for, how often, and which searches found nothing. The zero-result list shows what your site is missing.
* Entries older than 30 days are deleted daily, and the log stops at a row cap. Export it as CSV.

= Tester =

Type a search under Subset > Search > Tester and see how it was read (the words after stemming, any phrases and synonyms), which pass answered it, and each result's score broken down by field.

= Moving from Relevanssi =

Import Relevanssi's settings, synonyms, stopwords and recent search log from the Index tab or with `wp subset search import relevanssi`. It reads them from the database, so Relevanssi doesn't have to be active, and it leaves IP addresses and user IDs behind. Preview it first: the preview lists what will change and anything that can't be imported.

= For developers =

* WP-CLI: `wp subset search index`, `query --explain`, `settings`, `stopwords`, `synonyms`, `log` and `import`.
* A REST API under `subset-search/v1`, with a public `GET /search` for headless front ends, and `subset_search()` for searching from PHP.
* Hooks for every step. The hooks, commands and routes are documented in the plugin's `docs` folder.
* Multisite: network activation sets up every site, and each site has its own index, settings and log.

== Installation ==

1. Upload the plugin to `/wp-content/plugins/`, or install it from the Plugins screen.
2. Activate it. The first index builds in the background.
3. Go to Subset > Search > Tester and try a search.

== Frequently Asked Questions ==

= Do I need to change my theme? =

No. Subset Search answers the same search WordPress runs, so your search form, results template and the search block all work as before.

= How big does the index get? =

For a typical site, under one and a half times the size of your posts table. The Index tab shows both sizes side by side. To make it smaller, index fewer post types, leave comments out or raise the minimum word length.

= How many posts can it handle? =

It's built for sites up to about 200,000 posts. Past that, a hosted search engine such as ElasticPress or Algolia is a better fit, and Site Health will say so.

= How fast is it? =

On a generated site of 10,000 long posts, measured in our test runs:

* A three-word search scores in about 13 ms, and the whole search, including WordPress's own query for the results page, takes about 18 ms.
* Saving a post indexes it in about 15 ms.
* A full rebuild indexes about 14,000 posts a minute.
* The index is about two thirds the size of the posts table.
* A page that isn't a search runs no extra database queries and loads no scripts or styles from the plugin.

Your numbers depend on your host and your content.

= Does the search log store personal data? =

No. It stores the search text, the number of results, the time and where the search came from. A search that looks like an email address or a card number is stored as a hash.

= I have Relevanssi or SearchWP active. What happens? =

Subset Search stands aside while another search plugin is active, and Site Health tells you which one. Import your settings, deactivate the other plugin, and Subset Search takes over.

= What happens to Relevanssi's data after I import it? =

Nothing: the import only reads it. Relevanssi's settings, index and log stay in your database until you delete Relevanssi from the Plugins screen, which removes them.

= What happens when I delete the plugin? =

The index, settings and search log are deleted, on every site of a network. The index is rebuilt from your posts if you install the plugin again. To keep the data, add `define( 'SUBSET_SEARCH_DELETE_DATA_ON_UNINSTALL', false );` to `wp-config.php` before you delete the plugin.

== Screenshots ==

1. The Search tab: operator, fallbacks and field weights.
2. The Index tab with its status and rebuild progress.
3. The Tester explaining a search's scores.
4. Searches that found nothing.

== Changelog ==

= 1.6.1 =
* Security: The Subset menu and its Overview page now need the same capability as a Subset page you can open, so a subscriber no longer reaches the Overview.
* Changed: Built on subset-core 1.13.3.

= 1.6.0 =
* Security: with attachments indexed, a file attached to a draft, private or password-protected post no longer turns up in search. A file is found only while the post it's attached to is published and viewable, and saving, trashing or deleting a post, or attaching or detaching a file, updates its files in the index.
* Changed: sites whose index holds attachments recheck them once, in the background, after updating. Search keeps working while it runs.
* Security: a quoted phrase is no longer checked against the content of a password-protected post, only its title, so a search can't reveal what the protected text says.
* Security: did-you-mean only suggests a word from a post the searcher could find, and only suggests a logged search made at least three times.
* Changed: a search checks at most 5 quoted phrases of up to 100 characters each. Any more are searched as plain words.
* New for developers: `subset_search_index_unattached` decides whether files not attached to any post are indexed (they are by default). `subset_search_max_phrases` and `subset_search_max_phrase_length` change the phrase limits.
* Changed: Built on subset-core 1.13.2.

= 1.5.0 =
* Changed: The reindex on the Index tab runs on the admin code the Subset plugins share. It works as before: it retries a step that fails, waits while a scheduled task holds the index, and reloads the page when the job is done.
* Under the hood: the importers share more code with the other Subset plugins.
* Changed: Built on subset-core 1.13.0.

= 1.4.0 =
* Fixed: on German and other sites using Search Pro's language stemming with accent folding on, a search for a word's base form now finds its umlaut plurals ("Haus" finds "Häuser", "Baum" finds "Bäume").
* Changed: those sites rebuild their search index once, in the background, after updating. Search keeps working while it runs. English-only sites and sites without Search Pro aren't affected.
* Changed: "€" is now dropped from terms like other symbols ("€100" is indexed as `100`).
* Changed for developers: `subset_search_stem` stemmers now receive words with their accents; the stem is folded afterwards.

= 1.3.0 =
* Improved: the search log's CSV export tells browsers not to guess the file type.
* New for developers: `subset_search_admin_enqueue` runs when the settings screen loads its scripts, with the current tab. Add-on tab slugs now go through `sanitize_key()`, so a slug like `Bad Tab` becomes `badtab` instead of being dropped.
* Under the hood: shares more code with the other Subset plugins.

= 1.2.1 =
* Fixed: the REST search route now refuses a page past 1000, so a visitor can no longer make one search slow by asking for a page far past the last result.

= 1.2.0 =
* Improved: with Polylang or WPML, each post is now stemmed and has stopwords left out in its own language, and searches in the current one. Reindex from the Index tab after updating.
* New for developers: `subset_search_stem` and `subset_search_stopwords` get the language, and add-ons can add columns to the Tester.

= 1.1.0 =
* Fixed: with attachments indexed, searches now find them. Before, every attachment was left out of the results.
* New for developers: other plugins can index and search things other than posts, such as users and terms, through `subset_search()` and the REST route's `object_type`. Subset Search Pro uses this to search authors and terms.

= 1.0.0 =
* First release.
