Skip to content

Crocoblock/jet-ai-search

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

AI Search experiment

Experimental plugin for AI-driven search by Crocoblock. This plugin is literally AI search for your website. Allows parse you website content by Open AI and than search over parsed content also using Open AI possibilities. Returns a lot more better results than default WordPress search. One more advantage over deafult search - spelling insensetivity.

Quick Start

Step 1

Install and activate plugin (as usual WP plugin)

Step 2

Go to Settings/AI Search

image

Set up your Open AI API key and adjust other settings like you need (but better t test other settings later, when you set up all data)

Step 3

Fetch some starting content, because plugin will work only with own fetched fragments, not content directly.

Step 4

Enable required post types for auto-fetch. Auto fetch is required to plugin automatically update fragmnets when you create/update/delete posts of selected post type.

Advanced Usage

Allow to search by custom field values

Next code snippet allow you to add value from meta field to parsed content fragments. Using this you can run AI search by selected custom field values, not only posts content/excerpt.

add_filter( 'jet-ai-search/post-fragments', function( $fragments, $post, $parser ) {

	// Optional part - making sure we work with posts of need type
	if ( 'product' !== $post->post_type ) {
		return $fragments;
	}

	// Getting field value
	$field_name = 'description-for-the-search';
	$custom_description = get_post_meta( $post->ID, $field_name, true );

	// If value is empty - nothing to do here
	if ( ! $custom_description ) {
		return $fragments;
	}

	// Reset previously parsed stack and store new fragment
	$parser->reset_results();

	$parser->set_stack_defaults( [
		'post_id'    => $post->ID,
		'post_url'   => $post->guid,
		'post_title' => $post->post_title,
		'source'     => $post->post_type,
	] );

	// Optional - store post title with field value for better context
	$title = $parser->prepare_heading( $post->post_title );

	$fragment = $parser->prepare_fragment( $custom_description );

	$parser->stack_result( [
		'fragment' => $title . $fragment
	], true );

	// Merge stored fragment with all previous fragmnets
	$fragments = array_merge( $fragments, $parser->get_result() );

	return $fragments;
	
}, 10, 3 );

After adding this code, you need to re-fetch content of required post type to make sure new fragments stored in DB.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published