Jump to content

Search Template Adding All Fields or Some


quickjeff
 Share

Recommended Posts

Hey Guys, So I'm creating a search template that will search all of my created fields for a query.  Unfortunately, when I go to add 1 or 2 more from the stock search template as a test, I still am only searching the title, body and sidebar and not what I added.  

Any guidance on this?  

I have added the pipe line divider to add more fields manually to test the functionality behind the search template but no luck.  

Perhaps I am missing something?  

Here is a sample of what I am attempting, the piece of code I have included does not include everything in its entirety just the piece I am altering as a test. 

$matches = $pages->find("title|body|sidebar|band_title~=$q, limit=50"); 

As you can see I want to also search the field band_title but I have no results coming through.  

Last, is it possible to add search all fields? Versus inputing every field manually?


Thanks for the help! 

Link to comment
Share on other sites

Why do you need a band_title? Couldn't it use just title field?

No, you have to add them manually. But generally you would want to reuse fields as much as possible for various reason anyway. You don't need a new textfield for every different type, keep in mind you can set label and description, visiblity in template context aswell, so a title could be labeled "Band Title" on a "band" template.

There's a Fieldtype Cache that is not installed by default, that allows you to add multiple text fields that will cache them to "one" field allow you to search the cache field.

Link to comment
Share on other sites

Soma, is your name referenced to Brave New World the novel?  Just thought I would ask.

-The band title is for a list of band names that are playing at my clients bar.  The names are spit out into the band page.  We are trying to make the search field pull the data if a customers favorite band is playing and they have searched it.  Since the names are not in the body, title or sidebar, I wanted to add the field to the search.  Unfortunately it doesn't recognize the field in the search template. 

Link to comment
Share on other sites

I think what soma is saying is why didn't you use the 'title' field for the band template and then use template context to define that field as the band_title, this reduces the # of fields you need to use, and also simplifies writing the search stuff with the api

Link to comment
Share on other sites

Yes, just realized what he meant now.  Thanks for the feedback.  Great point! Also watched Ryan's video on template context, didn't know we could do this, now I know! Thanks! 

As far as the search for other templates in the search.php template, any suggestions? Since we have other fields we want to include that are not using template context. 

Link to comment
Share on other sites

it should work, you should be able to put as many fields there as you want to return results;

you can also do stuff like this, if you have different fields on different templates: also notice the % sign

    $matches = $pages->find("title|body%=$q, template=basic-page|faculty|class");
    $kmatches = $pages->find("keywords=$q, template=class");
    $matches->import($kmatches)->sort('template,title');
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...