Commit graph

518 commits

Author SHA1 Message Date
Erik Bernhardson
930b8fcd73 Update ISearchResultSet snippet/HtmlArmor documentation
Followup to I76231d6f adding more clarity to the doc blocks that were
changed with respect to when and why they can return different values.

Change-Id: I9afe50c8ee7a74b2c99a89ab19817e466153ba78
2019-12-17 10:21:54 -08:00
Umherirrender
554ef816e4 Fix doc of SearchIndexFieldDefinition::getIndexType
The class property is declared to be string

Change-Id: I1fa7f84ccbf55f5a29016f7bffc9fa7d527627b8
2019-12-15 17:30:16 +01:00
jenkins-bot
cab00f54ab Merge "Return HtmlArmor for Search ResultSet snippets" 2019-12-13 08:27:35 +00:00
Erik Bernhardson
0c8289e5db Return HtmlArmor for Search ResultSet snippets
Passing around strings that are expected to be safe html and are
known to be based on user input is a fairly unsafe operation. Make
it harder to do the wrong thing by requiring HtmlArmor to be returned
from the ResultSet snippets. This does not address the snippets on
individual result objects as the api surface is larger and requires
more bc handling.

Change-Id: I76231d6fc53c4982eb4cd174d2e6a75eb2740497
2019-12-12 10:14:50 -08:00
Umherirrender
0688dd7c6d Set method visibility for various constructors
Change-Id: Id3c88257e866923b06e878ccdeddded7f08f2c98
2019-12-03 20:17:30 +01:00
Umherirrender
c7ad21c25f Improve param docs
Change-Id: I746a69f6ed01c3ff000da125457df62b02d13b34
2019-11-28 19:08:59 +01:00
Umherirrender
337ecb0514 Add missing @param and @return to documentation
Change-Id: Ibc5849cc8ea7e7c4eb30ded9c1cfa5f52187c377
2019-11-10 22:12:58 +00:00
Daimona Eaytoy
b1a5367ec8 Fix new phan errors, part 7
Bug: T231636
Change-Id: Ia5e0abee7163c5a1abd0bb53b89603cc2e7a9b5c
2019-10-21 22:10:20 +00:00
jenkins-bot
abfea4c7ff Merge "Add faux SearchResult and SearchResultSet" 2019-10-21 09:37:50 +00:00
Daimona Eaytoy
bd5b6f98ba Fix new phan errors, part 3
These are almost only doc changes, with two exceptions:
1-In LinkHolderArray, int-alike array keys are now cast to int, to be uniform with what we do in other code paths
2-In ExtensionRegistration, changed a line to throw an Exception
immediately, instead of an ExtensionDependencyError. This is because the
latter takes an array with msg and type, but we were passing it a plain
string (and in fact the code was bugged).

Bug: T231636
Change-Id: I8b0ef50d279c2a87490dde6a467a4e22c0710afd
2019-10-12 10:35:22 +00:00
Gergő Tisza
c296cf69b4
Add faux SearchResult and SearchResultSet
The use case is code that uses search internally, but wants to allow
a development setup where search is proxied via some public API and
the actual querying is performed on a production server, instead of
having to set up all the search services + staging content locally.

Also fix a small logic error in SearchResultSet::shrink.

Change-Id: I83931c1a19c1cb747380e17a4aff3b1fadd5fcf3
2019-10-07 16:35:58 +02:00
Daimona Eaytoy
d40c7e24f8 searchResult: Fix docs for mTitle
It's documented as Title, but there's plenty of checks for null.

Bug: T233763
Change-Id: Id3b89caaa857000a42534f164eecad8a6e791de4
2019-10-07 13:10:34 +02:00
Thiemo Kreuz
879f749a62 Remove meaningless (auto-generated?) constructor documentation
Yes, the constructor of a class constructs a new instance of that
class. That's what constructors are for. No need to document this.

Change-Id: Ia94f476512f437f48edfeb71d95b269ac2ca0ab4
2019-10-01 14:34:21 +02:00
Daimona Eaytoy
c659bc6308 Unsuppress another phan issue (part 7)
Bug: T231636
Depends-On: I2cd24e73726394e3200a570c45d5e86b6849bfa9
Depends-On: I4fa3e6aad872434ca397325ed7a83f94973661d0
Change-Id: Ie6233561de78457cae5e4e44e220feec2d1272d8
2019-09-03 17:19:21 +00:00
Daimona Eaytoy
e2e543f7c2 Unsuppress more phan issues (part 5)
Bug: T231636
Depends-On: I6e5fba7bd273219b1206559420b5bdb78734aa84
Change-Id: I50377746f01749b058c39fd8229f9d566224cc43
2019-09-01 09:48:31 +00:00
David Causse
bf9a7cad61 Hard deprecate new SearchResult() and introduce RevisionSearchResult
Transitional step for the transformation of SearchResult into an
abstract base class:
- RevisionSearchResult is introduced to behave like SearchResult
- methods are currently shared between  RevisionSearchResult and
  SearchResult in the RevisionSearchResultTrait

Bug: T228626
Change-Id: I13d132de50f6c66086b7f9055d036f2e76667b27
2019-08-27 08:27:28 -07:00
David Causse
9d944bd816 Add SearchResultTrait
to hold non-obvious behaviors and rarely specialized methods.

Change-Id: Idc600e22b35a01be8be8cb629bfb09701e842cd7
2019-08-20 18:24:44 +02:00
David Causse
7d1d48ed5f Break the cyclic dependency between SearchEngine and SearchResult
Change-Id: Icda469eb675ccac6048d7a9d978d51e3e673edab
2019-08-20 18:24:44 +02:00
jenkins-bot
59491d8289 Merge "Use ExtensionRegistry instead of class name" 2019-08-15 08:02:53 +00:00
Amir Sarabadani
4b80ca45f7 Drop last bits of oracle
Undefined constant

Change-Id: I66f17a7647bdcf254695dd0d3a0d49d41a35fff3
2019-08-14 23:44:22 +02:00
WMDE-Fisch
e1518660e1 Use ExtensionRegistry instead of class name
Use the ExtensionRegistry instead of checking for the main class
name of the Cite extension. - I'm not entirely sure if this is much
better. A hook would still be the better option. But at least Cite
could be refactored and the class name changed.

Bug: T89151
Change-Id: I35e5aa9955141b575de68a5be2c0d5b87585eb77
2019-08-14 19:07:39 +02:00
Aaron Schulz
2eb5bdbac6 rdbms: remove DatabaseSqlite::checkForEnabledSearch() in favor of explicit queries
Change-Id: I0f13b9f054d7732f0e9694ec75c415f91a36ede9
2019-08-07 18:47:36 -07:00
jenkins-bot
bb844b11ba Merge "Deprecate SearchEngine:getTextFromContent() and SearchEngine::textAlreadyUpdatedForIndex()" 2019-08-02 06:40:17 +00:00
jenkins-bot
f585244a77 Merge "Document SearchDatabase::doSearchTextInDB to return null" 2019-08-01 21:51:36 +00:00
David Causse
63e199226d Deprecate SearchEngine:getTextFromContent() and SearchEngine::textAlreadyUpdatedForIndex()
It was just a wrapper to Content::getTextForSearchIndex(), simply use
this method rather than depending on (and sometimes constructing) a
SearchEngine.

Change-Id: I8541248ffdca303f0af3b959cf2f051dcb497925
2019-08-01 17:59:32 +02:00
David Causse
c6b4bdf0ab Deprecate SearchEngine::userHighlightPrefs()
was only returning two constants and forced a cyclic dep bewteen
SearchEngine and its SearchResult instance.
Simple make these values a constant in SearchHighlighter and use
them as default values for the highlight methods.

Change-Id: Ia78408d5266d0a305006027fe6265a2a1d68b0b9
2019-08-01 17:16:41 +02:00
Umherirrender
b037a852f8 Document SearchDatabase::doSearchTextInDB to return null
The function calling this abstract function allows to return null,
so it should be okay to return null here

The null for empty result in SearchOracle

Change-Id: I66a8fb3a4190bf5506f358a47f6f4833b1715c7f
2019-07-31 18:15:13 +02:00
David Causse
ff6b6a758a Add SearchResultSetTrait
trait meant to hold methods that rarely overridden or that are
non trivial to implement.

Bug: T228626
Change-Id: I4fba27b22860109d648e830a435d4a036d26ad06
2019-07-25 15:52:36 +02:00
David Causse
e97ff3524b Add BaseSearchResultSet
Meant to hold the B/C behaviors and be the base class implemented
by extensions.

Bug: T228626
Change-Id: I072a9bd0f94bd785d1ff51f0e6ee13790e37b417
2019-07-25 15:47:01 +02:00
David Causse
7a8ef16670 Add explicit visibility to SearchResult methods
Change-Id: Ifaa2f6b683690a130eef3439ffd9c1debfb188fe
2019-07-24 12:01:46 +02:00
David Causse
79895c7882 Add explicit visibility to ISearchResultSet methods
Change-Id: Ic1ad60fac6183004c4dfc110c8dfde95b57cdd9b
2019-07-23 10:59:41 +02:00
David Causse
6af636fb03 Add ISearchResultSet
Bug: T228626
Change-Id: I3306bf6107c97dd58adf578fd965bd11a422627d
2019-07-22 18:27:39 +00:00
David Causse
5420bf307b Deprecate SearchResultSet::free
Was only called by SpecialSearch, according to IResultWrapper::free()
this method is rarely worth being called. Therefor it does not seem wise
to expose it in the upcoming interface defining a search result set.

Bug: T228626
Change-Id: I12d41a488025eb2d6dd543c9fbdc1c803c840316
2019-07-22 17:46:00 +02:00
Aaron Schulz
f72ae0f6e6 Switch various LoadBalancer::getConnection() callers to getConnectionRef()
This is the preferred method as it enforces read-only mode for DB_REPLICA
and handles LoadBalancer::reuseConnection() calls automatically.

Change-Id: Iab9439ba8e0810fa14c302661ed7a3534f6bfc0d
2019-07-12 10:56:30 -07:00
David Causse
92c20832f1 Deprecate SearchResult::termMatches()
And start indicating that hooks relying on this data might become
unreliable as this data is only populated by SearchDatabase search
engines.

This information was only populated by SearchDatabase implementations
and due to bad initial design of SearchResult[Set] (now fixed) it forced
users of these classes to carry this information for the sole purpose of
highlighting.
Because SearchEngine can now own their SearchResult[Set] implementations
nothing that is engine specific should be exposed outside of these
specific implementations.
If there are some logic that still requires access to such list of terms
they should be made engine specific by guarding their code against
instanceof SqlSearchResult.

Change-Id: I38b82c5e4c35309ee447edc3ded60ca6a18b247a
Depends-On: I53fe37c65c7940f696c1e184125e01e592a976e4
2019-06-27 08:44:06 -07:00
Aaron Schulz
d16fb6515b search: refactor DatabaseSearch to take a load balancer instance
Also make the update() methods of the subclasses use DB_MASTER as they
should. This avoids read-only errors.

In addition, avoid passing a dummy argument of null in some cases
within SearchEngineFactory::create(). Fix some dynamic calls to
static methods too.

Change-Id: Id94f34994b0f9c18e23ef30cb2fe895e6dedd09c
2019-06-26 03:03:37 +00:00
James D. Forrester
ac5b9e53df PrefixSearch: Drop titleSearch(), deprecated in 1.23
Change-Id: I3e11421953bfe63856e29b928727c8264275cd25
2019-06-24 11:11:17 -07:00
jenkins-bot
8ffabe23a1 Merge "Fix param type of search terms in search related classes" 2019-06-17 07:54:27 +00:00
Aaron Schulz
a15be13371 search: clean up some type hints in search classes
Change-Id: I357a78b42ea02a63c3b64e8982f04314cbbfdf9f
2019-06-16 23:29:33 +00:00
Umherirrender
9421f6f52f Fix param type of search terms in search related classes
Change-Id: I036434268f1e7992f7f9f23d2c1c0fcd399823c8
2019-06-14 19:50:12 +02:00
Derick Alangi
21e2d71560 Replace some uses of deprecated wfFindFile() and wfLocalFile()
These global functions were deprecated in 1.34 and services made
available to replace them. See services below;

* wfFindFile() - MediaWikiServices::getInstance()->getRepoGroup()->findFile()
* wfLocalFind() - MediaWikiServices::getInstance()->getRepoGroup()->getLocalRepo()->newFile()

NOTES:

* wfFindFile() and wfLocalFind() usages in tests have been ignored
  in this change per @Timo's comments about state of objects.

* includes/upload/UploadBase.php also maintained for now as it causes
  some failures I don't fully understand, will investigate and handle
  it in a follow up patch.

* Also, includes/MovePage.php

Change-Id: I9437494de003f40fbe591321da7b42d16bb732d6
2019-06-11 13:26:37 +00:00
Derick Alangi
09567cc368 SearchResultSet: MW version number should be a string in wfDeprecated call
Seems this was a typo and I think 1.32 which is a double/float will be
implicitly converted to true (bool) because it will resolve 1.32 to 1 as
integer and then 1 which maps to true (bool).

To avoid this, use '1.32' instead of the integer form of the version.

Change-Id: Ifaf6ab0d36bc02bd1707f8caf375f65a30eb1af5
2019-05-15 15:17:23 +01:00
Derick Alangi
facddc488a SearchResult: MW version number should be a string in wfDeprecated call
Seems this was a typo and I think 1.32 which is a double/float will be
implicitly converted to true (bool) because it will resolve 1.32 to 1 as
integer and then 1 which maps to true (bool).

To avoid this, use '1.32' instead of the integer form of the version.

Change-Id: I2420396e110284f582cd79820ffc6064e247b4b9
2019-05-14 12:36:30 +00:00
Derick Alangi
a1731db5ab SearchEngine: Remove deprecated unused method transformSearchTerm()
I've checked around with code search tool and realized that SMW has
its own implementation of `transformSearchTerm()` which overwrites the
implementation of this method from core as it extends SearchEngine.

So removing this won't break SMW, see usage below;

Usage
=====

https://codesearch.wmflabs.org/search/?q=%5CbtransformSearchTerm%5Cb&i=nope&files=&repos=

Bug: T220656
Change-Id: I3dbe04ecba07700167c894673e23c1eead95460f
2019-05-13 15:37:00 +01:00
jenkins-bot
34d2b3aa23 Merge "Simplify by using ?: operator" 2019-05-09 16:25:22 +00:00
Derick Alangi
15269e9500 SearchEngine: Followup on I623b39e7ec791a66c4cf40
Per https://www.mediawiki.org/wiki/Deprecation_policy#Deprecation,
the version for hard deprecation must be exactly the same as the
one it was soft deprecated in.

Bug: T221431
Change-Id: Ib7c2b569959194e15f50c62fe0eca1c3011bc50e
2019-05-09 15:54:56 +01:00
jenkins-bot
3b0ff76e95 Merge "SearchEngine: Hard deprecate SearchEngine::transformSearchTerm()" 2019-05-07 19:51:34 +00:00
Derick Alangi
20bb2b067e SearchEngine: Hard-deprecate PrefixSearch::titleSearch()
Usage
=====

https://codesearch.wmflabs.org/search/?q=%5B%5E%3E%5D(-%3E%7C%3A%3A)titleSearch&i=nope&files=&repos=

Only the MassEditRegex extension uses this method per the search,
so hard deprecating this method.

Change-Id: Ia10caacd3cde94f08e59f5f8d7e90f61c7de604e
2019-05-06 15:57:21 +00:00
Derick Alangi
f9f2809a38 SearchEngine: Hard deprecate SearchEngine::transformSearchTerm()
As a follow up of it's soft deprecation in 1.32, this method should
be hard deprecated and removed. Also, remove related code that calls
this method.

Usage:

https://codesearch.wmflabs.org/search/?q=(%3A%3A%7C-%3E)transformSearchTerm&i=nope&files=&repos=

Bug: T221431
Change-Id: I623b39e7ec791a66c4cf40178edb80b2ebf4bb06
2019-04-26 19:24:02 +00:00
jenkins-bot
37344b9daf Merge "Define index types as strings" 2019-04-23 08:57:59 +00:00
Stanislav Malyshev
9e035a229e Define index types as strings
This will allow to use them easier in JSON config files.

Bug: T142809
Change-Id: I4053a87fe8e53c9b506604db6fad2f98f7dba150
2019-04-18 23:59:18 -07:00
Derick Alangi
0a4c2670a1 search: Remove unused deprecated methods replaced by MW Services
The following methods deprecated in .27 and no longer used have
been removed;

- SearchEngine::userNamespaces()
  https://codesearch.wmflabs.org/search/?q=%3A%3AuserNamespaces&i=nope&files=&repos=

- SearchEngine::namespacesAsText()
  https://codesearch.wmflabs.org/search/?q=%3A%3AnamespacesAsText&i=nope&files=&repos=

- SearchEngine::create()
  https://codesearch.wmflabs.org/search/?q=SearchEngine%3A%3Acreate&i=nope&files=&repos=

- SearchEngine::getSearchTypes()
  https://codesearch.wmflabs.org/search/?q=%3A%3AgetSearchTypes&i=nope&files=&repos=

- SearchEngine::getNearMatch()
  https://codesearch.wmflabs.org/search/?q=SearchEngine%3A%3AgetNearMatch%5C(&i=nope&files=&repos=

Also, replace deprecated use of searchableNamespaces() in SearchEngine.

Bug: T220656
Change-Id: I330fbfea158f70b2328da7c850fdb833e39b6c7d
2019-04-19 00:09:42 +00:00
James D. Forrester
f84457f8bd SearchEngine: Hard deprecate unused static methods deprecated in 1.27
Change-Id: I96c4454a2f89df0be5de20ca0506c3ce2c75cf7c
2019-04-18 16:54:30 -07:00
Fomafix
8a314d9b43 Simplify by using ?: operator
Change-Id: I2851cc51c9e05dd0599733be5af39e19f12b52e2
2019-04-15 15:05:00 +02:00
jenkins-bot
7f2f49ad23 Merge "Improve documentation of constants throughout the codebase" 2019-04-12 21:38:16 +00:00
Aaron Schulz
449ad97224 search: make legalSearchChars() non-static
No outside callers from code in gerrit are using this statically

Change-Id: I9513a5384bca71f419a9af09908678bcc86c0263
2019-04-11 17:55:54 -07:00
jenkins-bot
b306873222 Merge "Remove references to field rev_text_id" 2019-04-09 15:25:05 +00:00
Kunal Mehta
4ef179e335 Fix/suppress misc phan errors (#5)
Add lots of missing return statements, or remove incorrect doc blocks.

Change-Id: I0881e98fbb9d0d4cf79ecc824064d24538055d3f
2019-04-05 15:53:37 -07:00
Umherirrender
6745cb572a Move class SearchEngineDummy to own file
Each class should have its own file, even it is a no-op

Change-Id: I90124ed35e354c546fcd69d52dc1febb71b2c71f
2019-03-29 20:35:35 +01:00
Umherirrender
8d5a8fb181 Move PrefixSearch classes to own files
Move all into search subfolder

Change-Id: I4097b9745d22545afe6761da1fa67cf98af5b811
2019-03-27 21:40:33 +01:00
Bill Pirkle
8f03082521 Remove references to field rev_text_id
Field rev_text_id is being retired as part of MCR Schema Migration.
Remove references to this field from the Postgres search queries.

Bug: T198341
Change-Id: Id3cbf853aacc06709f441a93248b55943097cd11
2019-03-26 10:41:29 -05:00
Thiemo Kreuz
18741b9306 Improve documentation of constants throughout the codebase
The most notable improvements I was able to fit into this patch can be
seen in the User class, as well as in AbstractRestriction.

Our documentation generator ignores the @const tag. It's not needed. Just
have a comment above a constant and it will show up in the generated
documentation.

Using @var is misleading because a constant is not a "variable". The type
of a constant is strictly derived from it's value. Documenting the type
typically does not provide useful information. Doxygen does not understand
the type, but ignores any @… tag and renders everything else as plain text.

I can split this patch if you prefer. Please tell me.

Change-Id: I8019ae45c049822cdc1768d895ea3e3216c6db5f
2019-02-26 14:02:50 +01:00
James D. Forrester
5cc3a2ae4e Drop SearchEngine::getNearMatchResultSet(), deprecated in 1.27 and unused
Change-Id: I87987af702b9b92c4d1b3578e69f1b2e68529b52
2019-02-09 08:43:30 +00:00
Thiemo Kreuz
734a969d55 Safe replacement of a lot of !count() with === []
This was originally a global search and replace. I manually checked all
replacements and reverted them if (due to the lack of type hints) either
null (that would be 0 when counted) or a Countable object can end in the
variable or property in question.

Now this patch only touches places where I'm sure nothing can break.

For the sanity of the honorable reviewers this patch is exclusively touching
negated counts. You should not find a single `!== []` in this patch, that
would be a mistake.

Change-Id: I5eafd4d8fccdb53a668be8e6f25a566f9c3a0a95
2019-01-15 17:28:49 +01:00
Max Semenik
1da14005d9 Hard deprecate SearchEngine::getNearMatchResultSet()
Deprecated in 1.27, no callers.

Change-Id: I6084a114fe8d0b4681e2e4b55eada06b684c719c
2018-12-08 22:23:24 -08:00
jenkins-bot
bd78869618 Merge "No yoda conditions" 2018-12-09 01:34:23 +00:00
Jakub Vrana
45435d05a5 Change typehint callback to callable
Found by PHPStan.

Change-Id: I09f21da69ad9b9357cee85a47717dbe1bca04070
2018-12-01 10:10:41 +01:00
Fomafix
3ee1560232 No yoda conditions
Replace
  if ( 42 === $foo )
by
  if ( $foo === 42 )

Change-Id: Ice320ef1ae64a59ed035c20134326b35d454f943
2018-11-21 17:54:39 +01:00
jenkins-bot
5466734477 Merge "doc: Modernise parameter names and documentation for 'replica' DBs" 2018-11-13 21:39:14 +00:00
jenkins-bot
fbc9e214e7 Merge "Add docstrings for text search index field types" 2018-11-01 10:21:55 +00:00
Adam Wight
861d718768 Add docstrings for text search index field types
Change-Id: Icd34ec79db4d8fd024a82045aaa9bedb6556caa8
2018-10-31 17:30:58 -07:00
James D. Forrester
903e8b63de doc: Modernise parameter names and documentation for 'replica' DBs
Non-breaking change. Remaining uses are public interfaces (a constant, two
globals, a config sub-parameter, SQL queries, storage function names), one i18n
message key, and a whole lot of maintenance scripts with calls to the deprecated
function wfWaitForSlaves().

Change-Id: I6ee5ca92ccf6a80c08f53d9efe38ebb4b05064d7
2018-10-31 10:36:48 -07:00
Fomafix
43244db9a2 Use PHP 7 '??' operator instead of if-then-else
Change-Id: If9d4be5d88c8927f63cbb84dfc8181baf62ea3eb
2018-10-21 21:46:46 +02:00
Fomafix
5632815976 Write Latin and other scripts with captial letter
Change-Id: I16c660e54191b63cd6eb3407cb00504665930c4e
2018-10-05 18:49:08 +02:00
Erik Bernhardson
b357416273 Go search to consider fragment only title invalid
When submiting using the 'go' feature of Special:Search (standard
usecase for autocomplete) a nearby title can be selected.
Unfortunately a fragment only title is considered valid, which
sends the user to Main_Page#searchterm.

Instead don't allow a search starting with # to trigger the go
feature.

Bug: T182452
Change-Id: I8ce3ce8633e23db41ae6eafb9996ca7294f8445a
2018-09-11 13:03:53 -07:00
Zoranzoki21
1f2e9c1b54 Fix common typos in code
Bug: T201491
Change-Id: Id962b79f2590c51380cb977e727b7548abc11d33
2018-09-02 09:03:07 +00:00
jenkins-bot
9171317645 Merge "Add Special:Search sort parameter without ui" 2018-08-21 14:57:13 +00:00
Umherirrender
40d3ce8d17 Reduce calls to MediaWikiServices::getInstance()
In some functions MediaWikiServices::getInstance() was called twices or
in loops. Extract the variable to reduce calls.

Change-Id: I2705db11d7a9ea73efb9b5a5c40747ab0b3ea36f
2018-08-18 06:02:39 +02:00
Erik Bernhardson
c6a83871b5 Add Special:Search sort parameter without ui
Search engines support the sort parameter, it would be nice if we
could pass it to be rendered in the web ui. This avoids implementing
any ui, which can be done at a later time.

Bug: T195071
Change-Id: Id7bd35bd4259bb1f1f856933d279dbd6eddfa2e2
2018-08-16 17:12:05 -07:00
Aryeh Gregor
90d4f56fe4 Mass conversion of $wgContLang to service
Brought to you by vim macros.

Bug: T200246
Change-Id: I79e919f4553e3bd3eb714073fed7a43051b4fb2a
2018-08-11 22:44:29 -06:00
Timo Tijhof
64892ce978 search: Use self::class instead of __CLASS__ in SearchResultSet
For ease of understanding, use the same technique for both
sides of the comparison. Follows-up c2a308075f.

Change-Id: I66475fd4baaa6ab7cd24ad884e9fe01a1cd30d9f
2018-08-08 01:08:37 +01:00
David Causse
cf41c48f8d Deprecate SearchEngine::replacePrefixes
This should be handled internally by SearchEngine implementations.

Bug: T198860
Change-Id: Ifbfd0fcb81fcacf5228bd2ffcac7b80fca872b2a
Depends-On: I7d4ff9498fa1f4ea66835c634b8931f4c29993fb
2018-07-17 21:56:14 +00:00
David Causse
3115b3202d Unify SearchEngine normalizeNamespace and parseNamespacePrefixes
These methods are very similar there should be no need to have
two differents way to extract the namespace prefix.

Bug: T198860
Change-Id: I22802278452559d35a3d8f6068549c1fef1a5e86
2018-07-17 21:56:05 +00:00
David Causse
46c17ddb1f Deprecate usage of SearchEngine:transformSearchTerm
This method was introduced in 4115586000
to support the prefix URI param introduced by the InputBox extension.
There are no reasons that this logic is exposed to SearchEngine users
and should be handled internally by SearchEngine implementations
that supports it.
Previously the search query was updated, now the prefix param will passed
along using SpecialSearch::$extraParams.

Bug: T198318
Change-Id: I33518d3f3ddee741ff4f3b47eb4928009bea66d1
Depends-On: I67c7f1886dd6a2d07c12015e2711c138e9f140e9
2018-07-17 14:41:08 -07:00
jenkins-bot
ef97002179 Merge "Simplify PHP by using ?? and ?:" 2018-07-11 09:09:18 +00:00
Fomafix
6866cfec37 Simplify PHP by using ?? and ?:
Also remove not necessary surrounding parentheses.

Change-Id: I0eb5c9c1bdfb09a800258379cdcefb5fd4d3d21c
2018-07-10 20:03:17 +00:00
C. Scott Ananian
0935e47a72 Remove most uses of deprecated Language::truncate()
The Language::truncate() function was split into
Language::truncateForVisual() (which measures characters) and
Language::truncateForDatabase() (which measures bytes) in 1.31, but
the patch which soft-deprecated Language::truncate() didn't actually
remove all the uses in the codebase.  Replace most of those old uses
now, which should actually improve the situation for
non-latin-alphabet users who were getting unfairly squeezed in a
number of places.

Bug: T197492
Change-Id: I2291c69d9df17c1a9e4ab1b7d4cbc73bc51d3ebb
2018-07-09 13:36:27 -04:00
Umherirrender
130ec2523d Fix PhanTypeMismatchDeclaredParam
Auto fix MediaWiki.Commenting.FunctionComment.DefaultNullTypeParam sniff

Change-Id: I865323fd0295aabd06f3e3c75e0e5043fb31069e
2018-07-07 00:34:30 +00:00
Umherirrender
ae2f5d6232 Add missing use statements
Swap some ResultWrapper/Database to interface IResultWrapper/IDatabase

Change-Id: I312cb3cca5742f72efdb0965ba35362f2eb1129d
2018-06-27 20:49:23 +02:00
Erik Bernhardson
83bae78c3a Silently drop unknown titles in completion search
This mimics how full text works by silenty dropping results returned from
search that no longer exist. This could be because the search index is slightly
out of sync with reality, or the search engine could simply be broken.

Only silent from the users perspective. We maintain a count in statsd of
the number of titles dropped. This can be monitored over time to
recognize any increases.

Bug: T115756
Change-Id: I2f29d73e258cd448a14d35a2b4902a4fb6f61c68
2018-06-11 13:56:19 -07:00
Erik Bernhardson
2a43939ffb Push pagination decision for search into SearchEngine
Various code using the search engine shouldn't need to implement it's
own methods, such as over-fetching, to determine if there are more
results available. This should be knowledge internal to search that is
exposed by a boolean.

Change-Id: Ica094428700637dfdedb723b03f6aeadfe12b9f4
2018-06-11 13:35:44 -07:00
Erik Bernhardson
c2a308075f Convert SearchResultSet to typical iteration
The funky iteration here was at best annoying. Switch
it over to an iterator based approach with appropriate
BC code to simulate the old iteration style.

Depends-On: I19a8d6621a130811871dec9335038797627d9448
Change-Id: I9fccda15dd58a0dc35771d3b5cd7a6e8b02514a0
2018-06-11 13:35:41 -07:00
jenkins-bot
cc0fe6c4a7 Merge "Deprecate overriding SearchEngine::search*" 2018-05-16 13:31:56 +00:00
jenkins-bot
bbe9917203 Merge "Make internal search methods private for db implementations" 2018-05-15 20:09:59 +00:00
Erik Bernhardson
fdc133ef1a Deprecate overriding SearchEngine::search*
The plan is to convert these methods into final, considering
it a removal under the deprecation policy. By making entry
points into the search engine final we provide a guaranteed
point where generic handling can be applied to all search engines.

The first use case for this generic handling is pushing pagination
via overfetch into the SearchEngine class instead of re-implementing
an overfetch in individual parts of the code that perform searches.

Change-Id: I3426d6a2f32d8b368b044b154e1cb70dac007c62
2018-05-15 08:28:28 -07:00
David Causse
39cbbab021 Allow 'all:' on all wikis in addition to 'searchall' translation
This allows to have a common syntax useable everywhere.

Bug: T165110
Change-Id: If71fe5df045fb754925946088f8f793197bc8301
2018-05-11 15:20:27 +02:00
David Causse
0824579606 Make internal search methods private for db implementations
Change-Id: I622f1b35e27de7918e32c4ddd74ceb4e257c5b02
2018-05-09 11:56:27 +02:00
runntb
b033d3dc34 search: Add result ranking in MySQL
MySQL normally attempts to rank the results when performing a full-
text search. However, this behavior is disabled when using BOOLEAN
MODE. While BOOLEAN MODE is needed in the WHERE clause, the default
NATURAL LANGUAGE MODE can be used in an ORDER BY clause to reenable
ranking.

Bug: T192458
Change-Id: I09462c339432927efead58fb543a10aed2c53195
2018-05-01 17:00:53 -04:00
James D. Forrester
5f018dd6a4 Drop OpenSearch::getOpenSearchTemplate(), deprecated in 1.25
Change-Id: Ib76b96cf392b7f9fa38d28173dd2cd170e08a881
2018-03-08 10:43:28 +00:00
Reedy
39f0f919c5 Update suppressWarning()/restoreWarning() calls
Bug: T182273
Change-Id: I9e1b628fe5949ca54258424c2e45b2fb6d491d0f
2018-02-10 08:50:12 +00:00
Umherirrender
3124a990a2 Use ::class to resolve class names in includes files
This helps to find renamed or misspelled classes earlier.
Phan will check the class names

Change-Id: I07a925c2a9404b0865e8a8703864ded9d14aa769
2018-01-27 20:34:29 +01:00
Stanislav Malyshev
030da07b18 Use getSize since SearchSuggestionSet does not implement Countable
Bug: T184934
Change-Id: I39459352399e2023149b715b049084826df22935
2018-01-22 12:13:34 -08:00
jenkins-bot
a18476eab3 Merge "Remove @param comments that literally repeat what the code says" 2018-01-11 23:48:03 +00:00
Thiemo Mättig
ef470ebf7f Remove @param comments that literally repeat what the code says
These comments do not add anything. I argue they are worse than having
no comments, because I have to read them first to understand they
actually don't explain anything. Removing them makes room for actual
improvements in the future (if needed).

Change-Id: Iee70aad681b3385e9af282d5581c10addbb91ac4
2018-01-10 14:14:26 +01:00
Thiemo Mättig
fa15c98787 Improve (weak and strict) type hints invarious places
Change-Id: I3a42ec1547fae971d7b495c99dd144739d8521ab
2017-12-28 16:31:56 +01:00
Huji Lee
e74bfe13f6 Require indentation of CASE statements in PHP code
Bug: T182546
Change-Id: I91a9555893a08e4ec58da97c6cc4d1e70000ff6b
2017-12-10 22:07:50 -05:00
jenkins-bot
03cd9495a4 Merge "Fix a few minor mistakes in PHPDoc tags" 2017-09-15 19:18:17 +00:00
Thiemo Mättig
7301b2514e Fix a few minor mistakes in PHPDoc tags
Change-Id: I2d5f876c9945ba21f8748562230170e3c7ea2ff2
2017-09-15 11:17:17 +02:00
Umherirrender
f739a8f368 Improve some parameter docs
Add missing @return and @param to function docs and fixed some @param

Change-Id: I810727961057cfdcc274428b239af5975c57468d
2017-09-10 20:32:31 +02:00
Umherirrender
9b8b314992 Fix spacing for @param and indent of function comments
In phpcs.xml rename renamed sniffs and add the failing sniffs,
because now the whole sniff is no longer excluded.

Change-Id: If5b0bd16028761abc2c47ace9e97d37ad14bb36f
2017-08-15 14:33:29 +00:00
jenkins-bot
cc4115e87f Merge "Add missing @param and @return documentation" 2017-08-11 21:32:58 +00:00
jenkins-bot
84b6d5c2e5 Merge "Add missing type to @param documentation" 2017-08-11 21:31:51 +00:00
WMDE-Fisch
6df9ed1ad6 update mediawiki-codesniffer to 0.11.0 and fix issues
- mostly auto fixes
- some too long lines fixed
- ignore amp space in one case  passing by reference

Change-Id: I6472f83bc3cbf4bd629d83050cc3319b19ec465c
2017-08-11 22:27:51 +02:00
Umherirrender
718e63694d Add missing @param and @return documentation
Change-Id: I1d1098eec3933df6561cceef646576013ddc08c8
2017-08-11 22:17:01 +02:00
Umherirrender
5544cef16b Add missing type to @param documentation
Change-Id: I6b2c9c7af9a281fe457099cc3a336a60a25e74aa
2017-08-11 20:37:35 +02:00
Umherirrender
ace44e2064 Use correct variable name in @param documentation
For some varargs a variable name is added with suffix ,... as seen for
many other varargs

Some @param are swapped, because there are in the wrong order

Enable Sniff MediaWiki.Commenting.FunctionComment.ParamNameNoMatch

Change-Id: I60fec6025bce824d5c67563ab7b65ad6cd628ad8
2017-08-11 19:27:19 +02:00
Umherirrender
a9007e8baf Add missing & to @param documentation to match functon call
Change-Id: I81e68310abcbc59964b22e0e74842d509f6b1fb9
2017-08-11 18:47:46 +02:00
Umherirrender
bf61a77431 Change @inheritdoc to @inheritDoc
Only @inheritDoc works for the Sniff
MediaWiki.Commenting.FunctionComment

Change-Id: I91fc02cda6701d790e4334fc2bc47f230955545c
2017-08-11 16:49:52 +02:00
jenkins-bot
e72303c9f3 Merge "Remove auto-generated "Constructor" documentation on constructors" 2017-07-21 13:19:44 +00:00
Thiemo Mättig
91a920fd85 Remove auto-generated "Constructor" documentation on constructors
Having such comments is worse than not having them. They add zero
information. But you must read the text to understand there is
nothing you don't already know from the class and the method name.

This is similar to I994d11e. Even more trivial, because this here is
about comments that don't say anything but "constructor".

Change-Id: I474dcdb5997bea3aafd11c0760ee072dfaff124c
2017-07-21 12:19:30 +02:00
jenkins-bot
598a250b71 Merge "Support custom offsets from SearchResultSet" 2017-07-19 10:57:28 +00:00
Erik Bernhardson
7fd6ef9ca5 Support custom offsets from SearchResultSet
Work to support interleaved AB testing of search will display
interleaved results of two search configurations on the first page of
results, but standard results on all pages other than the first page.
This means that while 20 results may be requested, the next 'new' result
of the primary query may be at position 10. Allow the SearchResultSet
to declare what the new offset is.

Bug: T150032
Change-Id: I14c0c33249fcdb66f72f5966e2aa72781a34daee
2017-07-18 21:22:49 -07:00
Thiemo Mättig
d14faa6bed Remove auto-generated "Constructor" documentation on constructors
Having such comments is worse than not having them. They add zero
information. But you must read the text to understand there is
nothing you don't already know from the class and the method name.

Change-Id: I994d11e05f202b880390723e148d79c72cca29f0
2017-07-10 10:15:51 +00:00
jenkins-bot
e0f53bfb8d Merge "Fix phrase search" 2017-07-05 18:35:16 +00:00
David Causse
187ada1cf4 Fix phrase search
Partially revert I61dc536 that broke phrase search support.

Fix phrase search by making explicit that there are two
kind of legalSearchChars() usecases :

- the chars allowed to be part of the search query (including special
  syntax chars such as " and *). Used by SearchDatabase::filter() to
  cleanup the whole query string (the default).

- the chars allowed to be part of a search term (excluding special
  syntax chars) Used by search engine implementaions when parsing with
  a regex.

For future reference:
Originally this distinction was made "explicit" by calling directly
SearchEngine::legalSearchChars() during the parsing stage. This was
broken by Iaabc10c by enabling inheritance.
This patch adds a new optional param to legalSearchChars to make this
more explicit.

Also remove the function I introduced in I61dc536 (I wrongly assumed
that the disctinction made between legalSearchChars usecases was due
to a difference in behavior between indexing and searching).

Added more tests to prevent this from happening in the future.

Bug: T167798
Change-Id: Ibdc796bb2881a2ed8194099d8c9f491980010f0f
2017-07-03 11:44:48 +02:00
Umherirrender
b5cddfb27b Remove empty lines at begin of function, if, foreach, switch
Organize phpcs.xml a bit

Change-Id: Ifb767729b481b4b686e6d6444cf48b1f580cc478
2017-07-01 11:34:16 +00:00
jenkins-bot
0e25b05028 Merge "Add SearchIndexField::getEngineHints()" 2017-06-28 20:37:13 +00:00
jenkins-bot
01c3bf3431 Merge "Fix highlighting for phrase queries" 2017-06-27 23:44:27 +00:00
Umherirrender
be42e09aa8 build: Prepare for mediawiki/mediawiki-codesniffer to 0.9.0
The used phpcs has a bug, so the version 0.9.0 could not be enforced at the moment.
Will be fixed in next version, see T167168

Changed:
- Remove duplicate newline at end of file
- Add space between function and ( for closures
- and -> &&, or -> ||

Change-Id: I4172fb08861729bccd55aecbd07e029e2638d311
2017-06-26 17:14:31 +00:00
David Causse
f230f5dcc7 Fix highlighting for phrase queries
I think the bug was introduced during a cleanup in Iaabc10c.
I don't think that " should be part of the legalSearchChars at query
time, it seems to break the regex.
The strategy here is to distinguish legalSearchChars used query time vs
the ones used at index time by introducing:
SearchEngine::legalSearchCharsForUpdate()

Bug: T167798
Change-Id: I61dc53665e26d3c6c48caed78dd3bbde9a33def7
2017-06-26 09:53:13 +02:00
David Causse
b5aecfabd9 Add SearchIndexField::getEngineHints()
Allows search engine clients that implement custom definitions
to pass engine hints used at index time.
Hints are a way to fine tune the behavior of the search engine
when handling a particular field.
As of now this is introduced for CirrusSearch to let SearchIndexField
implementations to control how the noop script is configured.
The noop hint with CirrusSearch allows to (for example):
- ignore an update if a numeric value does not change for more than X%
- control the merge strategy of complex fields

Bug: T166589
Change-Id: Ia560e41d33013c30ac47e5a60543f8cb133e61fb
2017-06-22 16:03:01 +02:00
Paladox
54c56da85a Fix php code style
Preparation change for updating mediawiki code sniffer to 0.8.0

Change-Id: Ib0b3fe4afea9096ffa3a1347b4f7e07d3398b0b2
2017-05-05 12:03:54 +00:00
Brian Wolff
d4385537bc SECURITY: XSS in search if $wgAdvancedSearchHighlighting = true;
In the non-default configuration where $wgAdvancedSearchHighlighting
is set to true, there is an XSS vulnerability as HTML tags are
not properly escaped if the tag spans multiple search results

Issue introduced in abf726ea0 (MediaWiki 1.13 and above).

Bug: T144845
Change-Id: I2db7888d591b97f1a01bfd3b7567ce6f169874d3
2017-04-06 13:42:44 -07:00
Stanislav Malyshev
1e412aabdf Add deleted archive titles search
Allows search engine to suggest deleted titles for undelete search.
Note that the titles are still verified against the archive table,
to ensure search engine is not out-of-date.

Bug: T109561
Change-Id: Id6099fe9fbf18481068a6f0a329bbde0d218135f
2017-04-05 12:02:35 -07:00
Aaron Schulz
488a647831 Move IDatabase/IMaintainableDatabase to Rdbms namespace
Change-Id: If7e8a8ff574661fd827de8bcec11d2c39a687300
2017-03-28 15:32:38 -07:00
Stanislav Malyshev
cae86036aa Allow fields to define their own merge strategy via callback.
Change-Id: Ic1cc1581f07381224d3f4fcba4feb1eac7085057
2017-03-07 10:36:53 -08:00
Aaron Schulz
e01fd44388 Move ResultWrapper subclasses to Rdbms
Change-Id: I6f3f0e85e268b24c57c537aa6ad8016e0b4cdddb
2017-03-03 00:44:41 +00:00
Bartosz Dziewoński
ecdef925bb Miscellaneous indentation tweaks
I was bored. What? Don't look at me that way.

I mostly targetted mixed tabs and spaces, but others were not spared.
Note that some of the whitespace changes are inside HTML output,
extended regexps or SQL snippets.

Change-Id: Ie206cc946459f6befcfc2d520e35ad3ea3c0f1e0
2017-02-27 19:23:54 +01:00
jenkins-bot
0a2297c406 Merge "Fixes for more robust dealing with content handlers." 2017-01-30 16:06:25 +00:00
David Causse
cc61a14751 Allow SearchEngine users to access features data
Useful in case the client wants to re-evaluate what was set
here, or if the SearchEngine implementation wants to expose
some of its states.
In our case it allows CirrusSearch to inform SpecialSearch
that we prefer to display search results with a new experimental
layout.

Bug: T156299
Change-Id: I7f661c852ef70ea7bc9ae2959f7d6e48776a9877
2017-01-27 15:12:10 +01:00
Stanislav Malyshev
60ffe51c79 Fixes for more robust dealing with content handlers.
Change-Id: I12a02da005f4b2bceaa850bd1f41a90ac4e1754a
2017-01-26 12:20:07 -08:00
Bartosz Dziewoński
0cccd68dc8 Code style: no space after unary minus operator
Searched for /([^\d\w\s\)\]]\s*)- \d/ to find potential issues.
It seems there's no PHPCS check for this, huh.

Also fixed typo in a comment in LoginSignupSpecialPage.

Change-Id: Iaab1a1f5a9f234971e550e7909aa5c3e0c02a983
2017-01-05 14:38:32 +01:00
Max Semenik
d4f3e554d7 Decrease the number of 'function says it should return something' errors
Change-Id: Ib5115fe5bbaa67d8a6e54cc3ba1ba7020e239e11
2016-12-15 16:05:52 -08:00
Erik Bernhardson
41f9c933b3 Fix two instances of calling function with too few args
At one point SearchIndexFieldDefinition was updated to require the
engine to be passed in, but it seems that update was missed here.

BackupDumper::loadPlugin() requires the second argument, set it to
the empty string to keep current behaviour.

Change-Id: Ifbd8fc4870ff63b2d338f8bb4d251d7a3477b989
2016-12-15 13:24:40 -08:00
Thiemo Mättig
00c3f09566 Remove empty lines from PHP and JavaScript comment blocks
This is a pure documentation change. It mostly removes empty lines from
comments (and entirely empty comments), as well as adds a few missing
documentation blocks and fixes a minor mistake. I hope it's ok to have
this in one patch. I can split it, please tell me.

Change-Id: I9668338602ac77b903ab6b02ff56bd52743c37c4
2016-12-09 09:01:06 +00:00
umherirrender
34fe90ac52 Remove empty lines at end of functions
It looks like there is something missing after the last statement
Also remove some other empty lines at begin of functions, ifs or loops
while at these files

Change-Id: Ib00b5cfd31ca4dcd0c32ce33754d3c80bae70641
2016-11-05 11:55:10 +01:00
dcausse
bd7df68603 Do not run exact db match if offset is > 0
When scrolling results on prefix search api the exact Title
match is always at pos 0 even if we want to scroll the results
by setting offset to > 0.

Change-Id: Ib02c9d3e479d739e6fe79014d962db50b6fd9de8
2016-09-27 15:28:14 +02:00
dcausse
5417b6edc7 Add new type SearchIndexField::INDEX_TYPE_SHORT_TEXT
Useful for short technical strings such as mime types.

Change-Id: If440378f2b7004abed87eca4bbde767212c4b062
2016-09-26 12:50:23 +02:00
jenkins-bot
82dcfbe20e Merge "Pass User to SearchEngine::getProfiles" 2016-09-20 20:30:36 +00:00
dcausse
16e2491a73 Pass User to SearchEngine::getProfiles
Useful for search engines that allow users to customize search profiles.

Depends-On: Icd577c8ebc6e162befe30bde4fe276e633d2e434
Change-Id: I471cd090730d2a25cb70d622ec3bebbe9583118c
2016-09-20 20:22:23 +00:00