Jump to content

Recommended Posts

Posted

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'"); 

Posted

Thnaks RYAN i fix it now its working great just need some little styling

i use this code and work great

 $matches = $pages->find("title|body~=$q");  
  • 4 months later...
Posted

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?

Posted

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.

Posted

Thank you very much for your answers. I ended up with '%=', cause it's a small catalog and didn't want to mess with mysql settings!

:D

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.
×
×
  • Create New...