Jump to content



Issue Information

  • #000488

  • 0 - None Assigned

  • In Progress

  • 2.3.2

  • -

Issue Confirmations

  • Yes (0)No (0)
Photo

parsing search logical operators is hardcoded in english

Posted by bruyndoncx on 19 August 2012 - 10:57 PM

in catalog/includes/functions/general.php

Function   function tep_parse_search_string around line 734 is the following section which has the logical operators hardcoded in english.
Ideally this would be in the selected language or all supported languages
I've added my dutch equivalents in the same hardcoded way, though I think it would be better to define arrays for each of the logical 'and' and 'or' operators.

// add default logical operators if needed
	$temp = array();
	for($i=0; $i<(count($objects)-1); $i++) {
	  $temp[] = $objects[$i];
	  if ( ($objects[$i] != 'and') &&
		   ($objects[$i] != 'or') &&
		   ($objects[$i] != '(') &&
		   ($objects[$i+1] != 'and') &&
		   ($objects[$i+1] != 'or') &&
		   ($objects[$i+1] != ')') ) {
		$temp[] = ADVANCED_SEARCH_DEFAULT_OPERATOR;
	  }
	}
	$temp[] = $objects[$i];
	$objects = $temp;
	$keyword_count = 0;
	$operator_count = 0;
	$balance = 0;
	for($i=0; $i<count($objects); $i++) {
	  if ($objects[$i] == '(') $balance --;
	  if ($objects[$i] == ')') $balance ++;
	  if ( ($objects[$i] == 'and') || ($objects[$i] == 'or') ) {
		$operator_count ++;
	  } elseif ( ($objects[$i]) && ($objects[$i] != '(') && ($objects[$i] != ')') ) {
		$keyword_count ++;
	  }
	}
// add default logical operators if needed
	$temp = array();
	for($i=0; $i<(count($objects)-1); $i++) {
	  $temp[] = $objects[$i];
	  if ( ($objects[$i] != 'and') &&
		   ($objects[$i] != 'en') &&
		   ($objects[$i] != 'of') &&	
		   ($objects[$i] != 'or') &&
		   ($objects[$i] != '(') &&
		   ($objects[$i+1] != 'and') &&
		   ($objects[$i+1] != 'en') &&
		   ($objects[$i+1] != 'of') &&
		   ($objects[$i+1] != 'or') &&
		   ($objects[$i+1] != ')') ) {
		$temp[] = ADVANCED_SEARCH_DEFAULT_OPERATOR;
	  }
	}
	$temp[] = $objects[$i];
	$objects = $temp;
	$keyword_count = 0;
	$operator_count = 0;
	$balance = 0;
	for($i=0; $i<count($objects); $i++) {
	  if ($objects[$i] == '(') $balance --;
	  if ($objects[$i] == ')') $balance ++;
	  if ( ($objects[$i] == 'and') || ($objects[$i] == 'or')
   || ($objects[$i] == 'en') || ($objects[$i] == 'of')  
	  ) {
		$operator_count ++;
	  } elseif ( ($objects[$i]) && ($objects[$i] != '(') && ($objects[$i] != ')') ) {
		$keyword_count ++;
	  }
	}

main language file of each language;


define('SEARCH_AND', 'and');
define('SEARCH_OR', 'or');

function file;


// add default logical operators if needed
	$temp = array();
	for($i=0; $i<(count($objects)-1); $i++) {
	  $temp[] = $objects[$i];
	  if ( ($objects[$i] != SEARCH_AND) &&
		   ($objects[$i] != SEARCH_OR) &&
		   ($objects[$i] != '(') &&
		   ($objects[$i+1] != SEARCH_AND) &&
		   ($objects[$i+1] != SEARCH_OR) &&
		   ($objects[$i+1] != ')') ) {
		$temp[] = ADVANCED_SEARCH_DEFAULT_OPERATOR;

That would do it?

that would do it in a single language, in my case I'd always allow english in the english version, and dutch plus english in the dutch version (as we are used to have to use english on a lot of sites).I
I'm not sure what the french, german or italians would prefer ...

This is a normal boolean type search. Although it is technically nice to have, it might be better to just use a more user friendly "and" for multiple keywords.

changed status to: In Progress