Funzione ricerca rapida

Aperto da ibernet, Mercoledì - 30 Aprile 2014 - 16:03

0 Utenti e 1 Visitatore stanno visualizzando questa discussione.

ibernet

Buenas dias a tutti,
sono qui con un'altra delle mie richieste che possono sembrare assurde ma devo comunque arrivare a una soluzione e per farlo come al solito mi appoggio a voi guru di SMF.

Ho la necessità di modificare il funzionamento della ricerca rapida (che generalmente si attiva con una casellina che sta sotto al menu) screen in allegato

Ora quella ricerca funziona così:
1) Se sto sull'indice della sezione la ricerca funziona in tutte le categorie/sezioni/sottosezioni del forum
2) Se entro in una sezione la ricerca funziona SOLO in quella determinata sezione e NON nelle sue sottosezioni

Avrei la necessità di modificare il punto 2 e renderlo così:
2) Se entro in una sezione la ricerca deve funzionare sulla sezione stessa e su tutte le sue sottosezioni.

Riuscite ad indirizzarmi o ad aiutarmi ad apportare questa modifica?

Ringrazio fin da subito chiunque mi aiuterà

[allegato eliminato da un amministratore]

Filippo

Io davo per scontato che funzionasse già così.....

emanuele

C'è un "piccolo" problema.
Cosa fare con le sotto-sotto-board?
Esempio:
board
   |--sub-board
           |-- sub-sub-board
se sei in board, ti aspetti la ricerca consideri anche sub-sub-board?

ibernet

Si l'esigenza è che la ricerca funzioni ad albero (a livello infinito) dalla borad in cui ci si posiziona (essa compresa e tutte le sue sottoboard, sottosottoboard e così via)

emanuele

Pain in the ass.
Purtroppo al momento non posso scrivere codice, come indizio, probabilmente fai prima a recuperare tutti gli id delle board ed i parent, quindi da lì ricostruire l'albero discendente della board.
Un po' una palla.

emanuele

Non testato in maniera particolarmente approfondita, ma dovrebbe funzionare.
In Search.php:

Codice (find) Seleziona

$see_board = empty($search_params['advanced']) ? 'query_wanna_see_board' : 'query_see_board';
$request = $smcFunc['db_query']('', '
SELECT b.id_board
FROM {db_prefix}boards AS b
WHERE {raw:boards_allowed_to_see}
AND redirect = {string:empty_string}' . (empty($_REQUEST['brd']) ? (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
AND b.id_board != {int:recycle_board_id}' : '') : '
AND b.id_board IN ({array_int:selected_search_boards})'),
array(
'boards_allowed_to_see' => $user_info[$see_board],
'empty_string' => '',
'selected_search_boards' => empty($_REQUEST['brd']) ? array() : $_REQUEST['brd'],
'recycle_board_id' => $modSettings['recycle_board'],
)
);
$search_params['brd'] = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$search_params['brd'][] = $row['id_board'];
$smcFunc['db_free_result']($request);


Codice (replace with) Seleziona

$see_board = empty($search_params['advanced']) ? 'query_wanna_see_board' : 'query_see_board';
$search_params['brd'] = array();
if (empty($_REQUEST['quick_search']) || empty($_REQUEST['brd']) || (is_array($_REQUEST['brd']) && count($_REQUEST['brd']) > 1))
{
$request = $smcFunc['db_query']('', '
SELECT b.id_board
FROM {db_prefix}boards AS b
WHERE {raw:boards_allowed_to_see}
AND redirect = {string:empty_string}' . (empty($_REQUEST['brd']) ? (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
AND b.id_board != {int:recycle_board_id}' : '') : '
AND b.id_board IN ({array_int:selected_search_boards})'),
array(
'boards_allowed_to_see' => $user_info[$see_board],
'empty_string' => '',
'selected_search_boards' => empty($_REQUEST['brd']) ? array() : $_REQUEST['brd'],
'recycle_board_id' => $modSettings['recycle_board'],
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
$search_params['brd'][] = $row['id_board'];
$smcFunc['db_free_result']($request);
}
else
{
$children = array();
$possible_parents = array();
$request = $smcFunc['db_query']('', '
SELECT b.id_board, b.id_parent
FROM {db_prefix}boards AS b
WHERE {raw:boards_allowed_to_see}
AND redirect = {string:empty_string}',
array(
'boards_allowed_to_see' => $user_info[$see_board],
'empty_string' => '',
'no_parent' => 0,
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$possible_parents[$row['id_board']] = $row['id_parent'];
if (in_array($row['id_parent'], $_REQUEST['brd']) || in_array($row['id_board'], $_REQUEST['brd']))
$children[] = $row['id_board'];
}
$smcFunc['db_free_result']($request);

while (!empty($children))
{
$last_round = $children;
$search_params['brd'] = array_merge($search_params['brd'], $children);
$children = array();
foreach ($possible_parents as $brd => $parent)
{
if (in_array($parent, $last_round))
$children[] = $brd;
}
}
$search_params['brd'] = array_unique($search_params['brd']);
}

emanuele

Dimenticavo!

In index.template.php, dove c'è la form della risposta rapida, aggiungi un:
<input type="hidden" name="quick_search" value="1" />

ibernet

Ciao Emanuele,
grazie! ho provato il codice e apparentemente non cambia nulla.

emanuele

Messo anche l'input correttamente nella form della ricerca rapida?
hmm... devo riprovare, ma a me funzionava...magari ho sbagliato qualcosa nel copia&incolla... :-\

ibernet

#9
Yes, ho applicato il codice su entrambi gli index.template.php (default e del tema) ho provato anche singolarmente ma nada.

il codice è questo:

<div class="news normaltext">
<form id="search_form" action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '">
<input type="text" name="search" value="" class="input_text" />&nbsp;
<input type="submit" name="submit" value="', $txt['search'], '" class="button_submit" />
<input type="hidden" name="advanced" value="0" />
                                        <input type="hidden" name="quick_search" value="1" />';

emanuele

Sì, perché tu sei admin... >_<

Annulla le modifiche precedenti e applica queste di seguito.

Codice (find) Seleziona
// Select all boards you've selected AND are allowed to see.
elseif ($user_info['is_admin'] && (!empty($search_params['advanced']) || !empty($_REQUEST['brd'])))
$search_params['brd'] = empty($_REQUEST['brd']) ? array() : $_REQUEST['brd'];
else
{
$see_board = empty($search_params['advanced']) ? 'query_wanna_see_board' : 'query_see_board';
$request = $smcFunc['db_query']('', '
SELECT b.id_board
FROM {db_prefix}boards AS b
WHERE {raw:boards_allowed_to_see}
AND redirect = {string:empty_string}' . (empty($_REQUEST['brd']) ? (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
AND b.id_board != {int:recycle_board_id}' : '') : '
AND b.id_board IN ({array_int:selected_search_boards})'),
array(
'boards_allowed_to_see' => $user_info[$see_board],
'empty_string' => '',
'selected_search_boards' => empty($_REQUEST['brd']) ? array() : $_REQUEST['brd'],
'recycle_board_id' => $modSettings['recycle_board'],
)
);
$search_params['brd'] = array();
while ($row = $smcFunc['db_fetch_assoc']($request))
$search_params['brd'][] = $row['id_board'];
$smcFunc['db_free_result']($request);

// This error should pro'bly only happen for hackers.
if (empty($search_params['brd']))
$context['search_errors']['no_boards_selected'] = true;
}


Codice (replace with) Seleziona
// Select all boards you've selected AND are allowed to see.
elseif ($user_info['is_admin'] && (!empty($search_params['advanced']) || !empty($_REQUEST['brd'])))
{
if (empty($_REQUEST['quick_search']) || empty($_REQUEST['brd']) || (is_array($_REQUEST['brd']) && count($_REQUEST['brd']) > 1))
$search_params['brd'] = empty($_REQUEST['brd']) ? array() : $_REQUEST['brd'];
else
$search_params['brd'] = custFindChildBoards($_REQUEST['brd'], '1=1');
}
else
{
$see_board = empty($search_params['advanced']) ? 'query_wanna_see_board' : 'query_see_board';
$search_params['brd'] = array();

if (empty($_REQUEST['quick_search']) || empty($_REQUEST['brd']) || (is_array($_REQUEST['brd']) && count($_REQUEST['brd']) > 1))
{
$request = $smcFunc['db_query']('', '
SELECT b.id_board
FROM {db_prefix}boards AS b
WHERE {raw:boards_allowed_to_see}
AND redirect = {string:empty_string}' . (empty($_REQUEST['brd']) ? (!empty($modSettings['recycle_enable']) && $modSettings['recycle_board'] > 0 ? '
AND b.id_board != {int:recycle_board_id}' : '') : '
AND b.id_board IN ({array_int:selected_search_boards})'),
array(
'boards_allowed_to_see' => $user_info[$see_board],
'empty_string' => '',
'selected_search_boards' => empty($_REQUEST['brd']) ? array() : $_REQUEST['brd'],
'recycle_board_id' => $modSettings['recycle_board'],
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
$search_params['brd'][] = $row['id_board'];
$smcFunc['db_free_result']($request);
}
else
{
$search_params['brd'] = custFindChildBoards($_REQUEST['brd'], $user_info[$see_board]);
}

// This error should pro'bly only happen for hackers.
if (empty($search_params['brd']))
$context['search_errors']['no_boards_selected'] = true;
}


Quindi alla fine di Search.php aggiungi:


function custFindChildBoards($board, $see_board)
{
global $smcFunc;

$children = array();
$search_brd = array();
$possible_parents = array();
$request = $smcFunc['db_query']('', '
SELECT b.id_board, b.id_parent
FROM {db_prefix}boards AS b
WHERE {raw:boards_allowed_to_see}
AND redirect = {string:empty_string}',
array(
'boards_allowed_to_see' => $see_board,
'empty_string' => '',
'no_parent' => 0,
)
);
while ($row = $smcFunc['db_fetch_assoc']($request))
{
$possible_parents[$row['id_board']] = $row['id_parent'];
if (in_array($row['id_parent'], $board) || in_array($row['id_board'], $board))
$children[] = $row['id_board'];
}
$smcFunc['db_free_result']($request);

while (!empty($children))
{
$last_round = $children;
$search_brd = array_merge($search_brd, $children);
$children = array();
foreach ($possible_parents as $brd => $parent)
{
if (in_array($parent, $last_round))
$children[] = $brd;
}
}
return array_unique($search_brd);
}

ibernet

#11
Mitico Emanuale!
In allegato il file di installazione :)

Recap per non doversi leggere tutto:
Questo Add-On permette di effettuare la ricerca rapida ad albero.

Ecco come funzionava e come funziona dopo l'aggiunta dell'Add-On (custom):
Originale:
1) Se sto sull'indice della sezione la ricerca funziona in tutte le categorie/sezioni/sottosezioni del forum.
2) Se entro in una sezione la ricerca funziona SOLO in quella determinata sezione e NON nelle sue sottosezioni.

Dopo la modifica:
Il punto 2 cambia, se entro in una sezione la ricerca funziona sulla sezione stessa e su tutte le sue sottosezioni.

emanuele


Discussioni simili (3)