#2530 closed defect (fixed)
Search doesn't work on custom fields
Reported by: | 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)
Change History (21)
follow-up: 2 comment:1 by , 19 years ago
comment:2 by , 18 years ago
Priority: | normal → highest |
---|---|
Version: | 0.9b2 → 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
comment:3 by , 18 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 , 18 years ago
Priority: | highest → 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!
comment:5 by , 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 , 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 , 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 , 17 years ago
Is there really any reason that the simple patch posted above can not be incorporated into 0.11?
comment:9 by , 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 , 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 , 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 , 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).
comment:13 by , 16 years ago
Milestone: | 1.0 → 0.11.1 |
---|---|
Owner: | changed from | to
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 , 16 years ago
Attachment: | search-custom-fields-0.11-stable-r7376.diff added |
---|
Same as the other patch, but for branches/0.11-stable (applies on a different file)
comment:14 by , 16 years ago
Well, this will search on all custom fields, regardless on their types.
Can anyone see a problem with that?
by , 16 years ago
Attachment: | search-custom-fields-0.11-trunk-r7384.diff added |
---|
are you sure this patch works and should be not like this one?
by , 16 years ago
Attachment: | 2530-search-custom-fields-r7564.patch added |
---|
Updated patch for current 0.11-stable (and actually working :-)
comment:17 by , 16 years ago
Owner: | changed from | to
---|
this workes for me: excerpt from …/trac/ticket/api.py
notice the occurrence of "ltc", which is my custom ticket field that should be searched for the query string