Jump to content

Create search template / form


drilonb
 Share

Recommended Posts

What are the field names and types that you want to be searchable? Generally, you can find all pages that match keywords for a given text or textarea field like this:

<?php

// find pages that match the phrase 'some keywords' on the 'title' or 'body' fields: 
$matches = $pages->find("title|body*=some keywords"); 

// find pages that match the words 'some keywords' anywhere in the 'title' or 'body' fields:
$matches = $pages->find("title|body~=some keywords"); 

// find pages matching 'some keywords' phrase in 'title', and 'some other keywords' words anywhere in 'body'
$matches = $pages->find("title*=some keywords, body~='some other keywords'"); 

Link to comment
Share on other sites

  • 4 months later...

Hi! I'm having a lot of fun with PW! It rocks!

I was wondering if the search term can be of 3 characters, cause I'm working on a product catalog which has a lot of 3 letter products. I've noticed that these products don't show on the search results. Is there a way?

Link to comment
Share on other sites

You can also use the "%=" operator in your selector, rather than "*=", i.e. "body%=que", and that will work. The "%=" operator uses the MySQL LIKE command rather than a fulltext index, so it's not bound by word length or stopwords.

However, on a large site it is a lot slower since it's not using indexes. Though you may have to be dealing with hundreds or thousands of pages before the difference would be major. I compared broad text searches on a site with 3,500 pages and didn't perceive any difference in speed when replacing the "*=" with "%=". However, it really may depend on the server and *= is going to be measurably (if not noticeably) faster the larger the site gets. So if you can tweak your MySQL settings to support words below 4 characters like in Antti's link, then that is preferable since it is technically more efficient.

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...