Edgewall Software
Modify

Opened 19 years ago

Closed 16 years ago

Last modified 16 years ago

#2530 closed defect (fixed)

Search doesn't work on custom fields

Reported by: pavel4u@… Owned by: Remy Blank
Priority: normal Milestone: 0.11.2
Component: search system Version: 0.9.5
Severity: normal Keywords: custom field tracobject
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

We used to add a reference to another bug tracking tool by adding the other number in the Keywords field. In this case the search (the search field on the top right) worked as expected and the ticket was found. Now we added a custom field to store the reference and the search doesn't work anymore → no ticket is found.

Attachments (4)

search-custom-fields.diff (1.2 KB ) - added by ThurnerRupert 16 years ago.
0.10.4 patch
search-custom-fields-0.11-stable-r7376.diff (1.2 KB ) - added by Christian Boos 16 years ago.
Same as the other patch, but for branches/0.11-stable (applies on a different file)
search-custom-fields-0.11-trunk-r7384.diff (1.2 KB ) - added by ThurnerRupert 16 years ago.
are you sure this patch works and should be not like this one?
2530-search-custom-fields-r7564.patch (1.2 KB ) - added by Remy Blank 16 years ago.
Updated patch for current 0.11-stable (and actually working :-)

Download all attachments as: .zip

Change History (21)

comment:1 by jwin, 19 years ago

this workes for me: excerpt from …/trac/ticket/api.py

...
        sql2, args2 = query_to_sql(db, query,
'summary||keywords||description||reporter||ltc||cc')
        cursor = db.cursor()
        cursor.execute("SELECT DISTINCT
a.summary,a.description,a.reporter, "
                       "a.keywords,a.id,a.time,c.value as ltc FROM ticket
a "
                       "LEFT JOIN ticket_change b ON a.id = b.ticket "
                       "LEFT OUTER JOIN ticket_custom c ON (a.id =
c.ticket AND c.name = 'ltc') "
                       "WHERE (b.field='comment' AND %s ) OR %s" % (sql,
sql2),
                       args + args2)
        for summary,desc,author,keywords,tid,date,ltc in cursor:
...

notice the occurrence of "ltc", which is my custom ticket field that should be searched for the query string

in reply to:  1 comment:2 by anonymous, 19 years ago

Priority: normalhighest
Version: 0.9b20.9.5

But how does this help? You don't want to edit api.py every time you add a custom field?

Surely seach should search in custom fields!

(We have the same problem. I end up putting the same text in a comment as well as the custom field … in the comment so search will find it and in the custom field so that it can be included in repots :S :S :S

comment:3 by anonymous, 19 years ago

In fact, an edit to api.py is obviously a temporary workaround since it will be lost next time you upgrade!

comment:4 by anonymous, 19 years ago

Priority: highestnormal

I realised that the *fantastic* new custom query page can be used to work around this limitation completely.

While the trac seach box doesn't work for custom fields, the custom query page does :)

Just dial up the custom field you're interested in and away you go!

comment:5 by anonymous, 18 years ago

We ran into the same problem on our instance. Unfortunately, it's a shared install with two instances running. The following code allows them both to search all custom fields for each particular instance without having to re-modify it in the future.

excerpt from …/trac/ticket/api.py

...
        sql, args = query_to_sql(db, query, 'b.newvalue')
        sql2, args2 = query_to_sql(db, query, 
'summary||keywords||description||reporter||cc')
        sql3, args3 = query_to_sql(db, query, 'c.value')
        cursor = db.cursor()
        cursor.execute("SELECT DISTINCT a.summary,a.description,a.reporter, "
                       "a.keywords,a.id,a.time FROM ticket a "
                       "LEFT JOIN ticket_change b ON a.id = b.ticket "
                       "LEFT OUTER JOIN ticket_custom c ON (a.id = c.ticket)"
                       "WHERE (b.field='comment' AND %s ) OR %s OR %s" % (sql, 
sql2, sql3),
                       args + args2 + args3)
        for summary,desc,author,keywords,tid,date,ltc in cursor:
...

This works only when you want to search across all custom fields.

comment:6 by scott@…, 18 years ago

Patch for 0.10.3

located in: trac_install_folder/trac/ticket/api.py

        db = self.env.get_db_cnx()
        sql, args = search_to_sql(db, ['b.newvalue'], terms)
        sql2, args2 = search_to_sql(db, ['summary', 'keywords', 'description',
                                         'reporter', 'cc'], terms)
        sql3, args3 = search_to_sql(db, ['c.value'], terms)
        cursor = db.cursor()
        cursor.execute("SELECT DISTINCT a.summary,a.description,a.reporter, "
                       "a.keywords,a.id,a.time,a.status FROM ticket a "
                       "LEFT JOIN ticket_change b ON a.id = b.ticket "
                       "LEFT OUTER JOIN ticket_custom c ON (a.id = c.ticket) "
                       "WHERE (b.field='comment' AND %s ) OR %s OR %s" % (sql,sql2, sql3),
                       args + args2 + args3)

comment:7 by Christian Boos, 18 years ago

Keywords: tracobject added; search removed
Milestone: 1.0

Search in custom text fields should be possible, especially when custom fields will be possible for other resources than just the tickets.

comment:8 by sorberd@…, 17 years ago

Is there really any reason that the simple patch posted above can not be incorporated into 0.11?

comment:9 by Christian Boos, 17 years ago

There need to be a way to specify that a custom field can be searchable. Also, this part of the code will be subject to some big changes (FieldRefactoring, SearchRefactoring), so I don't want to endorse the above change in the meantime.

comment:10 by schandler@…, 17 years ago

Short of a better solution, I could "get by" if the Custom Query page included filtering on the content of custom fields that are defined as type "textarea". The Add Filter drop list lists custom fields that are of type "text"; just not "textarea". Being able to select tickets in which a multiline text area called "Excellent Presidential Candidate List" contains "ron paul", for example, would be nice.

comment:11 by ThurnerRupert <rupert.thurner@…>, 16 years ago

this should look now

...
        sql, args = search_to_sql(db, ['b.newvalue'], terms)
        sql2, args2 = search_to_sql(db, ['summary', 'keywords', 'description',
                                         'reporter', 'cc'], terms)
        sql3, args3 = search_to_sql(db, ['c.value'], terms)
        cursor = db.cursor()
        cursor.execute("SELECT DISTINCT a.summary,a.description,a.reporter, "
                       "a.keywords,a.id,a.time,a.status FROM ticket a "
                       "LEFT JOIN ticket_change b ON a.id = b.ticket "
                       "LEFT OUTER JOIN ticket_custom c ON (a.id = c.ticket) "
                       "WHERE (b.field='comment' AND %s ) OR %s OR %s" % (sql, sql2, sql3),
                       args + args2 + args3)

...

comment:12 by Christian Boos, 16 years ago

TracDev/SubmittingPatches … patches exist for a reason, they give you the much needed information about the expected context of the change (file, line numbers).

by ThurnerRupert, 16 years ago

Attachment: search-custom-fields.diff added

0.10.4 patch

comment:13 by Christian Boos, 16 years ago

Milestone: 1.00.11.1
Owner: changed from Jonas Borgström to Christian Boos

Thanks! Ah, 0.10.4, well, let's see how that works with 0.11-stable. Tentatively scheduling for 0.11.1, but no promise ;-)

by Christian Boos, 16 years ago

Same as the other patch, but for branches/0.11-stable (applies on a different file)

comment:14 by Christian Boos, 16 years ago

Well, this will search on all custom fields, regardless on their types.

Can anyone see a problem with that?

by ThurnerRupert, 16 years ago

are you sure this patch works and should be not like this one?

by Remy Blank, 16 years ago

Updated patch for current 0.11-stable (and actually working :-)

comment:15 by anonymous, 16 years ago

Resolution: fixed
Status: newclosed

Patch applied in [7569].

comment:16 by Remy Blank, 16 years ago

(anonymous above was me)

comment:17 by Christian Boos, 16 years ago

Owner: changed from Christian Boos to Remy Blank

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Remy Blank.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Remy Blank to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.