Version 5.0.13
This commit is contained in:
1 parent
b89858b2ff
commit
5efe744c5f
1407 files changed
+69690
-30177
No files matched your search
@@ -103,6 +103,7 @@ class Index extends SearchIndex
|
||||
'settings' => $settings,
|
||||
'mappings' => array(
|
||||
'properties' => array(
|
||||
'index_id' => array( 'type' => 'keyword' ),
|
||||
'index_class' => array( 'type' => 'keyword' ),
|
||||
'index_object_id' => array( 'type' => 'long' ),
|
||||
'index_item_id' => array( 'type' => 'long' ),
|
||||
@@ -205,6 +206,8 @@ class Index extends SearchIndex
|
||||
{
|
||||
if ( $indexData = $this->indexData( $object ) )
|
||||
{
|
||||
$indexData['index_id'] = $this->getIndexId( $object );
|
||||
|
||||
/* If nobody has permission to access it, just remove it */
|
||||
if ( !$indexData['index_permissions'] )
|
||||
{
|
||||
|
||||
@@ -44,6 +44,8 @@ class MassIndexer extends Index
|
||||
{
|
||||
if ( $indexData = $this->indexData( $object ) and $indexData['index_permissions'] )
|
||||
{
|
||||
$indexData['index_id'] = $this->getIndexId( $object );
|
||||
|
||||
if ( $object instanceof Item )
|
||||
{
|
||||
$parent = $object;
|
||||
|
||||
@@ -25,8 +25,10 @@ use IPS\IPS;
|
||||
use IPS\Log;
|
||||
use IPS\Member;
|
||||
use IPS\Member\Club;
|
||||
use IPS\Node\Grouping;
|
||||
use IPS\Settings;
|
||||
use StdClass;
|
||||
use function array_pop;
|
||||
use function count;
|
||||
use function defined;
|
||||
use function in_array;
|
||||
@@ -79,6 +81,11 @@ class Query extends SearchQuery
|
||||
*/
|
||||
protected array|null $itemClasses = NULL;
|
||||
|
||||
/**
|
||||
* @brief If true, just fetch the title record, or the first comment if a post, etc
|
||||
*/
|
||||
protected bool $getTitleRecordOnly = false;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
@@ -133,6 +140,19 @@ class Query extends SearchQuery
|
||||
{
|
||||
if ( $filter->containerIdFilter )
|
||||
{
|
||||
if ( $filter->containerIds )
|
||||
{
|
||||
if ( $filter->itemClass )
|
||||
{
|
||||
$itemClass = $filter->itemClass;
|
||||
if ( isset( $itemClass::$containerNodeClass ) )
|
||||
{
|
||||
$containerClass = $itemClass::$containerNodeClass;
|
||||
$filter->containerIds = $containerClass::normalizeIds( $filter->containerIds );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$conditions[] = array(
|
||||
'terms' => array(
|
||||
'index_container_id' => $filter->containerIds
|
||||
@@ -217,9 +237,7 @@ class Query extends SearchQuery
|
||||
/* Only first comment? */
|
||||
if ( $filter->onlyFirstComment )
|
||||
{
|
||||
$conditions[] = array(
|
||||
'exists' => array( 'field' => 'index_title' )
|
||||
);
|
||||
$this->getTitleRecordOnly = true;
|
||||
}
|
||||
|
||||
/* Only last comment? */
|
||||
@@ -290,7 +308,7 @@ class Query extends SearchQuery
|
||||
/**
|
||||
* Filter by club
|
||||
*
|
||||
* @param Club|int|array|null $club The club, or array of club IDs
|
||||
* @param Club|int|array|null $club The club, or array of club IDs or NULL to exlude content from clubs
|
||||
* @return Query (for daisy chaining)
|
||||
*/
|
||||
public function filterByClub( Club|int|array|null $club ): static
|
||||
@@ -1103,6 +1121,9 @@ class Query extends SearchQuery
|
||||
if ( $method & static::TERM_TITLES_ONLY )
|
||||
{
|
||||
$searchConditions[] = array( 'match_phrase' => array( 'index_title' => array( 'query' => $term ) ) );
|
||||
|
||||
/* Just get the title record only, or the first post if it's a topic as we don't want to show each comment as each comment will have the topic title in the index */
|
||||
$this->getTitleRecordOnly = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1115,6 +1136,9 @@ class Query extends SearchQuery
|
||||
if ( $method & static::TERM_TITLES_ONLY )
|
||||
{
|
||||
$searchConditions[] = array( 'wildcard' => array( 'index_title' => array( 'value' => $term ) ) );
|
||||
|
||||
/* Just get the title record only, or the first post if it's a topic as we don't want to show each comment as each comment will have the topic title in the index */
|
||||
$this->getTitleRecordOnly = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1138,6 +1162,9 @@ class Query extends SearchQuery
|
||||
if ( $method & static::TERM_TITLES_ONLY )
|
||||
{
|
||||
$searchConditions[] = array( 'match' => array( 'index_title' => array( 'query' => $term, 'operator' => $operator ) ) );
|
||||
|
||||
/* Just get the title record only, or the first post if it's a topic as we don't want to show each comment as each comment will have the topic title in the index */
|
||||
$this->getTitleRecordOnly = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1164,7 +1191,7 @@ class Query extends SearchQuery
|
||||
/* If we're not searching with a term, then just show the title record, not comments */
|
||||
if ( $term === NULL and ! $this->lastCommentMustBeTrue )
|
||||
{
|
||||
$must[] = ['exists' => ['field' => 'index_title']];
|
||||
$this->getTitleRecordOnly = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1221,6 +1248,19 @@ class Query extends SearchQuery
|
||||
/* Peform the search */
|
||||
try
|
||||
{
|
||||
/* We only want the main record (of first comment) not the comments themselves, so we check to make sure _id (aka index_id) is the same as index_item_index_id */
|
||||
if ( $this->getTitleRecordOnly )
|
||||
{
|
||||
$filters[] = [
|
||||
'script' => [
|
||||
'script' => [
|
||||
'lang' => 'painless',
|
||||
'source' => "doc['index_item_index_id'] == doc['index_id']"
|
||||
]
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/* Initial query */
|
||||
$query = array(
|
||||
'bool' => array(
|
||||
|
||||
@@ -22,6 +22,7 @@ use IPS\Db\Exception;
|
||||
use IPS\Db\Select;
|
||||
use IPS\Member;
|
||||
use IPS\Member\Club;
|
||||
use IPS\Node\Grouping;
|
||||
use IPS\Settings;
|
||||
use IPS\IPS;
|
||||
use Throwable;
|
||||
@@ -33,6 +34,7 @@ use function in_array;
|
||||
use function intval;
|
||||
use function is_array;
|
||||
use function is_null;
|
||||
use function is_string;
|
||||
use const IPS\CIC;
|
||||
use const IPS\USE_MYSQL_SEARCH_OPTIMIZED_MODE;
|
||||
|
||||
@@ -145,10 +147,23 @@ class Query extends \IPS\Content\Search\Query
|
||||
$clause[] = 'index_class=?';
|
||||
$params[] = array_pop( $filter->classes );
|
||||
}
|
||||
|
||||
|
||||
/* Set the containers */
|
||||
if ( $filter->containerIdFilter !== NULL )
|
||||
{
|
||||
if ( $filter->containerIds )
|
||||
{
|
||||
if ( $filter->itemClass )
|
||||
{
|
||||
$itemClass = $filter->itemClass;
|
||||
if ( isset( $itemClass::$containerNodeClass ) )
|
||||
{
|
||||
$containerClass = $itemClass::$containerNodeClass;
|
||||
$filter->containerIds = $containerClass::normalizeIds( $filter->containerIds );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$clause[] = Db::i()->in( 'index_container_id', $filter->containerIds, $filter->containerIdFilter === FALSE );
|
||||
}
|
||||
|
||||
|
||||
@@ -66,12 +66,19 @@ abstract class Query
|
||||
{
|
||||
if ( Settings::i()->search_method == 'elastic' )
|
||||
{
|
||||
return new Elastic\Query( $member ?: Member::loggedIn(), Url::external( rtrim( Settings::i()->search_elastic_server, '/' ) . '/' . Settings::i()->search_elastic_index ) );
|
||||
$search = new Elastic\Query( $member ?: Member::loggedIn(), Url::external( rtrim( Settings::i()->search_elastic_server, '/' ) . '/' . Settings::i()->search_elastic_index ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return new Mysql\Query( $member ?: Member::loggedIn() );
|
||||
$search = new Mysql\Query( $member ?: Member::loggedIn() );
|
||||
}
|
||||
|
||||
/* Don't include any club content if we have disabled clubs */
|
||||
if( !Settings::i()->clubs )
|
||||
{
|
||||
$search->filterByClub( NULL );
|
||||
}
|
||||
return $search;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,9 +106,10 @@ abstract class Query
|
||||
{
|
||||
$this->setHiddenFilter( static::HIDDEN_VISIBLE );
|
||||
}
|
||||
|
||||
$filters = [];
|
||||
|
||||
/* Exclude disabled applications */
|
||||
$filters = array();
|
||||
foreach( SearchContent::searchableClasses() as $class )
|
||||
{
|
||||
/* We only want items here */
|
||||
|
||||
@@ -161,11 +161,14 @@ class Content extends Result
|
||||
$data = array_pop( $images );
|
||||
$key = key( $data );
|
||||
|
||||
try
|
||||
if( !empty( $data[ $key ] ) )
|
||||
{
|
||||
$enclosure = File::get( $key, $data[ $key ] );
|
||||
try
|
||||
{
|
||||
$enclosure = File::get( $key, $data[ $key ] );
|
||||
}
|
||||
catch( Exception ) { }
|
||||
}
|
||||
catch( Exception ) { }
|
||||
}
|
||||
|
||||
$document->addItem( $object instanceof Comment ? $object->item()->mapped( 'title' ) : $object->mapped( 'title' ), $object->url(), Result::preDisplay( $this->indexData['index_content'] ), DateTime::ts( $this->indexData['index_date_created'] ), NULL, $enclosure );
|
||||
|
||||
@@ -169,7 +169,22 @@ abstract class SearchContentAbstract
|
||||
}
|
||||
|
||||
/* Articles language */
|
||||
$articles = static::articlesFromIndexData( $objectClass, $containerData );
|
||||
if( is_subclass_of( $objectClass, Comment::class ) and
|
||||
(
|
||||
( $itemClass::$firstCommentRequired and $indexData['index_item_index_id'] == $indexData['index_id'] ) or
|
||||
( isset( $itemData['author'] ) )
|
||||
)
|
||||
)
|
||||
{
|
||||
/* If the first comment is required, and this is the first comment, treat it as an item, not a comment.
|
||||
OR.... if we are commenting on someone else's content. */
|
||||
$articles = static::articlesFromIndexData( $itemClass, $containerData );
|
||||
}
|
||||
else
|
||||
{
|
||||
$articles = static::articlesFromIndexData( $objectClass, $containerData );
|
||||
}
|
||||
|
||||
$summaryLanguage = static::searchResultSummaryLanguage( $authorData, $articles, $indexData, $itemData );
|
||||
|
||||
/* Container details */
|
||||
@@ -292,7 +307,7 @@ abstract class SearchContentAbstract
|
||||
{
|
||||
if( $itemClass::$firstCommentRequired )
|
||||
{
|
||||
if( $indexData['index_title'] )
|
||||
if( $indexData['index_item_index_id'] == $indexData['index_id'] )
|
||||
{
|
||||
return Member::loggedIn()->language()->addToStack( "user_own_activity_item", FALSE, array( 'sprintf' => array( $articles['indefinite'] ), 'htmlsprintf' => array( $authorTemplate ) ) );
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user