Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
78.57% covered (warning)
78.57%
11 / 14
72.73% covered (warning)
72.73%
8 / 11
CRAP
0.00% covered (danger)
0.00%
0 / 1
SearchQuery
78.57% covered (warning)
78.57%
11 / 14
72.73% covered (warning)
72.73%
8 / 11
12.19
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
1
 getId
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getQueryString
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getTaskType
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getTopic
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getSort
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setSort
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getRescoreProfile
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setRescoreProfile
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 getDebugUrl
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setDebugUrl
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace GrowthExperiments\NewcomerTasks\TaskSuggester\SearchStrategy;
4
5use GrowthExperiments\NewcomerTasks\TaskSuggester\UnderlinkedFunctionScoreBuilder;
6use GrowthExperiments\NewcomerTasks\TaskType\TaskType;
7use GrowthExperiments\NewcomerTasks\Topic\Topic;
8
9/**
10 * A search query string with some associated metadata about what it represents.
11 * For now, a query is associated with a single task type and a single topic; this might
12 * change in the future (see T238171#5870744).
13 */
14class SearchQuery {
15
16    /** Sort option with custom handling for prioritizing underlinked articles. */
17    public const RESCORE_UNDERLINKED = 'growth_underlinked';
18
19    /** @var string */
20    private $id;
21
22    /** @var string */
23    private $queryString;
24
25    /** @var TaskType */
26    private $taskType;
27
28    /** @var Topic|null */
29    private $topic;
30
31    /** @var string|null */
32    private $sort;
33
34    /** @var string|null */
35    private $rescoreProfile;
36
37    /** @var string|null */
38    private $debugUrl;
39
40    /**
41     * @param string $id Search ID. Used for internal purposes such as debugging or deduplication.
42     * @param string $queryString Search query string.
43     * @param TaskType $taskType Task type returned by the query.
44     * @param Topic|null $topic Topic returned by the query.
45     */
46    public function __construct( string $id, string $queryString, TaskType $taskType, ?Topic $topic ) {
47        $this->id = $id;
48        $this->queryString = $queryString;
49        $this->taskType = $taskType;
50        $this->topic = $topic;
51    }
52
53    /**
54     * Get a human-readable unique ID for this search query. This is used internally by the
55     * task suggester for deduplication and for debug logging.
56     * @return string
57     */
58    public function getId(): string {
59        return $this->id;
60    }
61
62    /**
63     * Get the search query string represented by this object. This is a string suitable for
64     * passing to SearchEngine::searchText() or the srsearch parameter of the search API.
65     * @return string
66     */
67    public function getQueryString(): string {
68        return $this->queryString;
69    }
70
71    /**
72     * Results from the search query will belong to this task type.
73     * @return TaskType
74     */
75    public function getTaskType(): TaskType {
76        return $this->taskType;
77    }
78
79    /**
80     * Results from the search query will belong to this topic.
81     * @return Topic|null
82     */
83    public function getTopic(): ?Topic {
84        return $this->topic;
85    }
86
87    /**
88     * Get the sort option to use for this query (for SearchEngine::setSort() / the srsort
89     * API parameter).
90     * @return string|null
91     */
92    public function getSort(): ?string {
93        return $this->sort;
94    }
95
96    /**
97     * @param string|null $sort
98     * @see ::getSort
99     */
100    public function setSort( ?string $sort ): void {
101        $this->sort = $sort;
102    }
103
104    /**
105     * Get the custom rescore profile to use.
106     * @return string|null
107     * @see UnderlinkedFunctionScoreBuilder
108     */
109    public function getRescoreProfile(): ?string {
110        return $this->rescoreProfile;
111    }
112
113    /**
114     * @param string $rescoreProfile
115     * @see ::getRescoreProfile
116     */
117    public function setRescoreProfile( string $rescoreProfile ) {
118        $this->rescoreProfile = $rescoreProfile;
119    }
120
121    /**
122     * Get debug URL for this query. This is an URL that will give detailed information about
123     * the search results and how they were scored.
124     * Note: this is only set after the search was performed, and it depends on the suggester
125     * and its debug settings whether it is set at all.
126     * @return string|null
127     */
128    public function getDebugUrl(): ?string {
129        return $this->debugUrl;
130    }
131
132    /**
133     * @param string|null $debugUrl
134     * @see ::getDebugUrl
135     */
136    public function setDebugUrl( ?string $debugUrl ): void {
137        $this->debugUrl = $debugUrl;
138    }
139
140}