Edgewall Software

Ticket #2530 (new defect)

Opened 2 years ago

Last modified 7 months ago

Search doesn't work on custom fields

Reported by: pavel4u@… Owned by: jonas
Priority: normal Milestone: 1.0
Component: search system Version: 0.9.5
Severity: normal Keywords: custom field tracobject
Cc:

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

Change History

follow-up: ↓ 2   Changed 2 years ago by jwin

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   Changed 23 months ago by anonymous

  • priority changed from normal to highest
  • version changed from 0.9b2 to 0.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

  Changed 23 months ago by anonymous

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

  Changed 23 months ago by anonymous

  • priority changed from highest to normal

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!

  Changed 23 months ago by anonymous

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.

  Changed 17 months ago by scott@…

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)

  Changed 14 months ago by cboos

  • keywords tracobject added; search removed
  • milestone set to 1.0

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

  Changed 9 months ago by sorberd@…

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

  Changed 9 months ago by cboos

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.

  Changed 7 months ago by schandler@…

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.

Add/Change #2530 (Search doesn't work on custom fields)

Author



Change Properties
<Author field>
Action
as new
as The resolution will be set. Next status will be 'closed'
to The owner will change. Next status will be 'new'
The owner will change to anonymous. Next status will be 'assigned'
 
Note: See TracTickets for help on using tickets.