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

Does carbonfield search work? #3900

Closed
1 task done
rstrah opened this issue Apr 26, 2024 · 7 comments
Closed
1 task done

Does carbonfield search work? #3900

rstrah opened this issue Apr 26, 2024 · 7 comments

Comments

@rstrah
Copy link

rstrah commented Apr 26, 2024

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

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

@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
Copy link
Author

rstrah commented May 3, 2024

@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",

Copy link

github-actions bot commented May 7, 2024

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 May 7, 2024
@rstrah
Copy link
Author

rstrah commented May 8, 2024

i have problem

@github-actions github-actions bot removed the stale label May 9, 2024
@felipeelia
Copy link
Member

@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.

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 May 13, 2024
Copy link

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.

@github-actions github-actions bot closed this as not planned Won't fix, can't repro, duplicate, stale May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants