Jump to content
dandeckr

Boolean Searching (AND, OR, NOT, etc.)

Recommended Posts

Hello!

I'm making my way through my first encounter with ProcessWire, and I'm very near the end of my tasks! I've searched Google, these forums, and for add-ons, but I haven't found any documentation or reference work for implementing boolean searching in the native CMS? Am I missing a thread, add-on, or docs that can point the way? I'm sure I'm not the first to have a need like this? Thanks in advance! 

Share this post


Link to post
Share on other sites

Hello @dandeckr!

I'm sure you also stumbled upon the selector docs. Can you elaborate what you are trying to achieve? Do you need to do some complex queries? If you tell us a bit about your site structure, and what you have already done so far, I'm sure we could jump in with some practical tips.

A simple NOT would mean simply using field!=value.

There are also quite a few methods where the documentation is scattered a bit all over the place, e.g.

https://processwire.com/blog/posts/pw-3.0.25/

https://processwire.com/blog/posts/processwire-3.0.13-selector-upgrades-and-new-form-builder-version/#selector-engine-array-support

 

  • Like 1

Share this post


Link to post
Share on other sites

Hello and thank you!

Indeed, the more I research the more I've determined the difference between what the client says and what the client means. Basically, its advanced filtering. They want "results with THESE words, or THOSE words, but not THAT word". As you noted, going over the selector docs, I think It's possible to gather a result set with pages that "contain 'all these words'" and then filter the result set for "but not 'these words'" before display. 
I'll follow up with my outcomes once I get to test my means! Thank you again!

Share this post


Link to post
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

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Anders
      I want to allow full text search on my site. There is a very nice solution that comes right out of the box:
      $selector = "title|body~=$q, limit=50"; This works, but to make it even better I would want to give higher weight to pages where the search term occurs in the title, than if it just occurs in the body. After all, a page with the title "Wine from France" is probably the best match for the search "france wine". How do I accomplish this in ProcessWire?
      I can see three possible paths, but I am not very fond of any of them:
      Do a direct SQL query, circumventing the API, along these lines. But I would prefer to abstract away the database layout if at all possible. Use something like ElasticSearch, but to be honest that would be to complicated to set up and maintain in the long run. Make multiple lookups, first for matches in the title, then for matches in the body, and merge and sort in PHP. My suspicion is that this would get complicated quite quickly. For instance, how do you deal with a page that has two of the three search terms in the title and the third in the body? Is there a magic option four I should look into? Or are any of the above options better than the others? Any input is welcome!
    • By cboetens
      Hi guys
      So I'm building a little search index for a client with this recipe I've found on the ProcessWire Recipes website (more info: https://processwire-recipes.com/recipes/set-up-search-index-with-fieldtypecache/)
      I've followed the exact steps in the recipe and the script appears to be working, except for Profields: Repeater Matrix. 🙄
      This is the code I've got so far:
      <?php include('includes/header.php') ?> <?php $q = $sanitizer->selectorValue($input->get->q); if($q) { $results = $pages->find('search_cache%='. $q); } else { $results = new stdClass(); $results->count = 0; } ?> <section class="partners-block-consul mb-5"> <div class="container"> <div class="row"> <div class="col-sm-10 offset-sm-1"> <div class="partners-head sec-p-lg"> <?php if($page->headline) { ?> <h1 class="highlight"><?= $page->headline ?></h1> <?php } ?> <div class="cms text-left"> <p>Er werden <?= $results->count ?> resultaten gevonden.</p> <?php if($results->count > 0){ ?> <ul> <?php foreach($results as $result){ if($result->template->name == "faq_item") { $category = $pages->get("id=".$result->faq_category); $parent_template = $category->rootParent(); ?> <li><?= $result->title ?> - <a href="<?= $parent_template->url . $category->name . "/"; ?>" title="<?= $result->title ?>"><?= $labels->read_more ?></a></li> <?php } elseif($result->template->name == "faq_category") { $parent_template = $result->rootParent(); $faqCategoryUrl = $parent_template->url . $result->name . "/"; ?> <li><?= $result->title ?> - <a href="<?= $faqCategoryUrl; ?>" title="<?= $result->title ?>"><?= $labels->read_more ?></a></li> <?php } else { ?> <li><?= $result->title ?> - <a href="<?= $result->url; ?>" title="<?= $result->title ?>"><?= $labels->read_more ?></a></li> <?php } ?> <?php } ?> </ul> <?php } ?> </div> </div> </div> </div> </div> </section> <?php include('includes/cta.php'); ?> <?php include('includes/footer.php'); ?> In the ProcessWire admin the "search_cache" field is being build as follows (see image 1).


      Then, the field 'search_cache' is being used on the following templates (see image 2 and 3). So, let's say I'm searching the word 'kinderen', which should get a hit on the template 'Kind', the script isn't returning this page as one of the hits (the result should return 'migraine').
       

      If someone has any idea why the script is not looking for the data that is being put in the field "Profields: Repeater Matrix", he/ she would be my personal hero! 🤗
      Greetings
      Cédric
       


    • By jds43
      Hello,
      I have a search page loosely based on Skyscrapers where I'm parsing a selector with options 'beds', 'bathrooms', 'size' fields. It is working well until I select 'Any' after I've run a search. This is where no results are returned (/?beds=&bathrooms=&size=&submit=). I want it to reset and show all results.
      I hope this isn't too vague.
       
    • By NehaPillai
      Hello Everyone, I was trying to update SEO meta title, description and meta keywords for my website in Process Wire CMS but it saving in the backend but it is not reflecting on my website, Please help me regarding this error. Please find below attached screen shot for your ref. TIA.


    • By sww
      Hey there,
      i am trying to add a kind of "intelligent" search.
      Is there any way to ignore punctuation and extra chars.
      e.g.
      When I type "somebody elses" that I still get the result "SOMEBODY ELSE´S CAR, 2005"
      The problem is the extra ´ … if I don't type it I don't get the result.
      So far I am using %=query (which isn't enough, I know)
      So the idea would be something like that:
      $selector = "sanitize(title|text)%=$q, limit=50";
      I know, it's not gonna work like that … just to illustrate.
      Best,
      Stefan
×
×
  • Create New...