Author: pb
Date: Sun Feb 15 16:56:57 2009
New Revision: 3580
Log:
- fixed bug #014253: problem with limitation, and also added visibility
parameter
Modified:
ezfind/ezp4/trunk/extension/ezfind/classes/ezfezpsolrquerybuilder.php
ezfind/ezp4/trunk/extension/ezfind/classes/ezfmodulefunctioncollection.php
ezfind/ezp4/trunk/extension/ezfind/doc/changelogs/2.0/unstable/CHANGELOG-2.0.0alpha1-to-2.0.0beta1
ezfind/ezp4/trunk/extension/ezfind/modules/ezfind/function_definition.php
Modified: ezfind/ezp4/trunk/extension/ezfind/classes/ezfezpsolrquerybuilder.php
==============================================================================
--- ezfind/ezp4/trunk/extension/ezfind/classes/ezfezpsolrquerybuilder.php (original)
+++ ezfind/ezp4/trunk/extension/ezfind/classes/ezfezpsolrquerybuilder.php Sun Feb 15 16:56:57 2009
@@ -110,12 +110,17 @@
$asObjects = isset( $params['AsObjects'] ) && $params['AsObjects'] ? $params['AsObjects'] : true;
$spellCheck = isset( $params['SpellCheck'] ) && $params['SpellCheck'] > 0 ? $params['SpellCheck'] : array();
$queryHandler = isset( $params['QueryHandler'] ) ? $params['QueryHandler'] : self::$FindINI->variable( 'SearchHandler', 'DefaultSearchHandler' );
+ $ignoreVisibilty = isset( $params['IgnoreVisibility'] ) ? $params['IgnoreVisibility'] : false;
+ $limitation = isset( $params['Limitation'] ) ? $params['Limitation'] : null;
// check if filter parameter is indeed an array, and set it otherwise
if ( ! is_array( $params['Filter'] ) )
{
$params['Filter'] = array( $params['Filter'] );
}
+
+
+
$filterQuery = array();
// Add subtree query filter
@@ -131,7 +136,7 @@
}
// Add policy limitation query filter
- $policyLimitationFilterQuery = $this->policyLimitationFilterQuery();
+ $policyLimitationFilterQuery = $this->policyLimitationFilterQuery( $limitation, $ignoreVisibility );
if ( $policyLimitationFilterQuery !== false )
{
$filterQuery[] = $policyLimitationFilterQuery;
@@ -944,115 +949,130 @@
/**
* Create policy limitation query.
*
+ * @param $limitation array in the same format as $accessResult['policies']
+ * @param $ignoreVisibility boolean
* @return string Lucene/Solr query string which can be used as filter query for Solr
*/
- protected function policyLimitationFilterQuery()
- {
- $currentUser = eZUser::currentUser();
- $accessResult = $currentUser->hasAccessTo( 'content', 'read' );
-
+ protected function policyLimitationFilterQuery( $limitation = null, $ignoreVisibility = false )
+ {
$filterQuery = false;
-
+ if ( is_array( $limitation ) && ( count( $limitation ) == 0 ) )
+ {
+ return $filterQuery;
+ }
+ elseif ( is_array( $limitation ) && ( count( $limitation ) > 0 ) )
+ {
+ $policies = $limitation;
+ }
+ else
+ {
+ $currentUser = eZUser::currentUser();
+ $accessResult = $currentUser->hasAccessTo( 'content', 'read' );
+ if ( !in_array( $accessResult['accessWord'], array( 'yes', 'no' ) ) )
+ {
+ $policies = $accessResult['policies'];
+ }
+ }
+
+
// Add limitations for filter query based on local permissions.
- if ( !in_array( $accessResult['accessWord'], array( 'yes', 'no' ) ) )
- {
- $policies = $accessResult['policies'];
-
- $limitationHash = array(
- 'Class' => eZSolr::getMetaFieldName( 'contentclass_id' ),
- 'Section' => eZSolr::getMetaFieldName( 'section_id' ),
- 'User_Section' => eZSolr::getMetaFieldName( 'section_id' ),
- 'Subtree' => eZSolr::getMetaFieldName( 'path_string' ),
- 'User_Subtree' => eZSolr::getMetaFieldName( 'path_string' ),
- 'Node' => eZSolr::getMetaFieldName( 'main_node_id' ),
- 'Owner' => eZSolr::getMetaFieldName( 'owner_id' ),
- 'Group' => eZSolr::getMetaFieldName( 'owner_group_id' ) );
-
- $filterQueryPolicies = array();
-
- // policies are concatenated with OR
- foreach ( $policies as $limitationList )
- {
- // policy limitations are concatenated with AND
- $filterQueryPolicyLimitations = array();
-
- foreach ( $limitationList as $limitationType => $limitationValues )
- {
- // limitation values of one type in a policy are concatenated with OR
- $filterQueryPolicyLimitationParts = array();
-
- switch ( $limitationType )
- {
- case 'User_Subtree':
- case 'Subtree':
+
+
+ $limitationHash = array(
+ 'Class' => eZSolr::getMetaFieldName( 'contentclass_id' ),
+ 'Section' => eZSolr::getMetaFieldName( 'section_id' ),
+ 'User_Section' => eZSolr::getMetaFieldName( 'section_id' ),
+ 'Subtree' => eZSolr::getMetaFieldName( 'path_string' ),
+ 'User_Subtree' => eZSolr::getMetaFieldName( 'path_string' ),
+ 'Node' => eZSolr::getMetaFieldName( 'main_node_id' ),
+ 'Owner' => eZSolr::getMetaFieldName( 'owner_id' ),
+ 'Group' => eZSolr::getMetaFieldName( 'owner_group_id' ) );
+
+ $filterQueryPolicies = array();
+
+ // policies are concatenated with OR
+ foreach ( $policies as $limitationList )
+ {
+ // policy limitations are concatenated with AND
+ $filterQueryPolicyLimitations = array();
+
+ foreach ( $limitationList as $limitationType => $limitationValues )
+ {
+ // limitation values of one type in a policy are concatenated with OR
+ $filterQueryPolicyLimitationParts = array();
+
+ switch ( $limitationType )
+ {
+ case 'User_Subtree':
+ case 'Subtree':
+ {
+ foreach ( $limitationValues as $limitationValue )
{
- foreach ( $limitationValues as $limitationValue )
- {
- $pathString = trim( $limitationValue, '/' );
- $pathArray = explode( '/', $pathString );
- // we only take the last node ID in the path identification string
- $subtreeNodeID = array_pop( $pathArray );
- $filterQueryPolicyLimitationParts[] = eZSolr::getMetaFieldName( 'path' ) . ':' . $subtreeNodeID;
- }
- } break;
-
- case 'Node':
+ $pathString = trim( $limitationValue, '/' );
+ $pathArray = explode( '/', $pathString );
+ // we only take the last node ID in the path identification string
+ $subtreeNodeID = array_pop( $pathArray );
+ $filterQueryPolicyLimitationParts[] = eZSolr::getMetaFieldName( 'path' ) . ':' . $subtreeNodeID;
+ }
+ } break;
+
+ case 'Node':
+ {
+ foreach ( $limitationValues as $limitationValue )
{
- foreach ( $limitationValues as $limitationValue )
- {
- $pathString = trim( $limitationValue, '/' );
- $pathArray = explode( '/', $pathString );
- // we only take the last node ID in the path identification string
- $nodeID = array_pop( $pathArray );
- $filterQueryPolicyLimitationParts[] = $limitationHash[$limitationType] . ':' . $nodeID;
- }
- } break;
-
- case 'Group':
+ $pathString = trim( $limitationValue, '/' );
+ $pathArray = explode( '/', $pathString );
+ // we only take the last node ID in the path identification string
+ $nodeID = array_pop( $pathArray );
+ $filterQueryPolicyLimitationParts[] = $limitationHash[$limitationType] . ':' . $nodeID;
+ }
+ } break;
+
+ case 'Group':
+ {
+ foreach( eZUser::currentUser()->attribute( 'contentobject' )->attribute( 'parent_nodes' ) as $groupID )
{
- foreach( eZUser::currentUser()->attribute( 'contentobject' )->attribute( 'parent_nodes' ) as $groupID )
- {
- $filterQueryPolicyLimitationParts[] = $limitationHash[$limitationType] . ':' . $groupID;
- }
- } break;
-
- case 'Owner':
+ $filterQueryPolicyLimitationParts[] = $limitationHash[$limitationType] . ':' . $groupID;
+ }
+ } break;
+
+ case 'Owner':
+ {
+ $filterQueryPolicyLimitationParts[] = $limitationHash[$limitationType] . ':' . $currentUser->attribute ( 'contentobject_id' );
+ } break;
+
+ case 'Class':
+ case 'Section':
+ case 'User_Section':
+ {
+ foreach ( $limitationValues as $limitationValue )
{
- $filterQueryPolicyLimitationParts[] = $limitationHash[$limitationType] . ':' . $currentUser->attribute ( 'contentobject_id' );
- } break;
-
- case 'Class':
- case 'Section':
- case 'User_Section':
- {
- foreach ( $limitationValues as $limitationValue )
- {
- $filterQueryPolicyLimitationParts[] = $limitationHash[$limitationType] . ':' . $limitationValue;
- }
- } break;
-
- default :
- {
- eZDebug::writeDebug( $limitationType,
- 'ezfeZPSolrQueryBuilder::policyLimitationFilterQuery unknown limitation type: ' . $limitationType );
- continue;
+ $filterQueryPolicyLimitationParts[] = $limitationHash[$limitationType] . ':' . $limitationValue;
}
+ } break;
+
+ default :
+ {
+ eZDebug::writeDebug( $limitationType,
+ 'ezfeZPSolrQueryBuilder::policyLimitationFilterQuery unknown limitation type: ' . $limitationType );
+ continue;
}
-
- $filterQueryPolicyLimitations[] = '( ' . implode( ' OR ', $filterQueryPolicyLimitationParts ) . ' )';
- }
-
- if ( count( $filterQueryPolicyLimitations ) > 0 )
- {
- $filterQueryPolicies[] = '( ' . implode( ' AND ', $filterQueryPolicyLimitations ) . ')';
- }
- }
-
- if ( count( $filterQueryPolicies ) > 0 )
- {
- $filterQuery = implode( ' OR ', $filterQueryPolicies );
- }
- }
+ }
+
+ $filterQueryPolicyLimitations[] = '( ' . implode( ' OR ', $filterQueryPolicyLimitationParts ) . ' )';
+ }
+
+ if ( count( $filterQueryPolicyLimitations ) > 0 )
+ {
+ $filterQueryPolicies[] = '( ' . implode( ' AND ', $filterQueryPolicyLimitations ) . ')';
+ }
+ }
+
+ if ( count( $filterQueryPolicies ) > 0 )
+ {
+ $filterQuery = implode( ' OR ', $filterQueryPolicies );
+ }
+
// Add limitations for allowing search of other installations.
$anonymousPart = '';
@@ -1079,7 +1099,7 @@
}
// Add visibility condition
- if ( !eZContentObjectTreeNode::showInvisibleNodes() )
+ if ( !eZContentObjectTreeNode::showInvisibleNodes() || !$ignoreVisibility )
{
$filterQuery .= ' AND ' . eZSolr::getMetaFieldName( 'is_invisible' ) . ':false';
}
Modified: ezfind/ezp4/trunk/extension/ezfind/classes/ezfmodulefunctioncollection.php
==============================================================================
--- ezfind/ezp4/trunk/extension/ezfind/classes/ezfmodulefunctioncollection.php (original)
+++ ezfind/ezp4/trunk/extension/ezfind/classes/ezfmodulefunctioncollection.php Sun Feb 15 16:56:57 2009
@@ -103,7 +103,8 @@
*/
public function search( $query, $offset = 0, $limit = 10, $facets = null,
$filters = null, $sortBy = null, $classID = null, $sectionID = null,
- $subtreeArray = null, $asObjects = true, $spellCheck = null, $queryHandler = 'ezpublish' )
+ $subtreeArray = null, $ignoreVisibility = false, $limitation = null,
+ $asObjects = true, $spellCheck = null, $queryHandler = 'ezpublish' )
{
$solrSearch = new eZSolr();
$params = array( 'SearchOffset' => $offset,
@@ -114,6 +115,8 @@
'SearchContentClassID' => $classID,
'SearchSectionID' => $sectionID,
'SearchSubTreeArray' => $subtreeArray,
+ 'IgnoreVisibility' => $ignoreVisibility,
+ 'Limitation' => $limitation,
'AsObjects' => $asObjects,
'SpellCheck' => $spellCheck,
'QueryHandler' => $queryHandler );
@@ -139,6 +142,7 @@
* moreLikeThis function
* @todo document the solrconfig.xml required setting for remote streaming to be true
* if $queryType 'url' is to be used
+ * @todo consider adding limitation and visibility parameters
*
* @param string $queryType string ('nid' | 'oid' | 'text' | 'url' )
* @param string $query value for QueryType
Modified: ezfind/ezp4/trunk/extension/ezfind/doc/changelogs/2.0/unstable/CHANGELOG-2.0.0alpha1-to-2.0.0beta1
==============================================================================
--- ezfind/ezp4/trunk/extension/ezfind/doc/changelogs/2.0/unstable/CHANGELOG-2.0.0alpha1-to-2.0.0beta1 (original)
+++ ezfind/ezp4/trunk/extension/ezfind/doc/changelogs/2.0/unstable/CHANGELOG-2.0.0alpha1-to-2.0.0beta1 Sun Feb 15 16:56:57 2009
@@ -26,3 +26,4 @@
- corrected bug #014435: Allow for RANGE queries (quotes were added, creating an invalid expression for range queries)
- corrected bug #014472 Typos, in "more like this" filter and facet parameters
- corrected bug #014068: Filter definition must be an array in ezfind fetch, although documentation seems to allow string definition
+- fixed bug #014253: problem with limitation (and also added visibility parameter)
Modified: ezfind/ezp4/trunk/extension/ezfind/modules/ezfind/function_definition.php
==============================================================================
--- ezfind/ezp4/trunk/extension/ezfind/modules/ezfind/function_definition.php (original)
+++ ezfind/ezp4/trunk/extension/ezfind/modules/ezfind/function_definition.php Sun Feb 15 16:56:57 2009
@@ -69,6 +69,14 @@
'required' => false,
'default' => null ),
array( 'name' => 'subtree_array',
+ 'type' => 'array',
+ 'required' => false,
+ 'default' => null ),
+ array( 'name' => 'ignore_visibility',
+ 'type' => 'bool',
+ 'required' => false,
+ 'default' => false ),
+ array( 'name' => 'limitation',
'type' => 'array',
'required' => false,
'default' => null ),
_______________________________________________
svn-eZFind mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-ezfind