Skip to content

Commit

Permalink
Merge pull request #2920 from romainruaud/fix_mlt-query
Browse files Browse the repository at this point in the history
Improve MLT query.
  • Loading branch information
romainruaud authored Apr 25, 2023
2 parents 618fc32 + ae6cfde commit 1d350b2
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public function buildQuery(QueryInterface $query)
'min_doc_freq' => $query->getMinDocFreq(),
'max_doc_freq' => $query->getMaxDocFreq(),
'max_query_terms' => $query->getMaxQueryTerms(),
'min_word_length' => $query->getMinWordLength(),
'max_word_length' => $query->getMaxWordLength(),
'include' => $query->includeOriginalDocs(),
];

Expand Down
56 changes: 51 additions & 5 deletions src/module-elasticsuite-core/Search/Request/Query/MoreLikeThis.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,17 @@ class MoreLikeThis implements QueryInterface
/**
* @var integer
*/
const DEFAULT_MAX_DOC_FREQ = 100;
const DEFAULT_MAX_DOC_FREQ = 2147483647;

/**
* @var integer
*/
const DEFAULT_MIN_WORD_LENGTH = 0;

/**
* @var integer
*/
const DEFAULT_MAX_WORD_LENGTH = 0;

/**
* @var string
Expand Down Expand Up @@ -100,6 +110,16 @@ class MoreLikeThis implements QueryInterface
*/
private $maxDocFreq;

/**
* @var integer
*/
private $minWordLength;

/**
* @var integer
*/
private $maxWordLength;

/**
* @var integer
*/
Expand All @@ -124,6 +144,8 @@ class MoreLikeThis implements QueryInterface
* @param integer $minDocFreq Minimum doc freq for a term to be considered.
* @param integer $maxDocFreq Maximum doc freq for a term to be considered.
* @param integer $maxQueryTerms Maximum number of term in generated queries.
* @param integer $minWordLength Minimum length of word to consider.
* @param integer $maxWordLength Maximum length of word to consider.
* @param integer $includeOriginalDocs Include original doc in the result set.
* @param string $name Query name.
* @param integer $boost Query boost.
Expand All @@ -137,6 +159,8 @@ public function __construct(
$minDocFreq = self::DEFAULT_MIN_DOC_FREQ,
$maxDocFreq = self::DEFAULT_MAX_DOC_FREQ,
$maxQueryTerms = self::DEFAULT_MAX_QUERY_TERMS,
$minWordLength = self::DEFAULT_MIN_WORD_LENGTH,
$maxWordLength = self::DEFAULT_MAX_WORD_LENGTH,
$includeOriginalDocs = false,
$name = null,
$boost = QueryInterface::DEFAULT_BOOST_VALUE
Expand All @@ -152,6 +176,8 @@ public function __construct(
$this->name = $name;
$this->boost = $boost;
$this->includeOriginalDocs = $includeOriginalDocs;
$this->minWordLength = $minWordLength;
$this->maxWordLength = $maxWordLength;
}

/**
Expand Down Expand Up @@ -225,7 +251,7 @@ public function getBoostTerms()
*/
public function getMinTermFreq()
{
return $this->minTermFreq;
return (int) $this->minTermFreq;
}

/**
Expand All @@ -235,7 +261,7 @@ public function getMinTermFreq()
*/
public function getMinDocFreq()
{
return $this->minDocFreq;
return (int) $this->minDocFreq;
}

/**
Expand All @@ -245,7 +271,7 @@ public function getMinDocFreq()
*/
public function getMaxDocFreq()
{
return $this->maxDocFreq;
return (int) $this->maxDocFreq;
}

/**
Expand All @@ -255,7 +281,7 @@ public function getMaxDocFreq()
*/
public function getMaxQueryTerms()
{
return $this->maxQueryTerms;
return (int) $this->maxQueryTerms;
}

/**
Expand All @@ -267,4 +293,24 @@ public function includeOriginalDocs()
{
return $this->includeOriginalDocs;
}

/**
* Minimum doc freq for a term to be considered.
*
* @return integer
*/
public function getMinWordLength()
{
return (int) $this->minWordLength;
}

/**
* Maximum doc freq for a term to be considered.
*
* @return integer
*/
public function getMaxWordLength()
{
return (int) $this->maxWordLength;
}
}

0 comments on commit 1d350b2

Please sign in to comment.