searching in custom fields

Post about your customizations to share with others.

Moderators: Developer, Contributor

Frederic
Posts: 7
Joined: 24 Jan 2007, 09:03

searching in custom fields

Post by Frederic »

Hi there,

is there a way to use the search function on view_al_bug_page on all custom_fields?

Thx for your help


edit: I dont want to use Filter_on_custom_fields, i just have too many of them.
Frederic
Posts: 7
Joined: 24 Jan 2007, 09:03

Post by Frederic »

I´m sure it cane be done by modifiying filter_api.php.

It should work when adding
"$t_textsearch_where_clause = ...
OR ($t_custom_field_string_table.value LIKE '%$c_search%'))";

$t_textsearch_wherejoin_clause = ....
OR ($t_custom_field_string_table.value LIKE '%$c_search%'))";

and in the loop :
$t_id_join = $t_id_join . " INNER JOIN $t_custom_field_string_table ON $t_custom_field_string_table.bug_id = $t_bug_table.bug_text_id";

unfortunately, my sql-knowledge is not the best.
I also tried it with the LEFT JOIN statement from the 'sort by cuztom field',
but i think there must be made a little change to get it work.
Frederic
Posts: 7
Joined: 24 Jan 2007, 09:03

Post by Frederic »

:D
If somebody is interested in the solution for my question:

To find a searchstring in the custom fields, just modifiy the sql statement in filter_api.php:

Code: Select all

$custom_query = " $t_bug_table.id IN ( SELECT DISTINCT bug_id from mantis_custom_field_string_table where value LIKE '%$c_search%')";

$t_textsearch_where_clause = "((summary LIKE '%$c_search%')
	 OR ($t_bug_text_table.description LIKE '%$c_search%')
	 OR ($t_bug_table.id = '$c_search_int') 
	 OR ($custom_query))";

$t_textsearch_wherejoin_clause = "((summary LIKE '%$c_search%')
	 OR ($t_bug_text_table.description LIKE '%$c_search%')	 OR ($t_bug_table.id LIKE '%$c_search%')
	 OR ($t_bugnote_text_table.note LIKE '%$c_search%')
	 OR ($custom_query))";

Attention:
I think there was somewhere a warning about searching in all custom fields (didnt found it now ). If there are a lot of bugs to search in, the new sql-statement will cost the sql-server much more time.
benteil
Posts: 3
Joined: 09 Jan 2008, 10:45

Re: searching in custom fields

Post by benteil »

Hello Frederic,

Thanks for that.
I've tried to implement on my code, but i obtain an "ERROR #401".
I guess that i haven't paste your code at the good place, or maybe, not adapt it correctly.
May i ask u more indications about the place to paste it on filter_api.php.


Thanks again. :D

:arrow: Ben
Marnixp
Posts: 1
Joined: 15 Jan 2010, 15:13

Re: searching in custom fields

Post by Marnixp »

This is the way it should be implemented in version 1.1.8.

Search for similar code and replace with below:

# Simple Text Search - Thanks to Alan Knowles
if ( !is_blank( $t_filter['search'] ) ) {
$c_search = db_prepare_string( $t_filter['search'] );
$c_search_int = db_prepare_int( $t_filter['search'] );
$custom_query = " $t_bug_table.id IN ( SELECT DISTINCT bug_id from mantis_custom_field_string_table where value LIKE '%$c_search%')";
$t_textsearch_where_clause = '(' . db_helper_like( 'summary', "%$c_search%" ) .
' OR ' . db_helper_like( "$t_bug_text_table.description", "%$c_search%" ) .
' OR ' . db_helper_like( "$t_bug_text_table.steps_to_reproduce", "%$c_search%" ) .
' OR ' . db_helper_like( "$t_bug_text_table.additional_information", "%$c_search%" ) .
" OR ( $t_bug_table.id = '$c_search_int' ) OR ( $custom_query ) )";

$t_textsearch_wherejoin_clause = '(' . db_helper_like( 'summary', "%$c_search%" ) .
' OR ' . db_helper_like( "$t_bug_text_table.description", "%$c_search%" ) .
' OR ' . db_helper_like( "$t_bug_text_table.steps_to_reproduce", "%$c_search%" ) .
' OR ' . db_helper_like( "$t_bug_text_table.additional_information", "%$c_search%" ) .
' OR ' . db_helper_like( "$t_bug_table.id", "%$c_search%" ) .
' OR ' . db_helper_like( "$t_bugnote_text_table.note", "%$c_search%" ) .
" OR ( $custom_query ) )";
cas
Posts: 1768
Joined: 11 Mar 2006, 16:08
Contact:

Re: searching in custom fields

Post by cas »

Any clue how to do this in version 1.2.10 (0r 11/12)?
Really would like to have similar function available :mrgreen:
knall

Re: searching in custom fields

Post by knall »

I would like to do the same thing in 1.2.12. Any ideas?
knall

Re: searching in custom fields

Post by knall »

The very last note in this issue worked like a charm. http://www.mantisbt.org/bugs/view.php?id=7183

I'm using 1.2.12.
Thanks
atrol
Site Admin
Posts: 8573
Joined: 26 Mar 2008, 21:37
Location: Germany

Re: searching in custom fields

Post by atrol »

knall wrote:The very last note in this issue worked like a charm.
Great to hear, but be aware that you might get performance issues.
Please use Search before posting and read the Manual
bloodlessz
Posts: 5
Joined: 28 Sep 2012, 07:41

Re: searching in custom fields

Post by bloodlessz »

Hi to all,

Can someone tell me how to deploy this so i can search in custom fields?
I have download the api, and add it to \api\soap\ and nothing happens. Am i doing something wrong?

Thank you
cas
Posts: 1768
Joined: 11 Mar 2006, 16:08
Contact:

Re: searching in custom fields

Post by cas »

just to know that the moudsen patch for Mantis 1.2.4 (see attached file) can be applied to version 1.2.11 doing the following:

In the file core/filter_api.php search for:

$t_textsearch_where_clause .= '( ' . db_helper_like( 'summary' ) .
' OR ' . db_helper_like( "$t_bug_text_table.description" ) .
' OR ' . db_helper_like( "$t_bug_text_table.steps_to_reproduce" ) .
' OR ' . db_helper_like( "$t_bug_text_table.additional_information" ) .
' OR ' . db_helper_like( "$t_bugnote_text_table.note" );

and change it with:

$t_textsearch_where_clause .= '( ' . db_helper_like( 'summary' ) .
' OR ' . db_helper_like( "$t_bug_text_table.description" ) .
' OR ' . db_helper_like( "$t_bug_text_table.steps_to_reproduce" ) .
' OR ' . db_helper_like( "$t_bug_text_table.additional_information" ) .
' OR ' . db_helper_like( "$t_bugnote_text_table.note" )
.' OR ' . "($t_bug_table.id IN ( SELECT DISTINCT bug_id from " . db_get_table( 'mantis_custom_field_string_table' ) . " where value LIKE '%$c_search%'))";
bloodlessz
Posts: 5
Joined: 28 Sep 2012, 07:41

Re: searching in custom fields

Post by bloodlessz »

Hi cas,

I have download the two zip files ( replace files.zip and advanced_search_function_v1.0.zip) , search for "db_helper_like" with no success.

Can you show me the steps?

What folder is the right one?
"Replace Files" or "advanced_search_function"?

When i Download the folder, i copy the file\folder under \api\soap folder?

I know, i make a lot of questions :oops: but i don't know how to add patches to mantis bt.

Thank you
cas
Posts: 1768
Joined: 11 Mar 2006, 16:08
Contact:

Re: searching in custom fields

Post by cas »

Just make the change as described in my previous response. No need to download anything. :mrgreen:
bloodlessz
Posts: 5
Joined: 28 Sep 2012, 07:41

Re: searching in custom fields

Post by bloodlessz »

Sorry,

I was looking under \api\soap\ folder on mc_filter_api.php.
Thats why i can't find these entries :oops: :oops:

It is working now

Thanks for your help :D
dente
Posts: 7
Joined: 13 May 2014, 08:44

Re: searching in custom fields

Post by dente »

Thank you so much for the help!

By against if you want to just look in a custom column?

(I would add a search bar that allows you to search in a column that I have created just before)
Post Reply