Jump to content

module for filtering results from large list?


bongomania
 Share

Recommended Posts

My site has 150+ pages, and I need a tool so readers can sort and drill down to find the page that best meets their needs.  An example of something similar is here: http://www.mouser.com/Passive-Components/PotentiometersTrimmers-Rheostats/_/N-9q0yi/ in the section that allows filtering by several different parameters.  Another example would be profile matching on a dating site, where you describe the person you're looking for, e.g. "non-smoking, blonde, under 6 ft tall, over 20 years old, under 500 lbs, single" and the site shows you only results that match.

Each page will have about 20 filter parameters.  Obviously I will also need a way of appending these searchable parameters to each of my pages.  Currently my site is all simple SHTML and CSS; I've installed PW, but none of the site is built on it yet.

Any suggestions?  Thanks!

Link to comment
Share on other sites

Filtering is very easy because each choice excludes all the others. In the example you gave it could work like this:

$resultados = $pages->find("template=potenciometro, fabricante=$fabricante, produto=$produto, resistencia=$resistencia, classEnerg=$classEnerg, acabamento=$acabamento, tolerancia=$tolerancia, conica=$conica");

This would work because you would be looking for products that have all these characteristics. But the example that I gave doesn't take in account tat some filters might be not used. For that you could do this:

$fabricante = $sanitizer->selectorValue($fabricante);
$fabricante = $fabricante ? "fabricante={$fabricante}" : "";
// do the same for all fields

$resultados = $pages->find("template=potenciometro, $fabricante, $produto, $resistencia, $classEnerg, $acabamento, $tolerancia, $conica");
 

These assume that your fields are text fields, but most probably they would be page fields, in that case your search would be more of this kind:

fabricante.name=$fabricante

read more about how to organize content here http://processwire.com/talk/topic/3579-tutorial-approaches-to-categorising-site-content/

If you need a more intelligent search, one that instead of excluding just prioritizes some fields over others, I can help you with some code for that also.

  • Like 2
Link to comment
Share on other sites

Same thing:

$resistencia = $sanitizer->selectorValue($input->get->resistencia);
$resistencia = $resistencia ? "resistencia>{$resistencia}" : ""; // notice that here the sector has ">"
 
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

×
×
  • Create New...