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

WC Orders: properly add ID to fields when searching for digits #2666

Merged
merged 3 commits into from
Mar 22, 2022

Conversation

felipeelia
Copy link
Member

Description of the Change

This PR fixes the implementation of #2554. A search term will always be a string, so instead of is_int() we should be using ctype_digit(). It also fixes tests, properly casting the search term to a string, as WP core would do.

Changelog Entry

Fixed: Searches by WooCommerce Order ID.

Credits

Props @felipeelia

@felipeelia felipeelia self-assigned this Mar 18, 2022
@felipeelia felipeelia added this to the 4.1.0 milestone Mar 18, 2022
@felipeelia felipeelia merged commit 0c040f0 into develop Mar 22, 2022
@felipeelia felipeelia deleted the fix/wc-search-by-order-id branch March 22, 2022 10:33
@blenkhn
Copy link

blenkhn commented Mar 22, 2022

I just uploaded the file now and will report in a few minutes after the resync. I also removed the potential issue with the extra custom field.

The search for the order numbers worked well. when I did the search for a person's name in the orders, I got a person that did not match at all. I did not see anywhere in the order where krista was mentioned.

Did not fix the user indexing errors. I did not copy the error just yet I will have to resync later to see it I did turnon the query log though incase you want to see other queries.

I posted the query body below

@blenkhn
Copy link

blenkhn commented Mar 22, 2022

{
"from": 0,
"size": 40,
"sort": [
{
"_score": {
"order": "desc"
}
}
],
"query": {
"function_score": {
"query": {
"bool": {
"should": [
{
"multi_match": {
"query": "krista",
"type": "phrase",
"fields": [
"post_title",
"post_content",
"post_excerpt",
"meta._order_key.value",
"meta._billing_company.value",
"meta._billing_address_1.value",
"meta._billing_address_2.value",
"meta._billing_city.value",
"meta._billing_postcode.value",
"meta._billing_country.value",
"meta._billing_state.value",
"meta._billing_email.value",
"meta._billing_phone.value",
"meta._shipping_address_1.value",
"meta._shipping_address_2.value",
"meta._shipping_city.value",
"meta._shipping_postcode.value",
"meta._shipping_country.value",
"meta._shipping_state.value",
"meta._billing_last_name.value",
"meta._billing_first_name.value",
"meta._shipping_first_name.value",
"meta._shipping_last_name.value",
"meta._items.value"
],
"boost": 3
}
},
{
"multi_match": {
"query": "krista",
"fields": [
"post_title",
"post_content",
"post_excerpt",
"meta._order_key.value",
"meta._billing_company.value",
"meta._billing_address_1.value",
"meta._billing_address_2.value",
"meta._billing_city.value",
"meta._billing_postcode.value",
"meta._billing_country.value",
"meta._billing_state.value",
"meta._billing_email.value",
"meta._billing_phone.value",
"meta._shipping_address_1.value",
"meta._shipping_address_2.value",
"meta._shipping_city.value",
"meta._shipping_postcode.value",
"meta._shipping_country.value",
"meta._shipping_state.value",
"meta._billing_last_name.value",
"meta._billing_first_name.value",
"meta._shipping_first_name.value",
"meta._shipping_last_name.value",
"meta._items.value"
],
"boost": 1,
"fuzziness": "auto",
"operator": "and"
}
},
{
"multi_match": {
"query": "krista",
"type": "cross_fields",
"fields": [
"post_title",
"post_content",
"post_excerpt",
"meta._order_key.value",
"meta._billing_company.value",
"meta._billing_address_1.value",
"meta._billing_address_2.value",
"meta._billing_city.value",
"meta._billing_postcode.value",
"meta._billing_country.value",
"meta._billing_state.value",
"meta._billing_email.value",
"meta._billing_phone.value",
"meta._shipping_address_1.value",
"meta._shipping_address_2.value",
"meta._shipping_city.value",
"meta._shipping_postcode.value",
"meta._shipping_country.value",
"meta._shipping_state.value",
"meta._billing_last_name.value",
"meta._billing_first_name.value",
"meta._shipping_first_name.value",
"meta._shipping_last_name.value",
"meta._items.value"
],
"boost": 1,
"analyzer": "standard",
"tie_breaker": 0.5,
"operator": "and"
}
}
]
}
},
"functions": [
{
"exp": {
"post_date_gmt": {
"scale": "14d",
"decay": 0.25,
"offset": "7d"
}
}
},
{
"weight": 0.001000000000000000020816681711721685132943093776702880859375
}
],
"score_mode": "sum",
"boost_mode": "multiply"
}
},
"post_filter": {
"bool": {
"must": [
{
"terms": {
"post_type.raw": [
"shop_order"
]
}
},
{
"terms": {
"post_status": [
"wc-pending",
"wc-processing",
"wc-on-hold",
"wc-completed",
"wc-cancelled",
"wc-refunded",
"wc-failed"
]
}
}
]
}
}
}

@blenkhn
Copy link

blenkhn commented Mar 22, 2022

Does elastic search work with Active Custom Fields?

@felipeelia
Copy link
Member Author

@blenkhn please let's take the communication about the other problems in #2651 so things can be tracked easier later.

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

Successfully merging this pull request may close these issues.

3 participants