Seite 1 von 2

hilfe zum suchscript

Verfasst: 12.12.2004 20:26
von Lord_Femto
hi

ich habe mir auf basis von phpbb ein suchscript gecodet. wie ihr sehen könnt, wird das suchwort, wie bei phpbb gesplitet und dann mit einer schleife die wörter abgesucht.

jetzt habe ich nur ein problem. wenn ich einen oder zwei buchstaben eingebe, so zeigt er mir bei der ausgabe die korrekten ergebnisse nicht.

z.b. zeigt er mir bei der suche nach zz alle zeilen in der datenbank an, obwohl niergens ein inhalt mit zz vorhanden ist.

wie kann ich das ändern?!?

hier ist der code:

Code: Alles auswählen

if ( isset($_POST['mode']) || isset($_GET['mode']) )
{
	$mode = ( isset($_POST['mode']) ) ? $_POST['mode'] : $_GET['mode'];
}
else
{
	$mode = '';
}

if ( isset($_POST['search_keywords']) || isset($_GET['search_keywords']) )
{
	$search_keywords = ( isset($_POST['search_keywords']) ) ? $_POST['search_keywords'] : $_GET['search_keywords'];
}
else
{
	$search_keywords = '';
}

if ( isset($_POST['search_querry']) || isset($_GET['search_querry']) )
{
	$search_querry = ( $_POST['search_querry'] == 'news_subject' || $_GET['search_querry'] == 'news_subject' ) ? 'news_subject' : 'news_content' ;
}
else
{
	$search_querry = '';
}


if ( $mode == 'results' && $search_keywords == '' )
{
	message_die(GENERAL_ERROR, 'Could not obtain matched posts list', '', __LINE__, __FILE__, $sql);
}

else if ( $mode == 'results' && $search_keywords != '' )
{
	$split_search = array();
	$split_search = ( !strstr($multibyte_charset, 'iso-8859-1') ) ?  split_words(clean_words(stripslashes($search_keywords))) : split(' ', $search_keywords);	

	$page_title = 'News Search';
	include($inu_root_path . 'includes/page_header.'.$phpEx);
	include($inu_root_path . 'includes/page_left.'.$phpEx);

	$template->set_filenames(array(
		'body' => 'news_search_results.tpl')
	);

	for($i = 0; $i < count($split_search); $i++)
	{
		switch ( $split_search[$i] )
		{
			case 'and':
			$current_match_type = 'and';
			break;

			case 'or':
			$current_match_type = 'or';
			break;

			case 'not':
			$current_match_type = 'not';
			break;

			default:
			$current_match_type = 'and';

			$match_word =  addslashes('%' . str_replace('*', '', $split_search[$i]) . '%');
				
			$sql = "SELECT news_id, news_date, news_subject, news_content
					FROM " . NEWS_TABLE . "
					WHERE " . $search_querry . " LIKE '$match_word' ";
			
			if ( !($result = $db->sql_query($sql)) )
			{
				message_die(GENERAL_ERROR, 'Could not obtain matched posts list', '', __LINE__, __FILE__, $sql);
			}

			while( $row = $db->sql_fetchrow($result) )
			{
				$template->assign_block_vars('news_search_results', array( 
					$search_ids[] = $row['news_id'],
					
					'L_SUBJECT' => $row['news_subject'],
					'L_DATE' => $row['news_date'],

					'U_SUBJECT' => $post_url)
				);
			}
			
			$db->sql_freeresult($result);
			
		}
	}
	
	$total_match_count = count($search_ids);

	$template->assign_vars(array(
		'L_SUBJECT' => 'Titel',
		'L_DATE' => 'Datum',
		
		'L_COUNTER' => $total_match_count,
		
		'U_SUBJECT' => 'index.'.$phpEx.'?show=news_search&mode=results&search_keywords='.$search_keywords.'&search_querry='.$search_querry.'&order=news_subject',
		'U_DATE' => 'index.'.$phpEx.'?show=news_search&mode=results&search_keywords='.$search_keywords.'&search_querry='.$search_querry.'&order=news_date')
	);

	$template->pparse('body');

	include($inu_root_path . 'includes/page_tail.'.$phpEx);
}

Verfasst: 13.12.2004 21:23
von Lord_Femto
keiner eine idee?

Verfasst: 13.12.2004 22:03
von itst
Welchen Wert hat $match_word, wenn Du nach 'zz' suchst bzw wie sieht die gesamte Query dann aus?

Verfasst: 13.12.2004 22:09
von Lord_Femto
interessante sache. anscheinend funktioniert das ganze erst ab drei buchstaben. wenn ich ein oder zwei buchstaben verwende, wie z.b. z oder zz dann ist $word_match immer % %

wo ist der fehler?
eine andere frage ist, ob die methode überhaupt sinnvoll ist? irgendwo habe ich etwas mit indexierung gelesen. was ist nun fakto?

Verfasst: 14.12.2004 22:06
von Lord_Femto
keiner ne idee?

bitte itst... wie kann ich die suche optimieren bzw. spezifizieren.

Verfasst: 15.12.2004 21:20
von Lord_Femto
kommt schon. ich weiß doch, dass ihr das könnt

Verfasst: 16.12.2004 23:10
von Lord_Femto
help, i need somebody...

Verfasst: 16.12.2004 23:17
von itst
Was tut denn die Funktion clean_words()?

Verfasst: 16.12.2004 23:44
von Lord_Femto

Code: Alles auswählen

function clean_words($entry)
{
	static $drop_char_match =   array('^', '$', '&', '(', ')', '<', '>', '`', '\'', '"', '|', ',', '@', '_', '?', '%', '-', '~', '+', '.', '[', ']', '{', '}', ':', '\\', '/', '=', '#', '\'', ';', '!');
	static $drop_char_replace = array(' ', ' ', ' ', ' ', ' ', ' ', ' ', '',  '',   ' ', ' ', ' ', ' ', '',  ' ', ' ', '',  ' ',  ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' , ' ', ' ', ' ', ' ',  ' ', ' ');

	$entry = ' ' . strip_tags(strtolower($entry)) . ' ';

	$entry = str_replace(' +', ' and ', $entry);
	$entry = str_replace(' -', ' not ', $entry);

	//
	// Filter out strange characters like ^, $, &, change "it's" to "its"
	//
	for($i = 0; $i < count($drop_char_match); $i++)
	{
		$entry =  str_replace($drop_char_match[$i], $drop_char_replace[$i], $entry);
	}

	$entry = str_replace('*', ' ', $entry);
	$entry = preg_replace('/[ ]([\S]{1,2}|[\S]{21,})[ ]/',' ', $entry);

	return $entry;
}

Verfasst: 17.12.2004 23:48
von Lord_Femto
sag bitte nicht, dass dich das auch nicht weiterbringt.