Search just one category or section

Discuss the development and implementation of Joomla! bots/Plugins here.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
pitir
Joomla! Apprentice
Joomla! Apprentice
Posts: 11
Joined: Thu Dec 13, 2007 9:20 pm

Search just one category or section

Postby pitir » Thu May 22, 2008 8:13 pm

Hi there,

I have searched and searched the forums here, and there appears to be no solution for the problem I'm having.

I need to provide visitors to our site with the option to either search within one section/category AND/OR search the whole site. I have one section of our site that needs it's own separate search feature, but I' don't want to abandon the ability to search the entire site from other sections' pages.

Content Search Extendedhttp://extensions.joomla.org/component/option,com_mtree/task,viewlink/link_id,2700/Itemid,35/ is the only plugin I can find that does anything like this, but it is an either/or proposition - once you restrict the search to a specific section, you have no way to search the entire site (or vice-versa).

Is there a solution to this conundrum?

Thanks!

rodsdesign
Joomla! Intern
Joomla! Intern
Posts: 52
Joined: Tue Apr 17, 2007 2:11 pm

Re: Search just one category or section

Postby rodsdesign » Mon Jun 02, 2008 5:50 am

I have a similar need for this...

has anyone figured out a way to do it?

pitir
Joomla! Apprentice
Joomla! Apprentice
Posts: 11
Joined: Thu Dec 13, 2007 9:20 pm

Re: Search just one category or section

Postby pitir » Thu Jun 05, 2008 11:01 pm

I stall haven't found a solution for this - seems like there should be a canned solution for this, no?

*bump*

pitir
Joomla! Apprentice
Joomla! Apprentice
Posts: 11
Joined: Thu Dec 13, 2007 9:20 pm

Re: Search just one category or section

Postby pitir » Wed Jun 25, 2008 4:49 pm

Nobody has any ideas about this?

Really?


It doesn't seem like it'd be that unusual for someone to want this...am I the only one?

User avatar
Nog
Joomla! Apprentice
Joomla! Apprentice
Posts: 26
Joined: Fri Sep 28, 2007 10:47 am

Re: Search just one category or section

Postby Nog » Thu Nov 13, 2008 11:52 am

I also need to do this. Did you ever find a solution to this? I'm amazed nobody has replied - looks like the quietest thread in Joomla!
Gary Brindley
QLUE
http://www.qlue.co.uk
If you can keep your head when people all around you are losing theirs then maybe you've misunderstood the situation.

pitir
Joomla! Apprentice
Joomla! Apprentice
Posts: 11
Joined: Thu Dec 13, 2007 9:20 pm

Re: Search just one category or section

Postby pitir » Thu Nov 13, 2008 6:02 pm

I didn't find a solution to this. In fact, since I moved to PHP5 on our server the search feature doesn't work at all.

Go Joomla!

jcerious
Joomla! Intern
Joomla! Intern
Posts: 60
Joined: Thu Dec 13, 2007 3:59 pm

Re: Search just one category or section

Postby jcerious » Tue Dec 23, 2008 6:21 am

I'd like help with doing this too.

maciej
Joomla! Apprentice
Joomla! Apprentice
Posts: 11
Joined: Wed May 28, 2008 1:49 am

Re: Search just one category or section

Postby maciej » Tue Jan 13, 2009 6:40 am

I have a similar need? Anyone have any ideas how to go about it. Maybe we need to write it ourselves? Start with current seach component?

Thanks,

Maciej

jcerious
Joomla! Intern
Joomla! Intern
Posts: 60
Joined: Thu Dec 13, 2007 3:59 pm

Re: Search just one category or section

Postby jcerious » Tue Jan 13, 2009 7:20 am

Search feature works okay for me on php5. I just wish you could type in more than 20 characters.

yekibud
Joomla! Apprentice
Joomla! Apprentice
Posts: 27
Joined: Tue Jan 13, 2009 4:32 pm
Location: Sacramento, California

Re: Search just one category or section

Postby yekibud » Mon Mar 02, 2009 6:16 pm

Just started using Joomla and ran into this problem. I'm surprised it's not a feature of the built in search component.

Here's my solution - would like to hear ideas for something more elegant:

1. add a section id parameter to the search module (mod_search.xml)

Code: Select all

<param name="section_search_id" type="text" default="" label="Section Search Id" description="Search articles by a particular section" />


2. pass section id to search component via post (mod_search/tmpl/default.php)

Code: Select all

<input type="hidden" name="section_id" value="<?=$params->get('section_search_id')?>" />


3. add section id to model parameters from component controller (com_search/controller.php)

Code: Select all

$post['section_id'] = JRequest::getString('section_id', null, 'post');


4. add section_id parameter to setSearch method in model and add to constructor call (com_search/models/search.php)

Code: Select all

$section_id = urldecode(JRequest::getString('section_id'));
$this->setSearch($keyword, $match, $ordering,$section_id);


5. add section_id to search plugin and call via dispatcher in model search->getData method (plugins/search/content.php, com_search/models/search.php)

Code: Select all

function plgSearchContent( $text, $phrase='', $ordering='', $areas=null, $section_id=null ) {
...


and

Code: Select all

$results = $dispatcher->trigger( 'onSearch', array(
     $this->getState('keyword'),
     $this->getState('match'),
     $this->getState('ordering'),
     $areas['active'],
     $this->getState('section_id'))
);


6. add section_id conditionally to article search query and return results (plugins/search/content.php)

Code: Select all

. ($section_id ? " AND a.sectionid=$section_id " : '')


and, right after the article query,

Code: Select all

   if ($section_id) {
      $results = array();
      if(count($rows)) {
         foreach($rows as $row) {
            $new_row = array();
               foreach($row AS $key => $article) {
                  if(searchHelper::checkNoHTML($article, $searchText, array('text', 'title', 'metadesc', 'metakey'))) {
                     $new_row[] = $article;
                  }
               }
            }
         $results = array_merge($results, (array) $new_row);
      }
      return $results;
   }



hth

User avatar
elfif
Joomla! Apprentice
Joomla! Apprentice
Posts: 47
Joined: Fri Dec 23, 2005 1:33 pm
Location: Bordeaux - France
Contact:

Re: Search just one category or section

Postby elfif » Thu Jun 04, 2009 2:03 pm

Hello, did you succeed to make it work?
I've adapted it for categories (with $cat_id/cat_id/catit ) but I don't have results for section only. The results are the same as the standard search process.

Any help someone?
Keep smiling with the sun and singing with the birds
www.atelier51.com

yekibud
Joomla! Apprentice
Joomla! Apprentice
Posts: 27
Joined: Tue Jan 13, 2009 4:32 pm
Location: Sacramento, California

Re: Search just one category or section

Postby yekibud » Thu Jun 04, 2009 3:41 pm

Hi, Elfif.

You said you "adapted it for categories". Are you trying to search by sections or categories? Have you tried the 6 steps exactly how I described?

It works for me. The site I'm using it on goes live in 2 weeks. PM me then and I'll give you the URL if you want to see the implementation.

User avatar
elfif
Joomla! Apprentice
Joomla! Apprentice
Posts: 47
Joined: Fri Dec 23, 2005 1:33 pm
Location: Bordeaux - France
Contact:

Re: Search just one category or section

Postby elfif » Thu Jun 04, 2009 8:09 pm

I'm trying to search by categories, and tried your 6 steps like described, but I replaced section_id by cat_id evrywhere needed...
Do you think I'm going wrong ?
Keep smiling with the sun and singing with the birds
www.atelier51.com

yekibud
Joomla! Apprentice
Joomla! Apprentice
Posts: 27
Joined: Tue Jan 13, 2009 4:32 pm
Location: Sacramento, California

Re: Search just one category or section

Postby yekibud » Thu Jun 04, 2009 9:48 pm

Sorry, Elfif. I have only implemented my work-around for a section search. You might think simply doing a s/section/cat/ everywhere would work for categories - but Joomla is a funny beast. You may have to spend some more time trying to figure out what's going on.

If I come across the need to search by categories, I'll update the post.

User avatar
elfif
Joomla! Apprentice
Joomla! Apprentice
Posts: 47
Joined: Fri Dec 23, 2005 1:33 pm
Location: Bordeaux - France
Contact:

Re: Search just one category or section

Postby elfif » Thu Jun 04, 2009 10:12 pm

Thanks Yekibud.
I'm going to try your workaround by moving my articles in a brand new section !
I'll tell you if it works this way ;)

Thanks again for your answers
Keep smiling with the sun and singing with the birds
www.atelier51.com

User avatar
elfif
Joomla! Apprentice
Joomla! Apprentice
Posts: 47
Joined: Fri Dec 23, 2005 1:33 pm
Location: Bordeaux - France
Contact:

Re: Search just one category or section

Postby elfif » Mon Jun 08, 2009 7:50 am

Hello Yekibud,

I've tried your workaround for section search only. And I always have results for entire site... Can't understand where my problem is... :geek:
For beginning, could you please tell me where exactly you pasted your lines at step 6 ?

Thanks for your help !
Keep smiling with the sun and singing with the birds
www.atelier51.com

yekibud
Joomla! Apprentice
Joomla! Apprentice
Posts: 27
Joined: Tue Jan 13, 2009 4:32 pm
Location: Sacramento, California

Re: Search just one category or section

Postby yekibud » Mon Jun 08, 2009 2:52 pm

Hi, Elfif.

$section_id is an optional parameter that I added to the setSearch() and plgSearchContent() methods (cf. step 4 & 5) which adds the article sectionid field to the WHERE clause (if it exists) in step 6.

Are you setting the "Section Search Id" parameter in your search module?

User avatar
elfif
Joomla! Apprentice
Joomla! Apprentice
Posts: 47
Joined: Fri Dec 23, 2005 1:33 pm
Location: Bordeaux - France
Contact:

Re: Search just one category or section

Postby elfif » Mon Jun 08, 2009 4:11 pm

Yes yes of course, I've understood your way of thinking. Ive found your trick really useful and smart, because you can copy the seacrh module and customize easily your searches.
Nice work, but I'm not so fluent as you with php and I can't understand where the thing goes wrong...
Keep smiling with the sun and singing with the birds
www.atelier51.com

yekibud
Joomla! Apprentice
Joomla! Apprentice
Posts: 27
Joined: Tue Jan 13, 2009 4:32 pm
Location: Sacramento, California

Re: Search just one category or section

Postby yekibud » Mon Jun 08, 2009 4:31 pm

What version of Joomla are you using?

If you set $debug = 1 in configuration.php, do you get any messages?

Send me the following files, and I'll take a quick look to see if everything looks right:

mod_search.xml
mod_search/tmpl/default.php
com_search/controller.php
com_search/models/search.php
plugins/search/content.php

Otherwise, without access to your environment, I'm not sure how I can help troubleshoot. I may try to make the work-around plugable, which may help - but probably not for several weeks.

User avatar
elfif
Joomla! Apprentice
Joomla! Apprentice
Posts: 47
Joined: Fri Dec 23, 2005 1:33 pm
Location: Bordeaux - France
Contact:

Re: Search just one category or section

Postby elfif » Tue Jun 09, 2009 3:42 am

I'm using Joomla 1.5.9
Debug information are not really readable for me. I can't find the problem :(
I've copied debug results in a text file, and added it to other files you asked for.
I'm sending all of them via PM.
Thanks again...
Keep smiling with the sun and singing with the birds
www.atelier51.com

User avatar
freerider
Joomla! Apprentice
Joomla! Apprentice
Posts: 26
Joined: Wed Apr 12, 2006 10:42 am
Contact:

Re: Search just one category or section

Postby freerider » Fri Oct 09, 2009 8:11 am

Hi, yekibud
I'have tryed to implement your soulution for 4 or 5 times from scratch,
but I allways end up with "blank screen result" when testing search module.
I guess I'm doing something wrong. :-[
I would be very thankfull if you could publish or send me copies of the required files.

I'm using joomla 1.5.10

yekibud
Joomla! Apprentice
Joomla! Apprentice
Posts: 27
Joined: Tue Jan 13, 2009 4:32 pm
Location: Sacramento, California

Re: Search just one category or section

Postby yekibud » Tue Oct 13, 2009 3:06 pm

Hi, freerider.

Sorry - nobody seems to have had any luck implementing my work-around. I've attached the files - but I think I'm going to have to test on a fresh install or try to make it plugable in order for this to be useful. I'll see if I can put a little time into this today.

Btw, the blank page is probably a PHP error. Set debug=1 in your config and you should get a more meaningful message.
You do not have the required permissions to view the files attached to this post.

yekibud
Joomla! Apprentice
Joomla! Apprentice
Posts: 27
Joined: Tue Jan 13, 2009 4:32 pm
Location: Sacramento, California

Re: Search just one category or section

Postby yekibud » Tue Oct 13, 2009 6:18 pm

Damn - sorry guys - I forgot one step in my explanation. You need to add a section_id parameter to the setSearch function in the search model (com_search/models/search.php):

Code: Select all

   function setSearch($keyword, $match = 'all', $ordering = 'newest', $section_id=null)
   {
      if(isset($keyword)) {
         $this->setState('keyword', $keyword);
      }

      if(isset($match)) {
         $this->setState('match', $match);
      }

      if(isset($ordering)) {
         $this->setState('ordering', $ordering);
      }

      if(isset($section_id)) {
         $this->setState('section_id', $section_id);
      }
}
   


I just tested this with a fresh install of 1.5.14 and it works. (Don't forget to set the section id in the the search module.)

I would recommend making the modifications yourself, since I don't know if anything else has changed in the search functionality in 1.5.14, but if you want to overwrite the files, use the attached zip (instead of the one from my previous post). I added the small changes I just mentioned.

hth
You do not have the required permissions to view the files attached to this post.

User avatar
freerider
Joomla! Apprentice
Joomla! Apprentice
Posts: 26
Joined: Wed Apr 12, 2006 10:42 am
Contact:

Re: Search just one category or section

Postby freerider » Wed Oct 14, 2009 4:20 pm

Thank you!!! a milion!!!
It work's

I had to do one minor change... in /mod_search/temp/default.php
I changed

Code: Select all

<input type="hidden" name="section_id" value="<?=$params->get('section_search_id')?>" />

to

Code: Select all

<input type="hidden" name="section_id" value="<?php echo $params->get('section_search_id')?>" />


and becouse I require to limit search to more than one section
I changed ... in /plugins/search/content.php

Code: Select all

. ($section_id ? " AND a.sectionid=$section_id " : '')

to

Code: Select all

. ($section_id ? " AND a.sectionid IN ($section_id) " : '')


I allso tried to implement to limit search by category. And it all went without problem.
Now I have option of limiting search by categories or sections... Yeeaj!!! 8)
If you need solution, see my attached file (it is tested on Joomla 1.5.10!!!!!)

Yekibud thanks again!!!
You do not have the required permissions to view the files attached to this post.
Last edited by freerider on Thu Oct 15, 2009 8:35 am, edited 4 times in total.

yekibud
Joomla! Apprentice
Joomla! Apprentice
Posts: 27
Joined: Tue Jan 13, 2009 4:32 pm
Location: Sacramento, California

Re: Search just one category or section

Postby yekibud » Wed Oct 14, 2009 4:28 pm

Oh, good. I'm so glad I didn't post something that just made people chase their tails. ;-)

lehtori
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Fri Apr 03, 2009 9:32 am

Re: Search just one category or section

Postby lehtori » Wed Oct 28, 2009 3:08 pm

it works

but when you do a second search with the searchbox on the resultpage (not the module), he searches the complete site again. the parameter section_id is shown in the url, but the value remains empty.

its propably in 'components/com_search/views/search/view.html.php'

any thoughts?

yekibud
Joomla! Apprentice
Joomla! Apprentice
Posts: 27
Joined: Tue Jan 13, 2009 4:32 pm
Location: Sacramento, California

Re: Search just one category or section

Postby yekibud » Wed Oct 28, 2009 3:22 pm

Two thoughts:

1. Add some CSS to hide the search component. That way the user always has to use the module.

Code: Select all

#searchForm {
    display: none;
}


2. Pass the section id to the component.

brmn
Joomla! Apprentice
Joomla! Apprentice
Posts: 6
Joined: Sat Oct 03, 2009 3:17 pm

Re: Search just one category or section

Postby brmn » Thu Nov 05, 2009 8:08 am

i'm having trouble with step 6.. not sure where the code is supposed to go.

edit: nevermind.. downloaded the attachment and got it working! thanks!

mshoaib
Joomla! Apprentice
Joomla! Apprentice
Posts: 38
Joined: Tue Nov 10, 2009 4:09 pm

Re: Search just one category or section

Postby mshoaib » Fri Jun 11, 2010 9:02 pm

Thanks Alot to all for the help here.
Can any one tell me, whether this functionality is available in a module yet? I need to Make the default Search an Advance search where it can select any of the sections/Categories [In the site] and do the search only those sections or categories.

I have searched and i have found one but that is Commercial.
This is what i want: http://jxtended.com/search.html?q=finder

any Ideas?

yekibud
Joomla! Apprentice
Joomla! Apprentice
Posts: 27
Joined: Tue Jan 13, 2009 4:32 pm
Location: Sacramento, California

Re: Search just one category or section

Postby yekibud » Fri Jun 11, 2010 9:27 pm

I've had this on my list to make plugable for months. Once I do I'll post to this thread. But I can't say for sure when I'll be able to get around to it. My hope is "soon."


Return to “Plugins/Mambots”

Who is online

Users browsing this forum: No registered users and 0 guests