Version 4.3.6
This commit is contained in:
1 parent
fe1acf984a
commit
1a0c7fd3c2
609 files changed
+14707
-5726
No files matched your search
@@ -906,6 +906,12 @@ class _Query extends \IPS\Content\Search\Query
|
||||
*/
|
||||
public function search( $term = NULL, $tags = NULL, $method = 1, $operator = NULL )
|
||||
{
|
||||
/* If we're looking for more results than we can fetch, we don't need to ask Elastic Search */
|
||||
if( ( $this->offset + $this->resultsToGet ) >= \IPS\Settings::i()->search_index_maxresults )
|
||||
{
|
||||
return new \IPS\Content\Search\Results( array(), 0 );
|
||||
}
|
||||
|
||||
$operator = $operator ?: \IPS\Settings::i()->search_default_operator;
|
||||
$must = array();
|
||||
$filters = $this->filters;
|
||||
@@ -924,11 +930,11 @@ class _Query extends \IPS\Content\Search\Query
|
||||
$term = trim( $term, '"' );
|
||||
if ( $method & static::TERM_TITLES_ONLY )
|
||||
{
|
||||
$searchConditions[] = array( 'match_phrase' => array( 'index_title' => array( 'query' => $term ), 'analyzer' => 'standard' ) );
|
||||
$searchConditions[] = array( 'match_phrase' => array( 'index_title' => array( 'query' => $term ) ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
$searchConditions[] = array( 'multi_match' => array( 'query' => $term, 'fields' => array( 'index_content', $titleField ), 'type' => 'phrase', 'analyzer' => 'standard' ) );
|
||||
$searchConditions[] = array( 'multi_match' => array( 'query' => $term, 'fields' => array( 'index_content', $titleField ), 'type' => 'phrase' ) );
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -995,6 +1001,7 @@ class _Query extends \IPS\Content\Search\Query
|
||||
/* Peform the search */
|
||||
try
|
||||
{
|
||||
/* Initial query */
|
||||
$query = array(
|
||||
'bool' => array(
|
||||
'must' => $must,
|
||||
@@ -1003,6 +1010,7 @@ class _Query extends \IPS\Content\Search\Query
|
||||
)
|
||||
);
|
||||
|
||||
/* Add the time decay */
|
||||
if ( \IPS\Settings::i()->search_decay_factor and !$this->sort )
|
||||
{
|
||||
$query = array(
|
||||
@@ -1017,8 +1025,9 @@ class _Query extends \IPS\Content\Search\Query
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
if ( \IPS\Settings::i()->search_elastic_self_boost and $this->member->member_id )
|
||||
|
||||
/* Add the self boost */
|
||||
if ( \IPS\Settings::i()->search_elastic_self_boost and $this->member->member_id and !$this->sort )
|
||||
{
|
||||
$query = array(
|
||||
'function_score' => array(
|
||||
@@ -1033,25 +1042,37 @@ class _Query extends \IPS\Content\Search\Query
|
||||
);
|
||||
}
|
||||
|
||||
$return = $this->url->setPath( $this->url->data[ \IPS\Http\Url::COMPONENT_PATH ] . '/_search' )->request()->setHeaders( array( 'Content-Type' => 'application/json' ) )->get( json_encode( array(
|
||||
/* Build the JSON and validate it. Use JSON_PARTIAL_OUTPUT_ON_ERROR in case someone has used an unencodable value as
|
||||
the term, and check json_encode() didn't return FALSE (which it may do on error) as a sanity check against
|
||||
sending a blank query, which would return everything in the index */
|
||||
$array = array(
|
||||
'query' => $query,
|
||||
'sort' => $this->sort ?: array(),
|
||||
'from' => $this->offset,
|
||||
'size' => $this->resultsToGet,
|
||||
) ) )->decodeJson();
|
||||
);
|
||||
|
||||
$json = json_encode( $array, JSON_PARTIAL_OUTPUT_ON_ERROR );
|
||||
if ( $json === FALSE )
|
||||
{
|
||||
return new \IPS\Content\Search\Results( array(), 0 );
|
||||
}
|
||||
|
||||
/* Make the call! */
|
||||
$return = $this->url->setPath( $this->url->data[ \IPS\Http\Url::COMPONENT_PATH ] . '/_search' )->request()->setHeaders( array( 'Content-Type' => 'application/json' ) )->get( $json )->decodeJson();
|
||||
if ( isset( $return['error'] ) )
|
||||
{
|
||||
\IPS\Log::log( print_r( $return['error'], TRUE ), 'elasticsearch' );
|
||||
return new \IPS\Content\Search\Results( array(), 0 );
|
||||
}
|
||||
|
||||
|
||||
/* Set results */
|
||||
return new \IPS\Content\Search\Results( array_map( function( $hit ) {
|
||||
$indexData = $hit['_source'];
|
||||
$indexData['index_permissions'] = implode( ',', $indexData['index_permissions'] );
|
||||
$indexData['index_tags'] = $indexData['index_tags'] ? implode( ',', $indexData['index_tags'] ) : NULL;
|
||||
return $indexData;
|
||||
}, $return['hits']['hits'] ), $return['hits']['total'] );
|
||||
}, $return['hits']['hits'] ), $return['hits']['total'] <= \IPS\Settings::i()->search_index_maxresults ? $return['hits']['total'] : (int) \IPS\Settings::i()->search_index_maxresults );
|
||||
}
|
||||
catch ( \Exception $e )
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user