=== iMegaSearch ===
Contributors: fareeddaar
Tags: search, live search, instant search, product search, woocommerce
Requires at least: 6.2
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 1.0.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

A full-screen search overlay with results as you type, matched in the browser against a static index. No request per keystroke.

== Description ==

iMegaSearch replaces the search experience on your site with a full-screen overlay that shows grouped results while the visitor types: products, posts, pages, categories, tags, or any public post type and taxonomy you choose.

Most live-search plugins send a request to WordPress on every keystroke. On a typical host each of those requests boots WordPress and all of its plugins, which is why live search so often feels slow. This plugin works differently: it builds one small static index file of your content, the browser downloads it once (it is cached like any other static file), and every search after that is matched locally in a few milliseconds.

= Features =

* **Full-screen overlay** with a large search field, popular-search chips and results in two columns.
* **Results as you type**, with the matched text underlined and a "See all" link per group.
* **Grouped results page** for `/?s=`, with a tab and a count for each group. Use it as your theme's search page or place it anywhere with a shortcode.
* **Any content**: every public post type and taxonomy can become a result group. Choose the heading, column, order and number of results for each one.
* **Sensible ranking**: titles and term names match anywhere in the word ("grease" finds "Degreaser"), while body text matches from the start of words only, so "rust" does not return every page containing "trusted". Title matches always rank above body-text matches.
* **Keeps itself up to date**: the index rebuilds automatically a couple of minutes after content changes, and once a day as a safety net. There is a "Rebuild index now" button and a WP-CLI command too.
* **Works with your theme**: open the overlay from the shortcode button, from any element you point it at with a CSS selector (your theme's search icon, for example), or whenever a visitor focuses a search field.
* **Accessible**: a proper dialog with focus trapping, Escape to close, focus returned to the trigger, visible focus rings and support for reduced motion.
* **WooCommerce ready**: products, product categories and tags work out of the box, with product categories shown under each product.
* **No external requests**, no tracking and no account needed.

= Shortcodes =

* `[imegasearch_button]` prints a search button that opens the overlay. Attributes: `label`, `class`, and `icon="no"` to hide the magnifier.
* `[imegasearch_results]` renders the full grouped results page wherever it is placed.

Any element with the `mgs-open` class or a `data-mgs-open` attribute also opens the overlay.

= For developers =

* Override the results page by copying `templates/search.php` to `your-theme/imegasearch/search.php`.
* Filters: `imegasearch_available_groups`, `imegasearch_index`, `imegasearch_post_item`, `imegasearch_term_item`, `imegasearch_max_items`, `imegasearch_preferred_taxonomies`, `imegasearch_label_taxonomy`, `imegasearch_config`, `imegasearch_load`.
* Action: `imegasearch_index_built`.
* JavaScript: `window.iMegaSearch.open( 'term' )`, `.close()` and `.reload()`.
* WP-CLI: `wp imegasearch rebuild` and `wp imegasearch status`.

== Installation ==

1. Install and activate the plugin from Plugins → Add New, or upload the `imegasearch` folder to `/wp-content/plugins/`.
2. Go to Settings → iMegaSearch and choose which content to include.
3. Make the overlay reachable: add the `[imegasearch_button]` shortcode to your header, or enter your theme's search icon selector under "Opened by".
4. Save. The index is built straight away.

== Frequently Asked Questions ==

= Where is the index stored? =

In `wp-content/uploads/imegasearch/index.json`. It is written atomically (to a temporary file first) and its URL carries a version, so visitors never see a half-written or stale file.

= How big is the index? =

It holds titles, links, thumbnails and short excerpts, plus a compact word index of the body text. A shop with around a thousand products is typically a few hundred kilobytes before compression, and much less over the wire because the file is served gzipped like any other static file. It is downloaded once, when a visitor first opens search.

= Are private or password-protected posts included? =

No. Only published posts without a password are indexed, and only public post types and taxonomies are offered.

= My changes do not show up in search yet. =

The index rebuilds about two minutes after a change so that bulk edits rebuild only once. It relies on WP-Cron, so on a site with very little traffic it can take longer. Use Settings → iMegaSearch → Rebuild index now, or `wp imegasearch rebuild`.

= My theme already has a search icon. How do I make it open the overlay? =

Find a CSS selector for the icon (for example `.header-search` or `.search-toggle`) and enter it under "Opened by". Clicks on it are caught before the theme's own handler runs, so the theme's dropdown no longer opens.

= Does it work without JavaScript? =

The results page falls back to WordPress's own list of results when JavaScript is off.

= Does the plugin contact any external service? =

No. Everything runs on your own site and in the visitor's browser.

== Screenshots ==

1. The overlay showing live results while typing, with products on the left and categories, articles and topics on the right.
2. The grouped results page, with a tab and a count for each group.
3. Settings → iMegaSearch: choose what to search and how each group is shown.
4. The overlay on a phone.

== Changelog ==

= 1.0.0 =
* First release.

== Upgrade Notice ==

= 1.0.0 =
First release.
