How do you make Advanced Search on Drupal 6

Events happening in the community are now at Drupal community events on www.drupal.org.
budikristanto8's picture

I am a newbie to Drupal and having trouble in searching for the best module for Advanced Search feature (focusing on data search based on a range of price, i.e. 1000-100000 USD). An example of this feature can be found at http://www.housebroker.com.au/search. I've been browsing around the internet and found some interesting modules related to custom search or filtered search such as CCK Facet and rListing.

I would love to know and appreciate your recommendations and experiences about the custom search modules, especially those for Drupal 6. Thanks a lot for help.

Regards,

Budi

Comments

Just use views. You do not

bennos's picture

Just use views.

You do not need the search module, when you only want a search in your categories.

search module is only for full text searching.

Search on HouseBroker

JmsCrk's picture

Hi Budi

That sort of search can't be done using the standard Drupal search module (even from the advanced search page).

I made the HouseBroker search by writing a custom module for it, it wasn't really very hard as searchingby price range is a fairly simple query. Housebroker runs on drupal 5 so the code won't be exactly the same, but if you have a look at the comments in the original post about housebroker you can see some snippets of code I used to write it.

Or you could try Views as Bennos said, I haven't used it for this kind of thing but it's a powerful module and will work with drupal 6. There may also be other CCK search tools that I'm unaware of.

I'm learning Views and CCK Modules

budikristanto8's picture

Thanks for help James and Bennos! I'm now learning Views and CCK Modules. Hopefully those modules will help or I need to make a custom module for my need.

How to create advanced search block

desperatenewbie's picture

Hi, i'm doing a property website, i need to create a search block that let user choose the property location, price, can anyone please tell me how to do it?
should i create a new module or use views or cck? thanks in advance.

I did this with drupal 6

keyo's picture

-Setup a content type with a money field, and all your other fields.
-Make a view, make filters for price, location etc and make them exposed.
-There is an option to expose filters in a block somewhere on the left, use this
-Enable your block

However the price range comes out as a text field. I wanted it to be a drop down of pre defined prices.
I used a hook_form_alter in a custom module for this. If you want the (perhaps not so nice) code I can post it, I'm just too busy now. I have an exam today.

If you are using drupal 5, then you will need civic actions exposed filter block module.

Hope that helps.

Advanced Search

sol1313's picture

Hi Keyo,

I tried the approach above and can't seem to get it to work. The results won't display after applying the filter. In the views section, the results display, but not when I add the box to my home page. Also, I currently have the amenities as a list of items, but would prefer them as check boxes. How could I modify this output?

What I have so far can be viewed here: http://bestspotintown.com

I need to finish this project in the next couple of days. Would you be available to work on this project? What are your rates?

Thanks,
Sol

Regarding Custom Search Module

Nirlepa's picture

Hi , I am a new bie to Drupal, looking for help. I need to develop a website for library which can search for the various books , articles and journals. I heard of drupal, I am trying to modify the default search tool provided by drupal , but its not working fine. I am really confused what do I do.
Is there any existing search tool which ca help to serach for database just by modifying the database table name or do I need to create any custom search module for the same. How to create a custom search module if you can guide me or provide me any resource or tutorial for that available online.
Also I am looking to integrate Apache Solr server with my website but not knowing to work with it already configured and working but what to do next ??

I would really appreciate if you can guide me to develop custom search module.

nirlepa

This is off topic, but

Garrett Albright's picture

This is off topic, but generally, if you want to learn how to code with Drupal, you need to get the Drupal book.

Thx keyo, i will work on it.

desperatenewbie's picture

Thx keyo, i will work on it.

Hi wongkn, I've put my

keyo's picture

Hi wongkn, I've put my hook_form_alter code below, you should be able to adapt this to your liking. It would probably be a good idea to create an admin page for setting the price ranges in the drop downs.

Have a look at my development site to see how it looks. http://mainland-dev.codeworksdesign.co.nz/

/**
* Alter the form to display dropdowns for price range
*/
function mainland_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case 'views_exposed_form' :
      $form['submit']['#value'] = t('Search');
      $from_options = array(
        '' => t('Any'),
     '100000' => t('$100,000'),
      '200000' => t('$200,000'),
      '300000' => t('$300,000'),
      '400000' => t('$400,000'),
      '500000' => t('$500,000'),
      '600000' => t('$600,000'),
      '750000' => t('$750,000'),
      '1000000' => t('$1,000,000'),
      );
    $to_options = array(
        '' => t('Any'),
      '100000' => t('$100,000'),
      '200000' => t('$200,000'),
      '300000' => t('$300,000'),
      '400000' => t('$400,000'),
      '500000' => t('$500,000'),
      '600000' => t('$600,000'),
      '750000' => t('$750,000'),
      '1000000' => t('$1,000,000'),
       '1000000000' => t('$1,000,000 plus'),
      );
      $field_price_amount_from = array (
        '#type' => 'select',
        '#multiple' => false,
        '#required' => false,
        '#options' => $from_options,
        '#default_value' => 'Any',
      );     
      $field_price_amount_to = array (
        '#type' => 'select',
        '#multiple' => false,
        '#required' => false,
        '#options' => $to_options,
        '#default_value' => '$1,000,000 plus',
      );   
      $form['field_price_amount']['min'] = $field_price_amount_from;
      $form['field_price_amount']['max'] = $field_price_amount_to;
      $form['field_price_amount']['min']['#title'] = t('from');
      $form['field_price_amount']['max']['#title'] = t('to');
      break;
  }

}

Where to put the code

desperatenewbie's picture

Thx for your code, but i am wondering where to put the code. Is it a module??

The code goes in a module,

keyo's picture

The code goes in a module, you'll need to customize it a little, like the prices, name of the module and so on. I suggest you look up how to make a module in pro drupal development or the handbook pages.

hi keyo, i have enabled the

desperatenewbie's picture

hi keyo, i have enabled the hook_alter_form module. now i just want to change the textfield to drop down menu for the price range.
For "$form['field_price_amount']['min']", how do i specify it in exposed filters??
because there is only field_selling_price in my database and there is no field for min and max.

Any advice?? Thx

If you are using money field

keyo's picture

If you are using money field there is a between option in the exposed filter settings.

I should also mention that

keyo's picture

I should also mention that to get the default options in the drop downs to work you'll need to specify these in your view. The default options should also be keys in your select fields options array.

For example if you wanted $300,000 as the default field in your from field, you can use 300000 as the default value in the view, since this maps to $300,000 in the code.

$options = array (
  '300000' => '$300,000',
  '400000, => '$400,000',
  [and so on]
);

code question for Keyo

charlesmo's picture

Hi Keyo

please excuse the lame question I've hacked my way through things so far and got your code to work which was awesome by the way as have been struggling to do this for ages.

Anyways my question is how to apply this to two field types ie price and number of bedrooms.

I've tried replicating the code within itself and renaming the to and from options to $from_options1 and $from_options2 for example with references to them being made in other parts of the code I don't have it here but can post all of it tomorrow when I'm in the office.

I'm a complete newbie when it comes to coding am I doing something wrong should I be using an if statement relating to the field I want to change instead am going crazy trying to find solutions.

as the code I'll post tomorrow doesn't seem to work it throws up all the right selection boxes but the original text based search for bedrooms doesn't disappear/ get replaced as in the price section it just gets added along with the original from to text field search created in views.

dssdd

ultimateniks007's picture

dsdsds

Real Estate

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: