Version 5.0.13
This commit is contained in:
1 parent
b89858b2ff
commit
5efe744c5f
1407 files changed
+69690
-30177
No files matched your search
@@ -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(
|
||||
|
||||
Reference in new issue
Block a user