CirrusSearch
Elasticsearch-powered search for MediaWiki
Loading...
Searching...
No Matches
CirrusSearch\BuildDocument\Completion\SuggestBuilder Class Reference

Build a doc ready for the titlesuggest index. More...

Public Member Functions

 __construct (SuggestScoringMethod $scoringMethod, array $extraBuilders=[])
 
 build ( $inputDocs, $explain=false)
 
 getRequiredFields ()
 The fields needed to build and score documents.
 
 trimForDistanceCheck ( $input)
 
 extractTitleAndSimilarRedirects (array $doc)
 Extracts title with redirects that are very close.
 
 getBatchId ()
 
 getTargetNamespace ()
 

Static Public Member Functions

static create (Connection $connection, $scoreMethodName=null, $indexBaseName=null)
 
static encodeDocId ( $suggestionType, $docId)
 Encode the suggestion doc id.
 
static encodePossibleDocIds ( $docId)
 Encode possible docIds used by the completion suggester index.
 

Public Attributes

const MAX_INPUT_LENGTH = 50
 We limit the input to 50 chars the search requests It'll be used when searching to trim the input query and when determining close redirects.
 
const REDIRECT_DISCOUNT = 0.1
 Discount suggestions based on redirects.
 
const CROSSNS_DISCOUNT = 0.005
 Discount suggestions based on cross namespace redirects.
 
const REDIRECT_SUGGESTION = 'r'
 Redirect suggestion type.
 
const TITLE_SUGGESTION = 't'
 Title suggestion type.
 

Detailed Description

Build a doc ready for the titlesuggest index.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. http://www.gnu.org/copyleft/gpl.html Builder used to create suggester docs NOTE: Experimental

Constructor & Destructor Documentation

◆ __construct()

CirrusSearch\BuildDocument\Completion\SuggestBuilder::__construct ( SuggestScoringMethod $scoringMethod,
array $extraBuilders = [] )
Parameters
SuggestScoringMethod$scoringMethodthe scoring function to use
ExtraSuggestionsBuilder[]$extraBuildersset of extra builders

Member Function Documentation

◆ build()

CirrusSearch\BuildDocument\Completion\SuggestBuilder::build ( $inputDocs,
$explain = false )
Parameters
array[]$inputDocsa batch of docs to build
bool$explain
Returns
\Elastica\Document[] a set of suggest documents

◆ create()

static CirrusSearch\BuildDocument\Completion\SuggestBuilder::create ( Connection $connection,
$scoreMethodName = null,
$indexBaseName = null )
static
Parameters
Connection$connection
string | null$scoreMethodName
string | null$indexBaseName
Returns
SuggestBuilder
Exceptions

Exception

◆ encodeDocId()

static CirrusSearch\BuildDocument\Completion\SuggestBuilder::encodeDocId ( $suggestionType,
$docId )
static

Encode the suggestion doc id.

Parameters
string$suggestionType
string$docId
Returns
string

◆ encodePossibleDocIds()

static CirrusSearch\BuildDocument\Completion\SuggestBuilder::encodePossibleDocIds ( $docId)
static

Encode possible docIds used by the completion suggester index.

Parameters
string$docId
Returns
string[] list of docIds

◆ extractTitleAndSimilarRedirects()

CirrusSearch\BuildDocument\Completion\SuggestBuilder::extractTitleAndSimilarRedirects ( array $doc)

Extracts title with redirects that are very close.

It will allow to make one suggestion with title as the output and title + similar redirects as the inputs. It can be useful to avoid displaying redirects created to to handle typos.

e.g. : title: Giraffe redirects: Girafe, Girraffe, Mating Giraffes will output

  • 'group' : { 'text': 'Giraffe', 'variants': ['Girafe', 'Girraffe'] }
  • 'candidates' : ['Mating Giraffes']

It would be nice to do this for redirects but we have no way to decide which redirect is a typo and this technique would simply take the first redirect in the list.

Parameters
array$doc
Returns
array mixed 'group' key contains the group with the lead and its variants and 'candidates' contains the remaining candidates that were not close enough to $groupHead.

◆ getBatchId()

CirrusSearch\BuildDocument\Completion\SuggestBuilder::getBatchId ( )
Returns
int the batchId

◆ getRequiredFields()

CirrusSearch\BuildDocument\Completion\SuggestBuilder::getRequiredFields ( )

The fields needed to build and score documents.

Returns
string[] the list of fields

◆ getTargetNamespace()

CirrusSearch\BuildDocument\Completion\SuggestBuilder::getTargetNamespace ( )
Returns
int the target namespace

◆ trimForDistanceCheck()

CirrusSearch\BuildDocument\Completion\SuggestBuilder::trimForDistanceCheck ( $input)
Parameters
string$inputA page title
Returns
string A page title short enough to not cause indexing issues.

The documentation for this class was generated from the following file: