Hello all,

Suppose I create a view with fields: A, B, C, and D. I know that it is possible to add search fields for each individual field. My question is whether it is possible to create a global search that will search all the fields? If I wanted to search for the phrase 'Drupal', under my current set up, I would have to have a search for each individual field and type 'Drupal' in each field. Can it be done with only one input field? If so, is there a guide on how to do this?

Thanks,

Comments

lokisapocalypse’s picture

Just saw that Search: Index was added in some version of Drupal newer than the one we are using.

lokisapocalypse’s picture

Just to do an update to this question...

The initial view was done to search the user profiles. The user profiles are now being handled by the Bio module. I would like to have just one search field to search across all pieces in the Bio. The only way I've found to do this is to add computed field to the Bio module that stores the value of each of the field concatenated together. This is not an ideal solution because I am essentially storing all the information in the Biography twice.

Initially, the Search:Index option was accurately search across all fields but since switching over to the Bio module, it no longer works correctly.

Any thoughts on how to better implement this?

lokisapocalypse’s picture

I thought this might work:

I created filters for fields A, B, C, and D and exposed them all.
Added css to the header to change the style for those filters to display: none
Added a form to the header consisting of a single input field
When the form is submitted, it reloads the page passing the url as myview?&op0=contains&filter0=text&op1=contains&filter1=text&op2=contains&filter2=text&op3=contains&filter3=text

So what happens is that I would type text into the input field and use javascript to modify the url and add the filter text to each filter. Unfortunately this doesn't work as the filters are the result of a boolean AND instead of a boolean OR. If there was a way to change that, I believe this method would work.

Thoughts?

lokisapocalypse’s picture

I suppose that I could just modify the views.module file or one of the other files but I would really like to avoid that solution as any upgrade will overwrite my changes.

My other solution was to use a computed field (E) to store the concatenation of the fields A, B, C, and D. However, this is a poor solution because it requires twice as much storage space.

Is there something I could do with the header or the arguments that would allow this solution?

lokisapocalypse’s picture

I attempted to implement the solution where I add a computed field containing the concatenation of the other fields. Even though it doubles the size of the storage for each Bio, we will not run out of space. However, the search options on the computed field are mathematical operators (>, >=, <, <= ==, !=) instead of the string operators like I need (specifically "contains").

Anyone know of a solution?

lokisapocalypse’s picture

Would it be possible to do with with arguments?

For example, I tried the following:

  $query = sprintf("select nid from content_type_bio where field_a like '%%%s%%' or field_b like '%%%s%%' or field_c like '%%%s%%' or field_d like '%%%s%%' or field_e like '%%%s%%'", 
    mysql_real_escape_string($_GET['filter0']), 
    mysql_real_escape_string($_GET['filter0']), 
    mysql_real_escape_string($_GET['filter0']), 
    mysql_real_escape_string($_GET['filter0']), 
    mysql_real_escape_string($_GET['filter0'])); 

  $result = db_query($query); 
  $nodeid = array(); 

  while($row = db_fetch_array($result)) { 
    $nodeid[] = $row['nid'] + 0; 
  } // end while($row = db_fetch_assoc($result)) 

  return $nodeid;

This was based on the example found at http://drupal.org/node/70145 . Currently, however, this returns an empty set. Am I doing something incorrectly?