10up / ElasticPress

A fast and flexible search and query engine for WordPress.
https://elasticpress.io
GNU General Public License v2.0
1.23k stars 312 forks source link

Does carbonfield search work? #3900

Closed rstrah closed 2 months ago

rstrah commented 3 months ago

I tried to add a search for carbonfields on the /wp-admin/admin.php?page=elasticpress-weighting page via “ADD FIELD” but it did not produce results.

Container::make('post_meta', __('Руководители', 'crb')) ->where('post_template', '=', 'management.php') ->where( 'current_user_role', 'IN', array( 'carbonfields_manager', 'administrator' ) ) ->add_fields( array( Field::make('complex', 'crb_manager_description', 'Руководитель') ->add_fields( array( Field::make('image', 'manager_photo', 'Фото')->set_value_type('url'), Field::make('text', 'manager_name', 'Фио'), Field::make('text', 'manager_role', 'Должность'), Field::make('rich_text', 'manager_bio', 'Биография'), Field::make('rich_text', 'manager_reception', 'Время приёма'), ) ) ) ); I tried adding meta fields "manager_name, _manager_name,manager_name,_crb_manager_description,crb_manager_description,crb_manager_description" to the search but to no avail.

Code of Conduct

felipeelia commented 2 months ago

@rstrah did you try what I suggested in the thread you opened in WP.org? Using the debugging add-on you will see that is being queried from Elasticsearch.

If Carbon Fields does not use WP_Query and runs SQL queries directly into the database, you'll have to build that integration yourself.

rstrah commented 2 months ago

@felipeelia Hi.

{
    "from": 0,
    "size": 10,
    "post_filter": {
        "bool": {
            "must": [
                {
                    "terms": {
                        "post_type.raw": [
                            "post",
                            "page",
                            "event",
                            "newspaper",
                            "district",
                            "cae",
                            "prm",
                            "aaq",
                            "aqq-appeals",
                            "meri",
                            "authors-column",
                            "video",
                            "programs",
                            "news",
                            "qsm_quiz"
                        ]
                    }
                },
                {
                    "term": {
                        "post_status": "publish"
                    }
                },
                {
                    "bool": {
                        "must_not": [
                            {
                                "terms": {
                                    "meta.ep_exclude_from_search.raw": [
                                        "1"
                                    ]
                                }
                            }
                        ]
                    }
                }
            ]
        }
    },
    "query": {
        "function_score": {
            "query": {
                "bool": {
                    "should": [
                        {
                            "bool": {
                                "must": [
                                    {
                                        "bool": {
                                            "should": [
                                                {
                                                    "multi_match": {
                                                        "query": "ep_autosuggest_placeholder",
                                                        "type": "phrase",
                                                        "fields": [
                                                            "post_title^100",
                                                            "post_excerpt^100",
                                                            "post_content^100",
                                                            "terms.ep_custom_result.name^9999",
                                                            "meta.\\_crb\\_manager\\_description|%.value^100",
                                                            "meta._crb_manager_description|%.value^100"
                                                        ],
                                                        "boost": 3
                                                    }
                                                },
                                                {
                                                    "multi_match": {
                                                        "query": "ep_autosuggest_placeholder",
                                                        "fields": [
                                                            "post_title^100",
                                                            "post_excerpt^100",
                                                            "post_content^100",
                                                            "meta.\\_crb\\_manager\\_description|%.value^100",
                                                            "meta._crb_manager_description|%.value^100",
                                                            "post_title.suggest^1"
                                                        ],
                                                        "operator": "and",
                                                        "boost": 1,
                                                        "fuzziness": "auto"
                                                    }
                                                },
                                                {
                                                    "multi_match": {
                                                        "query": "ep_autosuggest_placeholder",
                                                        "type": "cross_fields",
                                                        "fields": [
                                                            "post_title^1",
                                                            "post_excerpt^1",
                                                            "post_content^1",
                                                            "terms.ep_custom_result.name^1",
                                                            "meta.\\_crb\\_manager\\_description|%.value^1",
                                                            "meta._crb_manager_description|%.value^1"
                                                        ],
                                                        "boost": 1,
                                                        "analyzer": "standard",
                                                        "tie_breaker": 0.5,
                                                        "operator": "and"
                                                    }
                                                }
                                            ]
                                        }
                                    }
                                ],
                                "filter": [
                                    {
                                        "match": {
                                            "post_type.raw": "page"
                                        }
                                    }
                                ]
                            }
                        },
                        {
                            "bool": {
                                "must": [
                                    {
                                        "bool": {
                                            "should": [
                                                {
                                                    "multi_match": {
                                                        "query": "ep_autosuggest_placeholder",
                                                        "type": "phrase",
                                                        "fields": [
                                                            "post_title^82",
                                                            "post_excerpt^59",
                                                            "post_content^65",
                                                            "post_author.display_name^54",
                                                            "terms.ep_custom_result.name^9999",
                                                            "terms.news-district.name",
                                                            "terms.news-list.name"
                                                        ],
                                                        "boost": 3
                                                    }
                                                },
                                                {
                                                    "multi_match": {
                                                        "query": "ep_autosuggest_placeholder",
                                                        "fields": [
                                                            "post_title^82",
                                                            "post_excerpt^59",
                                                            "post_content^65",
                                                            "post_author.display_name^54",
                                                            "terms.news-district.name",
                                                            "terms.news-list.name",
                                                            "post_title.suggest^1",
                                                            "term_suggest^1"
                                                        ],
                                                        "operator": "and",
                                                        "boost": 1,
                                                        "fuzziness": "auto"
                                                    }
                                                },
                                                {
                                                    "multi_match": {
                                                        "query": "ep_autosuggest_placeholder",
                                                        "type": "cross_fields",
                                                        "fields": [
                                                            "post_title^1",
                                                            "post_excerpt^1",
                                                            "post_content^1",
                                                            "post_author.display_name^1",
                                                            "terms.ep_custom_result.name^1",
                                                            "terms.news-district.name",
                                                            "terms.news-list.name"
                                                        ],
                                                        "boost": 1,
                                                        "analyzer": "standard",
                                                        "tie_breaker": 0.5,
                                                        "operator": "and"
                                                    }
                                                }
                                            ]
                                        }
                                    }
                                ],
                                "filter": [
                                    {
                                        "match": {
                                            "post_type.raw": "news"
                                        }
                                    }
                                ]
                            }
                        }
                    ]
                }
            },
            "functions": [
                {
                    "exp": {
                        "post_date_gmt": {
                            "scale": "14d",
                            "decay": 0.25,
                            "offset": "7d"
                        }
                    }
                },
                {
                    "weight": 0.001
                }
            ],
            "score_mode": "sum",
            "boost_mode": "multiply"
        }
    },
    "sort": [
        {
            "_score": {
                "order": "desc"
            }
        }
    ],
    "highlight": {
        "fields": {
            "post_title": {
                "pre_tags": [
                    "<mark class='ep-highlight'>"
                ],
                "post_tags": [
                    "<\/mark>"
                ],
                "type": "plain",
                "number_of_fragments": 0
            },
            "post_content": {
                "pre_tags": [
                    "<mark class='ep-highlight'>"
                ],
                "post_tags": [
                    "<\/mark>"
                ],
                "type": "plain",
                "number_of_fragments": 0
            },
            "post_excerpt": {
                "pre_tags": [
                    "<mark class='ep-highlight'>"
                ],
                "post_tags": [
                    "<\/mark>"
                ],
                "type": "plain",
                "number_of_fragments": 0
            }
        }
    },
    "suggest": {
        "text": "ep_autosuggest_placeholder",
        "ep_suggestion": {
            "phrase": {
                "field": "post_content.shingle",
                "max_errors": 2,
                "direct_generator": [
                    {
                        "field": "post_content.shingle"
                    }
                ]
            }
        }
    }
}

How to correctly extract the meta key for elastic from a post? A small clarification, are these fields repeatable an unlimited number of times? Do I understand correctly that I need this line? "meta.\\_crb\\_manager\\_description|%.value^100",

github-actions[bot] commented 2 months ago

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.

rstrah commented 2 months ago

i have problem

felipeelia commented 2 months ago

@rstrah I'm not sure how you are adding those fields in the Weighting Dashboard, but it should not have those symbols. They should look like meta._crb_manager_description.value^1. The query you pasted here is the autosuggest placeholder and NOT an actual query being sent to Elasticsearch. You'll need to make sure you are calling a search using WP_Query or a WP_Query instance with 'ep_integrate' => true to have it connected to Elasticsearch.

github-actions[bot] commented 2 months ago

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[bot] commented 2 months ago

This issue has been automatically closed because there has been no response to our request for more information in the past 3 days. With only the information that is currently available, we are unable to take further action on this ticket. Please reach out if you have found or find the answer we need so that we can investigate further. When the information is ready, you can re-open this ticket to share it with us.