Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'Did you mean' in FSE theme #3993

Open
1 task done
Ecknauer opened this issue Nov 1, 2024 · 4 comments
Open
1 task done

'Did you mean' in FSE theme #3993

Ecknauer opened this issue Nov 1, 2024 · 4 comments
Labels

Comments

@Ecknauer
Copy link

Ecknauer commented Nov 1, 2024

Describe your question

Hi,

I have tried to place
<?php do_action( 'ep_suggestions' ); ?>
inside of Classic theme and FSE theme but to no avail.

From reading the article on ElasticPress Docs I couldn't understand if I have to place this code inside of search form template (e.g. <form></form>) or search results template?

I have products with the title, for instance, Harry Potter. I have tried to look up items by the string: "happy rotter" to cause no search results. However, upon expecting the query with WP Query + ElasticPress Debug Add-on it doesn't return any suggestions results.

{
    "took": 246,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "skipped": 0,
        "failed": 0
    },
    "hits": {
        "total": {
            "value": 0,
            "relation": "eq"
        },
        "max_score": null,
        "hits": []
    },
    "suggest": {
        "ep_suggestion": [
            {
                "text": "happy rotter",
                "offset": 0,
                "length": 12,
                "options": []
            }
        ]
    }
}

Code of Conduct

  • I agree to follow this project's Code of Conduct
@felipeelia
Copy link
Member

Can you please share your ElasticPress Status Report, @Ecknauer? I'm mostly interested in knowing your ES version. Also, did you try only rotter?

@Ecknauer
Copy link
Author

Ecknauer commented Nov 9, 2024

Hi, I will update my op as I figured out how to get suggestions for default 'post_content' and also 'post_excerpt', 'post_title'. So other will have easier time figuring out on how to implement 'Did you mean' feature.

The only thing that I can't still achieve is to add post meta filed (acf) to the mapping and being able to get suggestion options on it. For instance where 'ep_acf_test' is a post meta field:

// Shingle token filter.
$mapping['settings']['analysis']['filter']['shingle_filter'] = [
	'type'             => 'shingle',
	'min_shingle_size' => 2,
	'max_shingle_size' => 3,
];

// Custom analyzer.
$mapping['settings']['analysis']['analyzer']['trigram'] = [
	'type'      => 'custom',
	'tokenizer' => 'standard',
	'filter'    => [
		'lowercase',
		'shingle_filter',
	],
];

// Add meta field to the mapping
$mapping['mappings']['properties']['meta']['properties']['ep_acf_test'] = [
	'type' => 'text',
	'fields' => [
		'shingle' => [
			'type'     => 'text',
			'analyzer' => 'trigram',
		],
		'raw'        => [
			'type'         => 'keyword',
			'ignore_above' => 10922,
		],
	],
];

And then I use this filter to add additional suggester on top default 'ep_suggestion':

add_filter('ep_post_formatted_args', function ($formatted_args, $args, $wp_query) {

    $search_analyzer_ = [
        'phrase' => [
            'field'            => 'meta.ep_acf_test.shingle',
            'max_errors'       => 2,
            'direct_generator' => [
                [
                    'field' => 'meta.ep_acf_test.shingle',
                ],
            ],
        ],
    ];

    $formatted_args['suggest']['ep_suggestion_meta'] = $search_analyzer;

    return $formatted_args;
}, 20, 3);

Status Report:

## Failed Queries ##



## WordPress ##

### WordPress Environment ###
wp_version: 6.6.2
home_url: 
site_url: 
is_multisite: false
plugins: Advanced Custom Fields PRO (6.3.10), ElasticPress (5.1.3), ElasticPress Debugging Add-On (3.1.0), LiteSpeed Cache (6.5.2), Query Monitor (3.16.4), Sii4 (1.0), White Label CMS (2.7.6), WooCommerce (9.3.3), and WP Crontrol (1.17.0)
revisions: all

### Server Environment ###
php_version: 8.3.10
memory_limit: 40M
timeout: 240



## Indexable Content ##

###— ###
post_count: 0
page_count: 6
product_count: 52,739
post_meta_keys: 0
page_meta_keys: 0
product_meta_keys: 17
total-all-post-types: 17
distinct-meta-keys: _sku, _regular_price, total_sales, _tax_status, _tax_class, _manage_stock, _backorders, _sold_individually, _virtual, _downloadable, _stock, _stock_status, _wc_average_rating, _product_version, _price, _thumbnail_id, and _product_image_gallery



## ElasticPress ##

### Settings ###
host: http://127.0.0.1:9200
index_prefix: 
language: site-default
per_page: 350
network_active: false

### Timeouts ###
request_timeout: 5
index_document_timeout: 15
bulk_request_timeout: 30



## Elasticsearch Indices ##

### temp-post-1 ###
health: yellow
status: open
index: temp-post-1
uuid: 3lFlQVUKTFyhlNcjNo0tAQ
pri: 5
rep: 1
docs.count: 54943
docs.deleted: 0
store.size: 209.1mb
pri.store.size: 209.1mb
total_fields_limit: 5000
analyzer_language: spanish
stop_language: _spanish_
snowball_language: Spanish



## Last Sync ##

### 2024/11/08 1:27:41 pm ###
method: WP Dashboard
is_full_sync: Yes
end_date_time: 2024/11/08 1:35:38 pm
total_time: 0 hours, 7 minutes, 57 seconds
total: 54943
synced: 54943
skipped: 0
failed: 0
errors: array (
)
trigger: manual
final_status: success



## Feature Settings ##

### Did You Mean ###
active: true
force_inactive: false
search_behavior: list

### E-Commerce ###
active: true
force_inactive: false
orders: 0

### Filters ###
active: true
force_inactive: false
match_type: all

### Post Search ###
active: true
decaying_enabled: 0
force_inactive: false
highlight_enabled: 0
highlight_excerpt: 0
highlight_tag: mark
synonyms_editor_mode: simple
synonyms: <pre># Defined synonyms.
runner, running shoe, sneaker, tennis shoe, trainer

# Defined hyponyms.
blue => blue, aqua, azure, cerulean, cyan, ultramarine

# Defined replacements.
supposably => supposedly
flustrated => flustered, frustrated
intensive purposes => intents and purposes</pre>
weighting: array (
  'post' => 
  array (
    'post_title' => 
    array (
      'weight' => 1,
      'enabled' => false,
    ),
    'post_content' => 
    array (
      'weight' => 1,
      'enabled' => false,
    ),
    'post_excerpt' => 
    array (
      'weight' => 1,
      'enabled' => false,
    ),
    'author_name' => 
    array (
      'weight' => 1,
      'enabled' => false,
    ),
    'terms.post_tag.name' => 
    array (
      'weight' => 1,
      'enabled' => false,
    ),
    'terms.category.name' => 
    array (
      'weight' => 1,
      'enabled' => false,
    ),
  ),
  'page' => 
  array (
    'post_title' => 
    array (
      'weight' => 1,
      'enabled' => false,
    ),
    'post_content' => 
    array (
      'weight' => 1,
      'enabled' => false,
    ),
    'post_excerpt' => 
    array (
      'weight' => 1,
      'enabled' => false,
    ),
    'author_name' => 
    array (
      'weight' => 1,
      'enabled' => false,
    ),
  ),
  'product' => 
  array (
    'post_title' => 
    array (
      'enabled' => true,
      'weight' => 80,
    ),
    'post_content' => 
    array (
      'weight' => 1,
      'enabled' => false,
    ),
    'post_excerpt' => 
    array (
      'enabled' => true,
      'weight' => 20,
    ),
    'meta._sku.value' => 
    array (
      'weight' => 100,
      'enabled' => true,
    ),
    'meta._variations_skus.value' => 
    array (
      'weight' => 1,
      'enabled' => false,
    ),
    'terms.product_cat.name' => 
    array (
      'enabled' => true,
      'weight' => 60,
    ),
  ),
)

Copy link

It has been 3 days since more information was requested from you in this issue and we have not heard back. This issue is now marked as stale and will be closed in 3 days, but if you have more information to add then please comment and the issue will stay open.

@github-actions github-actions bot added the stale label Nov 12, 2024
@Ecknauer
Copy link
Author

Still waiting for a reply. Don't mark the issue as closed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants