eZ Find 2 - excluding attribute from search

Author Message

Greg Lakomy

Friday 27 March 2009 12:10:58 pm

Hi,

Is it possible to exclude an attribute from search? I need to be able to still search that attribute on the admin site but exclude it from the front end.

Greg.

Developer
http://www.duoconsulting.com

Paul Borgermans

Friday 27 March 2009 2:11:31 pm

Not easily for attributes, though you could use the boost functions of eZ Find and add this as parameters in a custom search template.

However, better is to expose this query time functionality as parameters. Can you file an enhancement request?

Thanks
Paul

eZ Publish, eZ Find, Solr expert consulting and training
http://twitter.com/paulborgermans

Greg Lakomy

Monday 30 March 2009 8:07:17 am

Enhancement request has been submitted.

Thanks,
Greg

Developer
http://www.duoconsulting.com

Greg Lakomy

Friday 03 April 2009 10:29:50 am

I've implemented temp/dirty solution:

Modified /ezfind/classes/ezfezpsolrquerybuilder.php, buildSearch() function

- below $queryFields added the following code

$queryFields = .......
		
//exclude "internal_tags" attribute from search on the front site
$currentUser = eZUser::currentUser();
$webUser = $currentUser->Login;
if ($webUser == 'anonymous') {
	$key_to_be_deleted = array_search('attr_internal_tags_t', $queryFields);
	$this->array_delete($queryFields,$key_to_be_deleted);
}
eZDebug::writeDebug( $currentUser, 'currentUser' );

- based on the currentUser I can remove key and value from queryFields array

- added array_delete function (from php.net manual)

public function array_delete(&$ary,$key_to_be_deleted)
{
	$new = array();
	if($key_to_be_deleted) {
		if(!array_key_exists($key_to_be_deleted,$ary)) {
			return;
		}
		foreach($ary as $key => $value) {
			if($key != $key_to_be_deleted) {
				$new[$key] = $value;
			}
		}
		$ary = $new;
	}
	if(is_array($key_to_be_deleted)) {
		foreach($key_to_be_deleted as $del) {
			array_delete(&$ary,$del);
		}
	}
	eZDebug::writeDebug( $new, 'array_delete' );
} 

Developer
http://www.duoconsulting.com

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.