Commit 83f64a99 authored by Pedro Pombeiro's avatar Pedro Pombeiro

Make Ci::Runner.search only match full token

It is not a documented functionality so we avoid creating a new index
parent 56fa3f3b
...@@ -19,7 +19,7 @@ module Resolvers ...@@ -19,7 +19,7 @@ module Resolvers
argument :search, GraphQL::STRING_TYPE, argument :search, GraphQL::STRING_TYPE,
required: false, required: false,
description: 'Filter by text present in token or description fields.' description: 'Filter by token or text present in description field.'
argument :sort, ::Types::Ci::RunnerSortEnum, argument :sort, ::Types::Ci::RunnerSortEnum,
required: false, required: false,
......
...@@ -168,18 +168,13 @@ module Ci ...@@ -168,18 +168,13 @@ module Ci
# Searches for runners matching the given query. # Searches for runners matching the given query.
# #
# This method uses ILIKE on PostgreSQL. # This method uses ILIKE on PostgreSQL for the description field and performs a full match on tokens.
#
# This method performs a *partial* match on tokens, thus a query for "a"
# will match any runner where the token contains the letter "a". As a result
# you should *not* use this method for non-admin purposes as otherwise users
# might be able to query a list of all runners.
# #
# query - The search query as a String. # query - The search query as a String.
# #
# Returns an ActiveRecord::Relation. # Returns an ActiveRecord::Relation.
def self.search(query) def self.search(query)
fuzzy_search(query, [:token, :description]) where(token: query).or(fuzzy_search(query, [:description]))
end end
def self.online_contact_time_deadline def self.online_contact_time_deadline
......
...@@ -336,7 +336,7 @@ four standard [pagination arguments](#connection-pagination-arguments): ...@@ -336,7 +336,7 @@ four standard [pagination arguments](#connection-pagination-arguments):
| Name | Type | Description | | Name | Type | Description |
| ---- | ---- | ----------- | | ---- | ---- | ----------- |
| <a id="queryrunnerssearch"></a>`search` | [`String`](#string) | Filter by text present in token or description fields. | | <a id="queryrunnerssearch"></a>`search` | [`String`](#string) | Filter by token or text present in description field. |
| <a id="queryrunnerssort"></a>`sort` | [`CiRunnerSort`](#cirunnersort) | Sort order of results. | | <a id="queryrunnerssort"></a>`sort` | [`CiRunnerSort`](#cirunnersort) | Sort order of results. |
| <a id="queryrunnersstatus"></a>`status` | [`CiRunnerStatus`](#cirunnerstatus) | Filter runners by status. | | <a id="queryrunnersstatus"></a>`status` | [`CiRunnerStatus`](#cirunnerstatus) | Filter runners by status. |
| <a id="queryrunnerstaglist"></a>`tagList` | [`[String!]`](#string) | Filter by tags associated with the runner (comma-separated or array). | | <a id="queryrunnerstaglist"></a>`tagList` | [`[String!]`](#string) | Filter by tags associated with the runner (comma-separated or array). |
......
...@@ -154,11 +154,11 @@ RSpec.describe Resolvers::Ci::RunnersResolver do ...@@ -154,11 +154,11 @@ RSpec.describe Resolvers::Ci::RunnersResolver do
end end
end end
context 'to "def"' do context 'to "defghi"' do
let(:search_term) { 'def' } let(:search_term) { 'defghi' }
it 'returns runners containing term in token' do it 'returns runners containing term in token' do
is_expected.to contain_exactly(inactive_project_runner, offline_project_runner) is_expected.to contain_exactly(offline_project_runner)
end end
end end
end end
......
...@@ -873,12 +873,12 @@ RSpec.describe Ci::Runner do ...@@ -873,12 +873,12 @@ RSpec.describe Ci::Runner do
expect(described_class.search(runner.token)).to eq([runner]) expect(described_class.search(runner.token)).to eq([runner])
end end
it 'returns runners with a partially matching token' do it 'does not return runners with a partially matching token' do
expect(described_class.search(runner.token[0..2])).to eq([runner]) expect(described_class.search(runner.token[0..2])).to be_empty
end end
it 'returns runners with a matching token regardless of the casing' do it 'does not return runners with a matching token with different casing' do
expect(described_class.search(runner.token.upcase)).to eq([runner]) expect(described_class.search(runner.token.upcase)).to be_empty
end end
it 'returns runners with a matching description' do it 'returns runners with a matching description' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment