You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What would you like to be able to do? Can you provide some examples?
I'd like to be able to set a search_exact: true option on a searchable field in my dashboard such that when administrate executes the search query, it matches results using an equality constraint instead of a LIKE '%my-string%' substring search. I mainly want to do this for performance reasons when searching for eg. all emails sent to a given email address, from a table that might hold a very large number of records.
The filter feature wasn't well suited to this because it requires the filter options to be defined upfront, and in a case like this I don't think that I'd really want to include every possible email in the filter options even if I could.
How could we go about implementing that?
I've put together a proof of concept in repo based off an older fork and the diffs are pretty minimal:
lib/administrate/field/base.rb
+ defself.search_exact?
+ false
+ end
lib/administrate/field/deferred.rb
+ defself.search_exact?
+ false
+ end
lib/administrate/search.rb
defquery_templatesearch_attributes.mapdo |attr|
table_name=query_table_name(attr)searchable_fields(attr).mapdo |field|
column_name=column_to_query(field)
+ ifattribute_types[attr].search_exact?
+ "LOWER(#{table_name}.#{column_name}) = ?"
+ else
+ "LOWER(CAST(#{table_name}.#{column_name} AS CHAR(256))) LIKE ?"
+ endend.join(" OR ")end.join(" OR ")end# [...]defquery_values
+ search_attributes.flat_mapdo |attr|
+ attribute_type=attribute_types[attr]
+
+ ifattribute_type.search_exact?
+ ["#{term.mb_chars.downcase}"] * searchable_fields(attr).count
+ else
+ ["%#{term.mb_chars.downcase}%"] * searchable_fields(attr).count
+ end
+ endend
There were a couple of specs that needed updating to validate the new option.
Can you think of other approaches to the problem?
No, but to be fair this is my first time digging into administrate. Also, caveat: I haven't tested this with non-text fields, this might still require the CAST to work across all types given the LOWER.
The text was updated successfully, but these errors were encountered:
Coincidentally I was looking for exactly this today! Similar scenario. Some very large tables that timeout with the LIKE scans even though the searchable fields are indexed. Would love to see this
Ok this is admittedly a little bit of a bait & switch, insofar as I've thrown in two other options alongside the one I'm proposing here 😅 but they're working towards the same goal: more performant search options!
I haven't gone as far as to document or test it, this is an initial proof of concept to see if we're at least aligned on the extra bits I'm requesting we add here before doing any more work.
I'd like to be able to set a
search_exact: true
option on a searchable field in my dashboard such that when administrate executes the search query, it matches results using an equality constraint instead of aLIKE '%my-string%'
substring search. I mainly want to do this for performance reasons when searching for eg. all emails sent to a given email address, from a table that might hold a very large number of records.The filter feature wasn't well suited to this because it requires the filter options to be defined upfront, and in a case like this I don't think that I'd really want to include every possible email in the filter options even if I could.
I've put together a proof of concept in repo based off an older fork and the diffs are pretty minimal:
lib/administrate/field/base.rb
lib/administrate/field/deferred.rb
lib/administrate/search.rb
There were a couple of specs that needed updating to validate the new option.
No, but to be fair this is my first time digging into administrate. Also, caveat: I haven't tested this with non-text fields, this might still require the
CAST
to work across all types given theLOWER
.The text was updated successfully, but these errors were encountered: