=== Mav AI Powered Search ===
Contributors: mavlers
Tags: search, ai search, ai overview, search suggestions, woocommerce
Requires at least: 7.0
Tested up to: 7.1
Requires PHP: 7.4
Stable tag: 3.3.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Enhance WordPress search with an AI-generated answer and curated links, powered by the WordPress AI Client.

== Description ==

Mav AI Powered Search upgrades your site's search results page with an AI-generated answer to what the visitor searched for. The answer explains the topic, how it relates to your business and what you offer in that area, citing the pages it draws on, followed by the source pages and related search terms.

The plugin uses the AI Client built into WordPress 7.0+. You pick an AI provider and enter its credentials once, at the site level, under Settings → Connectors. Mav AI Powered Search then works with whichever provider you have connected. The plugin itself stores no API keys and does not talk to any AI service directly.

**How it works**

1. A visitor searches your site.
2. The AI works out what the visitor is after (for example a definition, a service or pricing) and the other words your site might use for the same topic.
3. The plugin searches your published posts, pages and (if WooCommerce is active) products for the query and those related terms, splits the matching pages into passages under their headings, and picks the passages that best cover the topic.
4. Those passages, the visitor's search and your Business Profile are passed to the WordPress AI Client, which sends them to the AI provider you have connected. The AI writes a structured answer: a direct headline, sections in a logical order, key takeaways and the pages it used.
5. The page loads straight away and the answer appears above your normal search results when it is ready.
6. Answers are cached, and cleared when you publish or update searchable content. The plugin falls back to a plain list of matching posts if no AI provider is connected or a request fails.

**Features**

* Works with any AI provider connected through WordPress's Settings → Connectors screen. No separate API key is needed for this plugin.
* Structured answers that explain the topic and how it relates to your business, with numbered citations to your own pages.
* A Business Profile setting that tells the AI who you are, drafted automatically from your site for you to review.
* Search intent analysis and passage-level retrieval, so answers draw on whichever part of the site covers a topic, even when it uses different words than the visitor.
* Reads content from the block editor, shortcodes and Elementor; other page builders can supply content through the `mav_aips_post_content` filter.
* WooCommerce awareness — includes matching products in the AI's context.
* Configurable caching to control AI usage and cost.
* Usage tracking and cache management in the admin settings screen.
* Graceful fallback to a plain matching-posts list when AI is unavailable.

== External services ==

This plugin does not connect to any external service by itself. AI requests go through the WordPress AI Client, which sends them to the AI provider the site owner has connected under Settings → Connectors. That provider's own terms of use and privacy policy apply, and it bills usage to the account whose credentials were entered there.

**What is sent**: the visitor's search query text, the Business Profile you enter in the settings, and passages from your own site's already-published post/page/product titles and content (used so the AI can write a relevant answer). No visitor personal data (name, email, IP address, account info) is collected or sent by this plugin.

**When it is sent**: when a visitor searches your site and a cached result for that search term doesn't already exist (two requests: one to interpret the search, one to write the answer), and when an administrator clicks "Draft from site content" in the settings.

== Installation ==

1. Upload the `mav-ai-powered-search` folder to `/wp-content/plugins/`, or install the plugin zip via Plugins → Add New → Upload Plugin.
2. Activate the plugin through the "Plugins" menu.
3. Make sure an AI provider is connected under Settings → Connectors.
4. Go to Mav AI Powered Search in the admin menu and click "Test Connection" to confirm AI responses are working.
5. Click "Draft from site content" under Business Profile, review the draft, and save. Answers are much better when the AI knows what your business does.
6. Add the `[mav_aips_suggestions]` shortcode to your search results template (or use the `mav_aips_search_suggestions()` template tag), placed just before your theme's normal search results loop.

== Frequently Asked Questions ==

= Do I need an API key? =

Not for this plugin. Mav AI Powered Search uses the AI provider connected to your site under Settings → Connectors (WordPress 7.0+). You need an account with that provider, and the provider bills you directly for usage.

= What happens if no AI provider is connected? =

The plugin falls back to showing a plain list of posts matching the search term, with no AI-generated content.

= Which AI model is used? =

The WordPress AI Client chooses a model from your connected provider that supports structured (JSON) text generation. The "Test Connection" button on the settings screen shows which provider and model answered.

= What happens if a search doesn't match anything on my site? =

The search is also run with related terms, so a page that describes the topic in other words can still be found. If nothing on the site covers it, the AI says so plainly rather than presenting unrelated content as an answer. If nothing matches and no Business Profile is set, the plain fallback list is shown instead.

= Can the AI make things up about my business? =

The AI may explain a topic in general terms from its own knowledge, but it is instructed to base every statement about your business on your Business Profile or on the pages it cites. Links in the answer are always to pages it was given, never URLs the AI wrote itself. Keep the Business Profile accurate, because the AI treats it as fact.

= My site uses a page builder. Is its content read? =

Block editor content, shortcode-based builders and Elementor are read automatically. For content stored elsewhere (for example ACF fields), return it from the `mav_aips_post_content` filter, which receives the rendered HTML and the post.

= Does this work with WooCommerce? =

Yes. When WooCommerce is active, matching products are included in the content the AI considers.

= How do I control AI costs? =

Each new search uses two AI requests: one to interpret it (cached for a week) and one to write the answer (cached for the Cache Duration, default 1 hour). Answers are only generated for submitted searches, not while visitors type. Check your AI provider's dashboard for actual usage and billing.

== Screenshots ==

1. Settings screen.
2. AI-generated answer displayed on a search results page.

== Changelog ==

= 3.3.0 =
* Answers are now structured: a direct headline, sections in a logical order (what the topic is, how it relates to your business, what you offer, next steps), key takeaways, and numbered citations to the pages used.
* New Business Profile setting, with a "Draft from site content" button, so the AI knows what your business does and how it talks.
* Each search is first interpreted for intent and related terms, which are used to find content and shape the answer.
* Content is now read passage by passage under its headings (including blocks, shortcodes and Elementor), and the best-matching passages from across the site are sent to the AI instead of the first 120 words of each page. Recent posts are no longer added as filler.
* The AI may now explain the topic itself from general knowledge, while claims about your business (services, projects, experience, capabilities and so on) must come from your profile or cited pages. Answer sections about the business that cite neither are removed, and anything the website doesn't substantiate is listed under "Not covered on this website" instead of being guessed.
* Less filler: passages that match the search only weakly are no longer sent to the AI, generic background is limited to one short section, and takeaways that restate the headline or each other are dropped.
* The search page loads immediately and the answer appears when ready. Answers are no longer generated on every keystroke.
* Cached answers are cleared when searchable content is published, updated or unpublished, and when settings change.
* Removed the separate Recommendations section. "Custom System Prompt" is now "Additional Instructions".
* AI requests get a longer timeout, for slower reasoning models.

= 3.2.0 =
* Plugin renamed from "Advanced AI Search" to "Mav AI Powered Search". The slug and text domain changed from advance-ai-search to mav-ai-powered-search, and the main plugin file is now mav-ai-powered-search.php.
* Function, hook, option, AJAX action, shortcode and CSS class prefix changed from aias to mav_aips (CSS: mav-aips-). Use the `[mav_aips_suggestions]` shortcode and `mav_aips_search_suggestions()` template tag; the old `[aias_suggestions]`, `[aiss_suggestions]`, `aias_search_suggestions()` and `aiss_search_suggestions()` still work but are deprecated.
* Existing settings and usage statistics are migrated automatically on upgrade.

= 3.1.0 =
* Plugin renamed from "Ai Powred Search" to "Advanced AI Search". The slug and text domain changed from ai-powred-search to advance-ai-search.
* Function, hook, option, AJAX action, shortcode and CSS class prefix changed from aiss to aias. Use the `[aias_suggestions]` shortcode and `aias_search_suggestions()` template tag; the old `[aiss_suggestions]` and `aiss_search_suggestions()` still work but are deprecated.
* Existing settings and usage statistics are migrated automatically on upgrade.

= 3.0.0 =
* Plugin renamed from "Search Press AI" to "Ai Powred Search" (slug and text domain: ai-powred-search).
* AI requests now go through the WordPress AI Client (WordPress 7.0+) instead of calling OpenAI, Google Gemini, and Anthropic Claude directly. Pick your provider and enter its credentials under Settings → Connectors.
* Removed the plugin's own provider, model, and API key settings. API keys saved by earlier versions are deleted from the database on upgrade.
* Removed the per-model cost estimate. Check your AI provider's dashboard for billing.
* "Test API" is now "Test Connection" and shows which provider and model responded.
* Requires WordPress 7.0 or later.

= 2.2.0 =
* Added Anthropic Claude as a third AI provider option, alongside OpenAI and Google Gemini.
* AI answers are now grounded in content that actually matches the visitor's search, instead of generic recent posts.
* Added a "key points" list alongside the main AI answer.
* AI responses are now schema-enforced for reliable, consistently structured output.
* When no keyword match is found, the AI now judges general site content for genuine relevance instead of always falling back to a plain post list.

= 2.1.0 =
* Updated default AI models for OpenAI and Google Gemini to current, supported models.
* Added automatic migration of previously-configured retired model IDs.

= 2.0.0 =
* Added Google Gemini as an alternative AI provider to OpenAI.

= 1.0.0 =
* Initial release.

== Upgrade Notice ==

= 3.3.0 =
Much better answers. After upgrading, fill in the new Business Profile setting (use "Draft from site content"). Searches now use two AI requests instead of one. If you styled the recommendations box with custom CSS, it has been removed.

= 3.2.0 =
Plugin renamed to Mav AI Powered Search. Settings migrate automatically. If you styled the suggestions box with custom CSS, update selectors from .aias- to .mav-aips-.

= 3.0.0 =
Requires WordPress 7.0+. AI requests now use the WordPress AI Client. Before upgrading, connect your AI provider under Settings → Connectors, because the API keys saved in this plugin's settings are removed during the upgrade.
