Jump to content

Filtering search results


Divinorum
 Share

Recommended Posts

I'm looking to search a list of services attached to peoples records. 

Each person has the repeater listed below called "price_list" it contains the following: 

Pricelist: 
- speciality (page reference for the actual skill they poses)
- Text field listing the price its self (numeric content only)  

Searching the records will involve a multiple checkbox price range being passed to the search function. 
something like: 

  • £1000 - £5000
  •  £5000 - £10,000
  •  £10,000 - £15,000
  •  £15,000 - £20,000

So depending what's passed will determine how the values are searched. I just can't seem to grasp how to search sets of values multiple times?!?

I thought perhaps a find search for something like "price_list.price>=15000||price_list.price<=20000" would work but it seems to ignore it. 

Any thoughts? 

145877348_Screenshot2023-07-07at11_32_52.png.bdaf137c7db27f176b60ba585a5d01d0.png

Link to comment
Share on other sites

@Divinorum Since you are trying to match a range of prices, it looks to me like you'd want an AND condition for that price_list.price rather than an OR condition? The AND condition in your selector would be:

price_list.price>=15000, price_list.price<=20000

Assuming that price_list is a Page field that lets you select multiple pages, a selector like the above says this: at least one page in your price_list field must match price>=15000 and at least one page in your price_list field must match price<=20000. It doesn't say that they have to be the same page in that set matching both of those conditions. If you want to tell it that the same exact page in that set must match both of those conditions (which seems more useful here), then prefix an "@" to both of the conditions (see subfield selectors for more details): 

@price_list.price>=15000, @price_list.price<=20000

For a single-page selection field, this use of "@" would not apply, as there's only ever 0 or 1 pages in the set of selected pages. 

Note that there is no such thing as double pipes "||" for an OR condition in selectors (from your example), but there is such thing as using 1 pipe "|" to match one field or another, or one value or another. See the Selectors doc page for more details. Also check out selector OR-groups, which I don't think are useful here, but seems like you might have been thinking of something like it when using those double pipes. 

  • Like 1
Link to comment
Share on other sites

@Divinorum I don't have the full picture of what you are querying, but my assumption is that you are finding pages that have a "price_list" (Page) field with selectable pages that each contain a "price"(integer) field. The returned pages are going to be those that have a "price_list" field, not pages that have a "price" field. I don't know what's producing the output in your screenshot, so you may have to post the code. 

Link to comment
Share on other sites

16 hours ago, Divinorum said:

Text field listing the price its self (numeric content only)

This is likely to be the problem. As @ngrmm mentioned, selector operators like > and < depend on the fieldtype used, so for a price you would want to use an integer field if you only need whole dollars, or a decimal field for dollars and cents (the decimal field is the better choice for futureproofing).

  • Like 2
Link to comment
Share on other sites

Thanks for all the suggestions so far: 

Im now using decimal fields for the price and adjusted the prices accordingly. I'm now using: 
both: 

template=staff_profile,staff_location=1119,@price_list.procedure_price>=1000.00,@price_list.procedure_price<=5000.00

and 

template=staff_profile,staff_location=1119,@price_list.procedure_price>=1000,@price_list.procedure_price<=5000

Result in a profile with a price of 1500 being selected?? 
I really don't get why this is being so problematic. I really do want to use Processwire for this project but this filtering issue is giving me second thoughts  

Link to comment
Share on other sites

It's almost like it's taking the > part of the first condition, ignoring the second argument all together!? Yet there is a service profile of 20000 and that's being (correctly) ignored. I really don;'t get what's going on 

Link to comment
Share on other sites

1418044570_Screenshot2023-07-10at11_36_14.thumb.jpg.fe667d3450e1768c5cf719f875110f9a.jpg

Above are my test prices. I am running the following search: 

template=staff_profile,staff_location=1119,price_list.procedure_price>=1000,price_list.procedure_price<=5000|price_list.procedure_price>=10000,price_list.procedure_price<=15000

The above search should return the first two results but not the third. Currently it finds the second but nothing else!?

Link to comment
Share on other sites

12 hours ago, Divinorum said:

I'm now using: 
both: 

template=staff_profile,staff_location=1119,@price_list.procedure_price>=1000.00,@price_list.procedure_price<=5000.00

and 

template=staff_profile,staff_location=1119,@price_list.procedure_price>=1000,@price_list.procedure_price<=5000

Result in a profile with a price of 1500 being selected?? 

That sounds like the correct result. 1500 is greater than or equal to 1000 and less than or equal to 5000.

11 hours ago, Divinorum said:

I am running the following search: 

template=staff_profile,staff_location=1119,price_list.procedure_price>=1000,price_list.procedure_price<=5000|price_list.procedure_price>=10000,price_list.procedure_price<=15000

 

That use of the pipe isn't valid selector string syntax. 

The pipe is used as an OR operator within the value...

firstname=Mike|Steve

...or within the field...

body|sidebar*=carbonated

But in the example you give you would need to use OR groups. And as Ryan mentioned earlier you will want to use the @ operator too because you want conditions like "price_list.procedure_price>=1000, price_list.procedure_price<=5000" to be matched within a single repeater item, not a staff_profile page that has one price_list item where procedure_price>=1000 and a different item where procedure_price<=5000.

template=staff_profile, staff_location=1119, (@price_list.procedure_price>=1000, @price_list.procedure_price<=5000), (@price_list.procedure_price>=10000, @price_list.procedure_price<=15000)

 

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...