Skip Navigation

[Resolved] Min and Max fields in search not returning correct results

This support ticket is created 4 years, 4 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 13 replies, has 3 voices.

Last updated by MargeP6083 4 years, 4 months ago.

Assisted by: Nigel.

Author
Posts
#1382691

I am trying to create a age range search of min (more than or equal) and max (less than or equal) in a page view. Search is set to number. Using the new content block custom search page.

Link to a page where the issue can be seen: hidden link

The results are wrong or none at all.

#1382927

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I checked on your install and I see that you have created block view that is set to query the "Talent Profiles" post type.

I see the custom fields group is attached to post type "Talent Profiles" is the "Talent Information". Now, within this custom fields group, I see two fields "Minimum Acting Age" and "Maximum Acting Age". If I'm not wrong, you want to filter by these two number fields for the age rage - correct?

#1383123

Yes, the queries return in correct results when using both or just one number field.

#1383765

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Sorry but as you say it works fine and shows correct results.

To eliminate any confusion/doubt, What combination I should use that you want to report that its not working as expected? Can you please share exact steps, what filters I should use to reproduce the issue?

#1384163

*incorrect results. Sorry typo.
There are two users in the system right now. If I put in an age range let's say that I'm looking for, the correct result doesn't show.

Example, I am searching for a person who has an age range of 60 min and 70 max. There's a person who has a range that falls within there. His profile doesn't show up. The search fields are set. >= is set for min and =< is set for Max.

It doesn't work even when I use only one search field.

#1385775

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Thanks, I've changed the filter settings on your view's custom search block area for the min and max-age fields.

I've changed the minimum age's comparison value as "lower than or equal to", please check the following screenshot:
=> hidden link

And, the maximum age's comparison value as "greater than or equal to", please check the following screenshot:
=> hidden link

Then, I searched with the age 60 min and 70 max and I can see the following result:
=> hidden link

Can you please confirm it works at your end as well.

#1386065

Hi, This doesn't work for me.

The user is searching for people in a range. The range should be true if the numbers overlap the range.

Example: User searches for people who fall into age range 49____________71. There is a user who has range 50____70, but that user doesn't show up in the result.

I want to show the users in the range that fall inside the search parameters.

49____________71 - search range, I want to see all users who fall in this range.
50__________70 -True, this person falls in that range.

Min is greater than or equal to 49. (50 is greater than 49)
Max is less than or equal to 71. (70 is less than 71)

It's not working. See link.
hidden link

#1386599

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Example: User searches for people who fall into age range 49____________71. There is a user who has range 50____70, but that user doesn't show up in the result.
==>
Considering the values you added to your post: Actual values added to post: Min: 50 and Max: 80
- hidden link

If you want to search in within the range 49____________71, then we need to set the filters to
- So, the comparison will be 50 > 49 and 80 > 71
- that means, we need to set the filters as min age >= search value (49) AND max-age is >= search value (71)

But, now:
it will become contrary when you use the search value 60 min and 70 max as you shared in your reply here:
=> https://toolset.com/forums/topic/min-and-max-fields-in-search-not-returning-correct-results/#post-1384163

Actual values added to the post: Min: 50 and Max: 70
- So, the comparison will be 50 > 60 and 80 > 70 (the condition will become false with 50 > 60 )
- that means, filters will be set as as min age actual 50 >= search value (60) AND max-age actual 80 >= search value (70)
- in this case you will not find any result.

For now, I've adjusted the filters as per your within the range 49____________71 value and if you can check it will show the result.
=> hidden link

#1389107

Hi, I'm sorry for the late response, but that doesn't work either. In fact, that page looks broken. I've not been in the admin since my last message to you.

hidden link

The age ranges have disappeared from the the profile excerpts. (Why is that?) For example, the man had a range of 50 - 80. The woman has a range of 18-35. That is gone from the search page. hidden link I have not edited this page. I'm wondering what happened. This happened before updating any plugins.

(If you are adding custom code, can you post the location and any code you've added?)

I'm not sure why this is so difficult.

When I search for a user min-max of 20-25, I get a wrong response.

The SEARCH RESULT should be the woman who has a range of 18 to 35. She fits that user search.

1. Minimum field should show the user with a MIN number that is EQUAL to or GREATER THAN the number the user inserts in the search box. (20 is greater than 18. True!)

2. Maximum field should return the USER who has a MAX number EQUAL to or LESS THAN 25. (25 is less than 35. True!)

This is big wrong since it shows the man who has a range of 50 - 80 in his profile.

hidden link

Can you bump this to the developer who created this part of the app? Maybe something is broken in the code.

I need to have this search feature ready for the customer in a couple days plus other features. I can't move forward until this is fixed.

Thank you

#1389199

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

The age ranges have disappeared from the the profile excerpts. (Why is that?) For example, the man had a range of 50 - 80. The woman has a range of 18-35. That is gone from the search page. hidden link I have not edited this page. I'm wondering what happened. This happened before updating any plugins.
==>
I do not see any issue with page range or anything. It works just fine: hidden link
Maybe you should try to clear the cache as I see you are using plugin SG Optimizer

That is why I shared the information that how the comparison will be applied in backend with the value in my previous reply and how it will compare the actual value in comparison of the search input value.
=> https://toolset.com/forums/topic/min-and-max-fields-in-search-not-returning-correct-results/#post-1386599

If you will check my above reply, how comparison works is bit different than you think.

When I search for a user min-max of 20-25, (the woman who has a range of 18 to 35 that are actual values available)
- filter set minimum age >= search value
- filter set maximum age <= search value

This is how the query will build:

SELECT SQL_CALC_FOUND_ROWS  wpae_posts.ID FROM wpae_posts  INNER JOIN wpae_postmeta ON ( wpae_posts.ID = wpae_postmeta.post_id )  INNER JOIN wpae_postmeta AS mt1 ON ( wpae_posts.ID = mt1.post_id ) WHERE 1=1  AND wpae_posts.ID NOT IN (239) AND ( 
  ( wpae_postmeta.meta_key = 'wpcf-minimum-age' AND CAST(wpae_postmeta.meta_value AS SIGNED) >= '20' ) 
  AND 
  ( mt1.meta_key = 'wpcf-maximum-age' AND CAST(mt1.meta_value AS SIGNED) <= '25' )
) AND wpae_posts.post_type = 'talent' AND ((wpae_posts.post_status = 'publish' OR wpae_posts.post_status = 'private')) GROUP BY wpae_posts.ID ORDER BY wpae_posts.post_date DESC LIMIT 0, 10

As you can see:
- minimum age comparision will be translated to:
- 18 >= 20

- maximum age comparison will be translated to:
- 35 <= 25

Both conditions will become false. You need to place actual values.

That is why I shared the solution here, if you set the filter as I suggested with the following reply - you will get the woman who has a range of 18 to 35 when you enter search values min 20 and max 25:
=> https://toolset.com/forums/topic/min-and-max-fields-in-search-not-returning-correct-results/#post-1385775

So, for now, I already set the filters as explained in the above reply.

But, then you again shared another scenario:
49____________71 - search range, I want to see all users who fall in this range.
==>
This range will NOT show the results:

SELECT SQL_CALC_FOUND_ROWS  wpae_posts.ID FROM wpae_posts  INNER JOIN wpae_postmeta ON ( wpae_posts.ID = wpae_postmeta.post_id )  INNER JOIN wpae_postmeta AS mt1 ON ( wpae_posts.ID = mt1.post_id ) WHERE 1=1  AND wpae_posts.ID NOT IN (239) AND ( 
  ( wpae_postmeta.meta_key = 'wpcf-minimum-age' AND CAST(wpae_postmeta.meta_value AS SIGNED) <= '49' ) 
  AND 
  ( mt1.meta_key = 'wpcf-maximum-age' AND CAST(mt1.meta_value AS SIGNED) >= '71' )
) AND wpae_posts.post_type = 'talent' AND ((wpae_posts.post_status = 'publish' OR wpae_posts.post_status = 'private')) GROUP BY wpae_posts.ID ORDER BY wpae_posts.post_date DESC LIMIT 0, 10

-- As you can see the minimum age comparision will translate to: 50 <= 49 (which is false)

50__________70 -True, this person falls in that range.
===>
This range will show the results.

SELECT SQL_CALC_FOUND_ROWS  wpae_posts.ID FROM wpae_posts  INNER JOIN wpae_postmeta ON ( wpae_posts.ID = wpae_postmeta.post_id )  INNER JOIN wpae_postmeta AS mt1 ON ( wpae_posts.ID = mt1.post_id ) WHERE 1=1  AND wpae_posts.ID NOT IN (239) AND ( 
  ( wpae_postmeta.meta_key = 'wpcf-minimum-age' AND CAST(wpae_postmeta.meta_value AS SIGNED) <= '50' ) 
  AND 
  ( mt1.meta_key = 'wpcf-maximum-age' AND CAST(mt1.meta_value AS SIGNED) >= '71' )
) AND wpae_posts.post_type = 'talent' AND ((wpae_posts.post_status = 'publish' OR wpae_posts.post_status = 'private')) GROUP BY wpae_posts.ID ORDER BY wpae_posts.post_date DESC LIMIT 0, 10

So, all cases for min-max you shared are correct but 49____________71 beause the actual value for min age is set to 50.

Now, when you search for the following range: hidden link
- 20-25:
=> it will show you one result with woman pic

- 50-70:
=> it will show you one result with man pic

- 60-70:
=> it will show you one result with man pic

Let me know if you still have any confusion or you want to pass this ticket to support a person who works more closely with your timezone.

#1389919
2019-11-22_1104.png

It doesn't quite work.

For example, if I search min: 15 max: 20, there are no results returned. The woman should appear since she falls within that scope. She is within that range. There seems to be some operation missing in this range comparison. Is there some way to use "or" to solve this problem? Does that make sense?

The woman is greater than 15 so there would be overlap
18_________________35
15_______20

#1389937

That wouldn't work either since 15 did not return the correct result.

Search for minimum "15" should result in the woman's profile. And it did not. Used incognito window, so there was no cache.

And when I use the max of "15", it returns both man and woman. That should return nothing. see below screen. SEarch was in incognito window. hidden link

Sorry, it would be easier to talk to someone in my timezone.

#1390095

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Marge

My shift is over but I can see you need a solution—which I have—so let me share it briefly with you, I need to leave soon.

Hopefully it will be sufficient. If you have further problems with it, I suggest you open a new ticket (linking to this one).

You might still catch Shane who is still working today, and if not, Christian will be working in your timezone on Sunday.

The first key thing you need to know is that I'm not sure if you can do this with the new Block Editor for creating Views, and you may have to use the classic Views editor. (I will have time to revisit this on Monday to check, but you can always try yourself.)

I have set a basic version of this up for you which is working.

The View is inserted on this page: hidden link

Test it, it should work.

The View can be edited in the Classic mode here: hidden link

To make your range search work, I had to swap the labels of the max and min filters and reverse the order (so that when users think they are entering the value for the max filter they are actually entering the value for the min filter and vice versa, and then the actual comparisons are different than you would expect.

I describe how it works in another thread: https://toolset.com/forums/topic/filter-by-range-within-range/#post-501081

I've included the same filters as your original View, you shouldn't have to change much aside from possibly styling.

For the output, I chose a Bootstrap grid, and then the template for each result is made using the Block Editor, which you should be familiar with.

Sorry I can't do more now, open a new ticket for continuing help over the weekend, and feel free to ask anything here that can wait till Monday.

#1390639

This actually works on the blocks. I just tested. The results work the same. I think others may be interested in knowing how the search fields actually work as well.

My issue is resolved now. Thanks for your help!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.