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
argument :search, GraphQL::STRING_TYPE,
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,
required: false,
......
......@@ -168,18 +168,13 @@ module Ci
# Searches for runners matching the given query.
#
# This method uses ILIKE on PostgreSQL.
#
# 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.
# This method uses ILIKE on PostgreSQL for the description field and performs a full match on tokens.
#
# query - The search query as a String.
#
# Returns an ActiveRecord::Relation.
def self.search(query)
fuzzy_search(query, [:token, :description])
where(token: query).or(fuzzy_search(query, [:description]))
end
def self.online_contact_time_deadline
......
......@@ -336,7 +336,7 @@ four standard [pagination arguments](#connection-pagination-arguments):
| 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="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). |
......
......@@ -154,11 +154,11 @@ RSpec.describe Resolvers::Ci::RunnersResolver do
end
end
context 'to "def"' do
let(:search_term) { 'def' }
context 'to "defghi"' do
let(:search_term) { 'defghi' }
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
......
......@@ -873,12 +873,12 @@ RSpec.describe Ci::Runner do
expect(described_class.search(runner.token)).to eq([runner])
end
it 'returns runners with a partially matching token' do
expect(described_class.search(runner.token[0..2])).to eq([runner])
it 'does not return runners with a partially matching token' do
expect(described_class.search(runner.token[0..2])).to be_empty
end
it 'returns runners with a matching token regardless of the casing' do
expect(described_class.search(runner.token.upcase)).to eq([runner])
it 'does not return runners with a matching token with different casing' do
expect(described_class.search(runner.token.upcase)).to be_empty
end
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