mirror of
https://github.com/humhub/humhub.git
synced 2025-01-29 20:38:26 +01:00
parent
d8fc0d251f
commit
d7f72e1182
@ -52,5 +52,3 @@ class Searchable extends Behavior
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
@ -155,13 +155,19 @@ class ZendLuceneSearch extends Search
|
||||
\ZendSearch\Lucene\Search\Query\Wildcard::setMinPrefixLength(0);
|
||||
|
||||
$query = new \ZendSearch\Lucene\Search\Query\Boolean();
|
||||
$emptyQuery = true;
|
||||
foreach (explode(" ", $keyword) as $k) {
|
||||
// Require at least 3 non-wildcard characters
|
||||
if (strlen($k) < $this->minQueryTokenLength) {
|
||||
return null;
|
||||
// Require a minimum of non-wildcard characters
|
||||
if (mb_strlen($k, Yii::$app->charset) >= $this->minQueryTokenLength) {
|
||||
$term = new \ZendSearch\Lucene\Index\Term("*$k*");
|
||||
$query->addSubquery(new \ZendSearch\Lucene\Search\Query\Wildcard($term), true);
|
||||
$emptyQuery = false;
|
||||
}
|
||||
$term = new \ZendSearch\Lucene\Index\Term("*" . $k . "*");
|
||||
$query->addSubquery(new \ZendSearch\Lucene\Search\Query\Wildcard($term), true);
|
||||
}
|
||||
|
||||
// if no keywords or only too short keywords are given, the result is empty.
|
||||
if ($emptyQuery) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Add model filter
|
||||
|
@ -24,5 +24,3 @@ interface Searchable
|
||||
|
||||
public function getSearchAttributes();
|
||||
}
|
||||
|
||||
?>
|
||||
|
@ -8,6 +8,9 @@
|
||||
|
||||
namespace humhub\modules\search\libs;
|
||||
|
||||
use humhub\components\ActiveRecord;
|
||||
use Yii;
|
||||
|
||||
/**
|
||||
* SearchResultSet
|
||||
*
|
||||
@ -36,22 +39,24 @@ class SearchResultSet
|
||||
*/
|
||||
public $pageSize;
|
||||
|
||||
|
||||
/**
|
||||
* Returns active record instances of the search results
|
||||
*
|
||||
* @return \yii\db\ActiveRecord
|
||||
* @return ActiveRecord[]
|
||||
*/
|
||||
public function getResultInstances()
|
||||
{
|
||||
$instances = array();
|
||||
|
||||
foreach ($this->results as $result) {
|
||||
/** @var $modelClass ActiveRecord */
|
||||
$modelClass = $result->model;
|
||||
$instance = $modelClass::findOne(['id' => $result->pk]);
|
||||
if ($instance !== null) {
|
||||
$instances[] = $instance;
|
||||
} else {
|
||||
\Yii::error('Could not load search result ' . $result->model . " - " . $result->pk);
|
||||
Yii::error('Could not load search result ' . $result->model . " - " . $result->pk);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user