Divinorum Posted July 7, 2023 Share Posted July 7, 2023 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? Link to comment Share on other sites More sharing options...
ngrmm Posted July 7, 2023 Share Posted July 7, 2023 I'm not sure about text fields in combination with operators. Maybe you try a float field. But in general i would recommend to use a search index field: look here 1 Link to comment Share on other sites More sharing options...
ryan Posted July 7, 2023 Share Posted July 7, 2023 @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. 1 Link to comment Share on other sites More sharing options...
Divinorum Posted July 7, 2023 Author Share Posted July 7, 2023 When I do run @price_list.price>=1000, @price_list.price<=5000 in the query it returns 2 items: I can't understand how it's able to select these 2 pages given the query Link to comment Share on other sites More sharing options...
ryan Posted July 7, 2023 Share Posted July 7, 2023 @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 More sharing options...
Divinorum Posted July 7, 2023 Author Share Posted July 7, 2023 $servicePage = $pages->find("template=staff_profile,services=$service,staff_location=$location_id, @price_list.price>=1000, @price_list.price<=5000, limit=$limit"); This is the code currently Link to comment Share on other sites More sharing options...
Robin S Posted July 8, 2023 Share Posted July 8, 2023 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). 2 Link to comment Share on other sites More sharing options...
netcarver Posted July 8, 2023 Share Posted July 8, 2023 How about using an int field for the price - but in cents, not dollars and cents. Would, of course, require formatting when displaying and storing the value. 1 Link to comment Share on other sites More sharing options...
Divinorum Posted July 10, 2023 Author Share Posted July 10, 2023 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 More sharing options...
Divinorum Posted July 10, 2023 Author Share Posted July 10, 2023 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 More sharing options...
Divinorum Posted July 10, 2023 Author Share Posted July 10, 2023 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 More sharing options...
Robin S Posted July 10, 2023 Share Posted July 10, 2023 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) 1 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now