Version 4.7.23

This commit is contained in:
Neo committed 2025-12-19 16:21:27 -08:00
1 parent 7124a02564
commit 25ddeb65d6
1791 files changed
+76990 -44452

No files matched your search

+75 -20
View File
@@ -172,19 +172,19 @@ class _Query extends \IPS\Content\Search\Query
$this->joins[] = array( 'from' => $class::$databaseTable, 'where' => $class::$databaseTable . '.' . $class::$databasePrefix . $class::$databaseColumnId . '=main.index_item_id' );
if ( $filter->minimumComments )
if ( $filter->minimumComments AND isset( $class::$databaseColumnMap['num_comments'] ) )
{
$this->select[ $class::$databaseTable . '_comments' ] = $class::$databaseTable . '.' . $class::$databasePrefix . $class::$databaseColumnMap['num_comments'];
$clause[] = $class::$databaseTable . '.' . $class::$databasePrefix . $class::$databaseColumnMap['num_comments'] . '>=' . \intval( $filter->minimumComments );
}
if ( $filter->minimumReviews )
if ( $filter->minimumReviews AND isset( $class::$databaseColumnMap['num_reviews'] ) )
{
$this->select[ $class::$databaseTable . '_reviews' ] = $class::$databaseTable . '.' . $class::$databasePrefix . $class::$databaseColumnMap['num_reviews'];
$clause[] = $class::$databaseTable . '.' . $class::$databasePrefix . $class::$databaseColumnMap['num_reviews'] . '>=' . \intval( $filter->minimumReviews );
}
if ( $filter->minimumViews )
if ( $filter->minimumViews AND isset( $class::$databaseColumnMap['views'] ) )
{
$this->select[ $class::$databaseTable . '_views' ] = $class::$databaseTable . '.' . $class::$databasePrefix . $class::$databaseColumnMap['views'];
$clause[] = $class::$databaseTable . '.' . $class::$databasePrefix . $class::$databaseColumnMap['views'] . '>=' . \intval( $filter->minimumViews );
@@ -503,21 +503,24 @@ class _Query extends \IPS\Content\Search\Query
else if ( \count( $followed ) )
{
/* IN is not a SIN. It's been a long day */
$where[] = \IPS\Db::i()->in( 'index_author', $followed );
$where[] = \IPS\Db::i()->in( 'index_author', $followed );
}
else
else if ( ! $includeItems and ! $includeContainers )
{
/* There are no results */
/* There are no results, and we only wanted members they followed */
$this->where[] = "1=2 /*Filter by followed returned nothing*/";
}
}
catch( \UnderflowException $ex )
{
/* There are no results */
$this->where[] = "1=2 /*Filter by followed returned nothing*/";
if ( ! $includeItems and ! $includeContainers )
{
/* There are no results and we only wanted members they followed */
$this->where[] = "1=2 /*Filter by followed returned nothing*/";
}
}
}
/* Put it all together */
if ( \count( $where ) )
{
@@ -905,7 +908,7 @@ class _Query extends \IPS\Content\Search\Query
$termWhere = NULL;
/* Do we have tags? */
if ( $tags !== NULL )
if ( \IPS\Settings::i()->tags_enabled AND $tags !== NULL )
{
$itemsOnlyTagSearch = '';
@@ -1001,15 +1004,39 @@ class _Query extends \IPS\Content\Search\Query
}
}
$results = iterator_to_array( \IPS\Db::i()->select( 'index_item_id, index_class', array( 'core_search_index_item_map', 'sub' ), array( array( 'index_author_id=' . \intval( $this->member->member_id ) . ' AND ' . \IPS\Db::i()->in( 'index_class', $classes ) ) ), 'index_item_id desc', array( 0, 501 ) ) );
if ( \count( $results ) )
$results = iterator_to_array( \IPS\Db::i()->select( 'index_item_id, index_class', array( 'core_search_index_item_map', 'sub' ), array( array( 'index_author_id=' . \intval( $this->member->member_id ) . ' AND ' . \IPS\Db::i()->in( 'index_class', $classes ) ) ), 'index_item_id desc', array( 0, 801 ) ) );
if ( \count( $results ) == 801 )
{
/* Assume we have loads of matches, so do a full query */
$subClause = array( array( 'sub.index_item_id=main.index_item_id AND index_author_id=' . \intval( $this->member->member_id ) . ' AND ' . $this->makeEmbeddedIfClauseForSearchMapTable('sub.index_class') ) );
$query = \IPS\Db::i()->select( 'index_item_id', array( 'core_search_index_item_map', 'sub' ), $subClause );
$where[] = array( 'EXISTS(?)', $query );
}
else if ( \count( $results ) )
{
$classIds = array();
foreach( $results as $result )
{
$classIds[ $result['index_class'] ][] = $result['index_item_id'];
}
$subWhere = array();
foreach( $classIds as $class => $ids )
{
$stack = array( $class );
if ( isset( $class::$commentClass ) )
{
$stack[] = $class::$commentClass;
}
$subWhere[] = '(' . \IPS\Db::i()->in( 'index_class', $stack ) . ' and ' . \IPS\Db::i()->in( 'index_item_id', $ids ) . ')';
}
/* IN is not a SIN. It's been a long day */
$where[] = '(' . implode( ' OR ', $subWhere ) . ')';
}
else
{
/* There are no results */
@@ -1264,7 +1291,7 @@ class _Query extends \IPS\Content\Search\Query
/* Set order clause */
$order = $this->order;
/* This forces MySQL to strongly hint a better index to the optimiser for MySQL 5.7+, even though sorting will not be affected */
if ( !\IPS\CIC )
{
@@ -1276,7 +1303,7 @@ class _Query extends \IPS\Content\Search\Query
}
/* If we're filtering by unread, and not using MariaDB, then force an index because MySQL tends to use the incorrect one in this scenario. */
if ( !mb_stristr( \IPS\Db::i()->server_info, '-MariaDB' ) and $this->filterByUnread === TRUE )
if ( !mb_stristr( \IPS\Db::i()->server_info, '-MariaDB' ) and $this->filterByUnread === TRUE and \IPS\Db::i()->server_version < 80000 )
{
$this->forceIndex = 'index_date_updated';
}
@@ -1288,7 +1315,7 @@ class _Query extends \IPS\Content\Search\Query
if ( mb_substr( $this->order, 0, 9 ) === 'calcscore' )
{
/* But we can only do that if there's a term (rather than tag-only) */
if ( $term !== NULL )
if ( static::canUseRelevancy() and $term !== NULL )
{
if ( \IPS\Settings::i()->search_title_boost )
{
@@ -1311,7 +1338,7 @@ class _Query extends \IPS\Content\Search\Query
. ',1.5)' // To the power of 1.5
. ' AS calcscore';
}
/* So if we don't have a term, fallback to last updated */
/* So if we don't have a term ot can't use relevancy, fallback to last updated */
else
{
$order = 'index_date_updated DESC';
@@ -1369,7 +1396,7 @@ class _Query extends \IPS\Content\Search\Query
*/
public function getDefaultDateCutOff()
{
if ( \IPS\USE_MYSQL_SEARCH_BASIC_MODE_THRESHOLD and static::getTableSize() >= \IPS\USE_MYSQL_SEARCH_BASIC_MODE_THRESHOLD )
if ( \IPS\USE_MYSQL_SEARCH_OPTIMIZED_MODE )
{
return 'year';
}
@@ -1384,13 +1411,23 @@ class _Query extends \IPS\Content\Search\Query
*/
public function getDefaultSortMethod()
{
if ( \IPS\USE_MYSQL_SEARCH_BASIC_MODE_THRESHOLD and static::getTableSize() >= \IPS\USE_MYSQL_SEARCH_BASIC_MODE_THRESHOLD )
if ( \IPS\USE_MYSQL_SEARCH_OPTIMIZED_MODE )
{
return 'newest';
}
return parent::getDefaultSortMethod();
}
/**
* Can use relevancy?
*
* @return boolean
*/
public function canUseRelevancy(): bool
{
return ! \IPS\USE_MYSQL_SEARCH_OPTIMIZED_MODE;
}
protected static $tableCount = NULL;
@@ -1403,9 +1440,27 @@ class _Query extends \IPS\Content\Search\Query
{
if ( static::$tableCount === NULL )
{
/* Try and be more efficient */
try
{
if( $result = \IPS\Db::i()->query( "SELECT TABLE_ROWS as _size FROM `information_schema`.`TABLES` WHERE TABLE_SCHEMA = '" . \IPS\Settings::i()->sql_database . "' AND TABLE_NAME='" . \IPS\Db::i()->prefix . "core_search_index'" ) )
{
if( $resultSet = $result->fetch_assoc() )
{
static::$tableCount = (int) $resultSet['_size'];
}
}
}
catch( \Exception $e ) { }
}
/* Did that fail? */
if ( static::$tableCount === NULL )
{
/* Do it the old-fashioned way */
static::$tableCount = \IPS\Db::i()->select( 'COUNT(*)', 'core_search_index' )->first();
}
return static::$tableCount;
}