Version 4.3.0
This commit is contained in:
1 parent
96997ddd8e
commit
fe1acf984a
1349 files changed
+116159
-67711
No files matched your search
+140
-27
@@ -30,18 +30,53 @@ abstract class _Index extends \IPS\Patterns\Singleton
|
||||
/**
|
||||
* Get instance
|
||||
*
|
||||
* @param bool $skipCache Do not use the cached instance if one exists
|
||||
* @return static
|
||||
*/
|
||||
public static function i()
|
||||
public static function i( $skipCache=FALSE )
|
||||
{
|
||||
if( static::$instance === NULL )
|
||||
if( static::$instance === NULL OR $skipCache === TRUE )
|
||||
{
|
||||
static::$instance = new \IPS\Content\Search\Mysql\Index;
|
||||
if ( \IPS\Settings::i()->search_method == 'elastic' )
|
||||
{
|
||||
static::$instance = new \IPS\Content\Search\Elastic\Index( \IPS\Http\Url::external( \IPS\Settings::i()->search_elastic_server . '/' . \IPS\Settings::i()->search_elastic_index ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
static::$instance = new \IPS\Content\Search\Mysql\Index;
|
||||
}
|
||||
}
|
||||
|
||||
return static::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get mass indexer
|
||||
*
|
||||
* @return static
|
||||
*/
|
||||
public static function massIndexer()
|
||||
{
|
||||
if ( \IPS\Settings::i()->search_method == 'elastic' )
|
||||
{
|
||||
return new \IPS\Content\Search\Elastic\MassIndexer( \IPS\Http\Url::external( \IPS\Settings::i()->search_elastic_server . '/' . \IPS\Settings::i()->search_elastic_index ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
return static::i();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initalize when first setting up
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
// Does nothing by default
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear and rebuild search index
|
||||
*
|
||||
@@ -96,14 +131,14 @@ abstract class _Index extends \IPS\Patterns\Singleton
|
||||
}
|
||||
|
||||
/* Or if this *is* the first comment, add the title and replace the tags */
|
||||
$title = $object->mapped('title');
|
||||
$title = $object->searchIndexTitle();
|
||||
$isForItem = FALSE;
|
||||
if ( $object instanceof \IPS\Content\Comment )
|
||||
{
|
||||
$itemClass = $class::$itemClass;
|
||||
if ( $itemClass::$firstCommentRequired and $object->isFirst() )
|
||||
{
|
||||
$title = $object->item()->mapped('title');
|
||||
$title = $object->item()->searchIndexTitle();
|
||||
$tags = ( $object->item() instanceof \IPS\Content\Tags and \IPS\Settings::i()->tags_enabled ) ? implode( ',', array_filter( $object->item()->tags() ) ) : NULL;
|
||||
$prefix = ( $object->item() instanceof \IPS\Content\Tags and \IPS\Settings::i()->tags_enabled ) ? $object->item()->prefix() : NULL;
|
||||
$isForItem = TRUE;
|
||||
@@ -114,10 +149,29 @@ abstract class _Index extends \IPS\Patterns\Singleton
|
||||
if ( $isForItem )
|
||||
{
|
||||
$dateUpdated = $object->item()->mapped('last_comment');
|
||||
$dateCommented = $object->item()->mapped('last_comment');
|
||||
}
|
||||
else
|
||||
{
|
||||
$dateUpdated = ( $object instanceof \IPS\Content\Item ) ? $object->mapped('last_comment') : $object->mapped('date');
|
||||
$dateUpdated = $object->mapped('date');
|
||||
$dateCommented = $object->mapped('date');
|
||||
if ( $object instanceof \IPS\Content\Item )
|
||||
{
|
||||
foreach ( array( 'last_comment', 'last_review', 'updated' ) as $k )
|
||||
{
|
||||
if ( $val = $object->mapped( $k ) )
|
||||
{
|
||||
if ( $val > $dateUpdated )
|
||||
{
|
||||
$dateUpdated = $val;
|
||||
}
|
||||
if ( $k != 'updated' and $val > $dateCommented )
|
||||
{
|
||||
$dateCommented = $val;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Is the the latest content? */
|
||||
@@ -182,7 +236,7 @@ abstract class _Index extends \IPS\Patterns\Singleton
|
||||
}
|
||||
|
||||
/* Strip spoilers */
|
||||
$content = $object->mapped('content');
|
||||
$content = $object->searchIndexContent();
|
||||
if ( preg_match( '#<div\s+?class=["\']ipsSpoiler["\']#', $content ) )
|
||||
{
|
||||
$content = \IPS\Text\Parser::removeElements( $content, array( 'div[class=ipsSpoiler]' ) );
|
||||
@@ -211,6 +265,12 @@ abstract class _Index extends \IPS\Patterns\Singleton
|
||||
{
|
||||
try
|
||||
{
|
||||
/* If the first comment is required and there is no first comment, this is a broken piece of content - do not try to index */
|
||||
if( !$object->item()->firstComment() )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$itemIndexId = $this->getIndexId( $object->item()->firstComment() );
|
||||
}
|
||||
catch ( \Exception $e ) { }
|
||||
@@ -271,24 +331,27 @@ abstract class _Index extends \IPS\Patterns\Singleton
|
||||
|
||||
/* Return */
|
||||
return array(
|
||||
'index_class' => $class,
|
||||
'index_object_id' => $object->$idColumn,
|
||||
'index_item_id' => ( $object instanceof \IPS\Content\Item ) ? $object->$idColumn : $object->mapped('item'),
|
||||
'index_container_class' => ( $object instanceof \IPS\Content\Item ) ? get_class( $object->searchIndexContainerClass() ) : get_class( $object->item()->searchIndexContainerClass() ),
|
||||
'index_container_id' => ( $object instanceof \IPS\Content\Item ) ? (int) $object->searchIndexContainer() : (int) $object->item()->mapped('container'),
|
||||
'index_title' => $title,
|
||||
'index_content' => $content,
|
||||
'index_permissions' => $object->searchIndexPermissions(),
|
||||
'index_date_created' => intval( $object->mapped('date') ),
|
||||
'index_date_updated' => intval( $dateUpdated ?: $object->mapped('date') ),
|
||||
'index_author' => (int) $object->mapped('author'),
|
||||
'index_tags' => $tags,
|
||||
'index_prefix' => $prefix,
|
||||
'index_hidden' => $hiddenStatus,
|
||||
'index_item_index_id' => $itemIndexId,
|
||||
'index_item_author' => intval( ( $object instanceof \IPS\Content\Item ) ? $object->mapped('author') : $object->item()->mapped('author') ),
|
||||
'index_is_last_comment' => $isLastComment,
|
||||
'index_club_id' => $clubId
|
||||
'index_class' => $class,
|
||||
'index_object_id' => $object->$idColumn,
|
||||
'index_item_id' => ( $object instanceof \IPS\Content\Item ) ? $object->$idColumn : $object->mapped('item'),
|
||||
'index_container_class' => ( $object instanceof \IPS\Content\Item ) ? ( $object->searchIndexContainerClass() ? get_class( $object->searchIndexContainerClass() ) : NULL ) : get_class( $object->item()->searchIndexContainerClass() ),
|
||||
'index_container_id' => ( $object instanceof \IPS\Content\Item ) ? (int) $object->searchIndexContainer() : (int) $object->item()->mapped('container'),
|
||||
'index_title' => $title,
|
||||
'index_content' => $content,
|
||||
'index_permissions' => $object->searchIndexPermissions(),
|
||||
'index_date_created' => intval( $object->mapped('date') ),
|
||||
'index_date_updated' => intval( $dateUpdated ),
|
||||
'index_date_commented' => intval( $dateCommented ),
|
||||
'index_author' => (int) $object->mapped('author'),
|
||||
'index_tags' => $tags,
|
||||
'index_prefix' => $prefix,
|
||||
'index_hidden' => $hiddenStatus,
|
||||
'index_item_index_id' => $itemIndexId,
|
||||
'index_item_author' => intval( ( $object instanceof \IPS\Content\Item ) ? $object->mapped('author') : $object->item()->mapped('author') ),
|
||||
'index_is_last_comment' => $isLastComment,
|
||||
'index_club_id' => $clubId,
|
||||
'index_class_type_id_hash' => md5( $class . ':' . $object->$idColumn )
|
||||
|
||||
);
|
||||
}
|
||||
|
||||
@@ -300,6 +363,19 @@ abstract class _Index extends \IPS\Patterns\Singleton
|
||||
*/
|
||||
abstract public function index( \IPS\Content\Searchable $object );
|
||||
|
||||
/**
|
||||
* Update view count
|
||||
*
|
||||
* @param string $class Class to update
|
||||
* @param int $id ID of item
|
||||
* @param int $count Count to update
|
||||
* @throws \OutOfRangeException When table to update no longer exists
|
||||
*/
|
||||
public function updateViewCounts( $class, $id, $count )
|
||||
{
|
||||
// Do nothing by default
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the search ID for an item
|
||||
*
|
||||
@@ -320,10 +396,11 @@ abstract class _Index extends \IPS\Patterns\Singleton
|
||||
* Removes all content for a classs
|
||||
*
|
||||
* @param string $class The class
|
||||
* @param int|NULL $containerId The container ID to update, or NULL
|
||||
* @param int|NULL $containerId The container ID to delete, or NULL
|
||||
* @param int|NULL $authorId The author ID to delete, or NULL
|
||||
* @return void
|
||||
*/
|
||||
abstract public function removeClassFromSearchIndex( $class, $containerId=NULL );
|
||||
abstract public function removeClassFromSearchIndex( $class, $containerId=NULL, $authorId=NULL );
|
||||
|
||||
/**
|
||||
* Removes all content for a specific application from the index (for example, when uninstalling).
|
||||
@@ -405,4 +482,40 @@ abstract class _Index extends \IPS\Patterns\Singleton
|
||||
* @return void
|
||||
*/
|
||||
abstract public function resetLastComment( $class, $indexItemId );
|
||||
|
||||
/**
|
||||
* Given a list of item index IDs, return the ones that a given member has participated in
|
||||
*
|
||||
* @param array $itemIndexIds Item index IDs
|
||||
* @param \IPS\Member $member The member
|
||||
* @return array
|
||||
*/
|
||||
abstract public function iPostedIn( array $itemIndexIds, \IPS\Member $member );
|
||||
|
||||
/**
|
||||
* Given a list of "index_class_type_id_hash"s, return the ones that a given member has permission to view
|
||||
*
|
||||
* @param array $itemIndexIds Item index IDs
|
||||
* @param \IPS\Member $member The member
|
||||
* @return array
|
||||
*/
|
||||
abstract public function hashesWithPermission( array $hashes, \IPS\Member $member );
|
||||
|
||||
/**
|
||||
* Get timestamp of oldest thing in index
|
||||
*
|
||||
* @return int|null
|
||||
*/
|
||||
abstract public function firstIndexDate();
|
||||
|
||||
/**
|
||||
* Convert terms into stemmed terms for the highlighting JS
|
||||
*
|
||||
* @param array $terms Terms
|
||||
* @return array
|
||||
*/
|
||||
public function stemmedTerms( $terms )
|
||||
{
|
||||
return $terms;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user