[RISOLTO] Ricerca attiva su modulo creato con CTLModuleMaker

La discussione sul CMS Made Simple in italiano.
Post Reply
User avatar
protempore
Power Poster
Power Poster
Posts: 599
Joined: Mon Jan 14, 2008 9:08 pm

[RISOLTO] Ricerca attiva su modulo creato con CTLModuleMaker

Post by protempore »

ciao,
ho messo in linea la mia ultima fatica...
;)

www.teatrolafabbrica.com

per realizzare il sistema di Rassegne-Eventi-Calendario avevo tempo addietro utilizzato Cataloger e CGCalendar... c'erano però troppe limitazioni e complicazioni nella gestione della cosa... anche perché era richiesta una gestione anche lato frontend e non solo di backend...

così mi sono avventurato a costruire un modulo ad-hoc... e devo dire che, con mia sorpresa, ci sono riuscito...

si, va beh... ai puristi della programmazione magari gli si rizzano i capelli... però funziona in modo soddisfacente.

Adesso ho un problema... come fare a far funzionare il modulo "Search" anche sul modulo da me creato?... c'è una qualche procedura da seguire?

grazie

CMSMS 1.7.1
Last edited by protempore on Tue Jun 08, 2010 10:46 am, edited 1 time in total.
An eye for an eye will make the whole world blind
Mahatma Gandhi (1869-1948)
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

Re: Ricerca attiva su modulo creato con CTLModuleMaker

Post by nervino »

Molto bello. Complimenti!
Mi piace soprattutto la gestione del calendario (dropdown mesi/anni).
Se non ricordo male, c'è un modo per registrare un modulo affinché venga incluso nella ricerca del modulo search.
Serve anche a me, ed in questi giorni contavo di approfondire la cosa. Chi fa prima...

ciao

P.S. ho scoperto da poco CTLModuleMaker. È veramente comodo e ben fatto!
Last edited by nervino on Sun Jun 06, 2010 1:58 pm, edited 1 time in total.
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

Re: Ricerca attiva su modulo creato con CTLModuleMaker

Post by nervino »

User avatar
protempore
Power Poster
Power Poster
Posts: 599
Joined: Mon Jan 14, 2008 9:08 pm

Re: Ricerca attiva su modulo creato con CTLModuleMaker

Post by protempore »

grazie per i complimenti e, soprattutto, per il link...

c'ho capito poco, ma senz'altro che è possibile una ricerca nel mio modulo!  ;D

Proverò a definire i due metodi come indicato e a capire come devono essere richiamati per la ricerca... non la vedo semplice, ma sono uno che vede sempre il bicchiere mezzo pieno...
:D
An eye for an eye will make the whole world blind
Mahatma Gandhi (1869-1948)
User avatar
protempore
Power Poster
Power Poster
Posts: 599
Joined: Mon Jan 14, 2008 9:08 pm

Re: Ricerca attiva su modulo creato con CTLModuleMaker

Post by protempore »

ops...
i due metodi già li crea CTLModuleMaker... però mi sembra che agisca solo sul campo "name"... mentre a me servrebbe anche sul campo "descrizione"...

nello specifico ha creato questo:

Code: Select all

function SearchResult($returnid, $itemid, $level = "")
    {
		$result = array();
		$wantedparam = false;
		$newparams = array();
		if($level == "calendario"){
			// we seek an element of the last level, and will display the detail view
			$wantedparam = "alias";
		}else{
			if($newparams["what"] = $this->get_nextlevel($level)){
			// we seek an element of another level, and will display the list view of its children
				$wantedparam = "parent";
			}
		}
		if ($wantedparam){
			$tablename = cms_db_prefix()."module_gg_eventi_".$level;
			$db =& $this->GetDb();
			$query = "SELECT name, alias FROM $tablename WHERE id = ?";
			$dbresult = $db->Execute( $query, array( $itemid ) );
			if ($dbresult){
				$row = $dbresult->FetchRow();
				$newparams[$wantedparam] = $row["alias"];

				//0 position is the prefix displayed in the list results.
				$result[0] = $this->GetFriendlyName();

				//1 position is the title
				$result[1] = $row["name"];
		
				//2 position is the URL to the title.
				$result[2] = $this->CreateLink($id, "default", $returnid, "", $newparams, "", true, false, "", false, $this->BuildPrettyUrls($newparams, $returnid));
			}
		}

		return $result;
	}
	
	function SearchReindex(&$module)
    {
		$db =& $this->GetDb();
		if($this->GetPreference("searchmodule_index_rassegna",false)){
			$itemlist = $this->get_level_rassegna();
			foreach($itemlist as $item){
				$text = "$item->name";
				$module->AddWords($this->GetName(), $item->id, "rassegna", $text, NULL);
			}
		}
		if($this->GetPreference("searchmodule_index_evento",false)){
			$itemlist = $this->get_level_evento();
			foreach($itemlist as $item){
				$text = "$item->name";
				$module->AddWords($this->GetName(), $item->id, "evento", $text, NULL);
			}
		}
		if($this->GetPreference("searchmodule_index_calendario",false)){
			$itemlist = $this->get_level_calendario();
			foreach($itemlist as $item){
				$text = "$item->name";
				$module->AddWords($this->GetName(), $item->id, "calendario", $text, NULL);
			}
		}
		
    }	
Last edited by protempore on Sun Jun 06, 2010 5:16 pm, edited 1 time in total.
An eye for an eye will make the whole world blind
Mahatma Gandhi (1869-1948)
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

Re: Ricerca attiva su modulo creato con CTLModuleMaker

Post by nervino »

Giusto. Mi ricordo che CTLModuleMaker, ad un certo punto della creazione, chiede se l'elemnto deve essere indicizzato.

Un altro spunto può venire dal modo in cui viene implementata la ricerca nel modulo News: News.module.php, riga 386 circa:

Code: Select all

    function SearchReindex(&$module)
    {
      $db =& $this->GetDb();
		
      $query = 'SELECT * FROM '.cms_db_prefix().'module_news ORDER BY news_date';
      $result = $db->Execute($query);

      while ($result && !$result->EOF)
	{
	  if ($result->fields['status'] == 'published')
	    {
	      $module->AddWords($this->GetName(), 
				$result->fields['news_id'], 'article', 
				$result->fields['news_data'] . ' ' 
                                . $result->fields['summary'] . ' ' 
                                . $result->fields['news_title'] . ' ' . $result->fields['news_title'],
				($result->fields['end_time'] != NULL && 
                 $this->GetPreference('expired_searchable',0) == 0) ?  
                 $db->UnixTimeStamp($result->fields['end_time']) : NULL);
	    }
	  $result->MoveNext();
	}
    }
Se non se ne viene a capo, caro paraguru, possiamo sempre evocare il tuo diretto superiore  :D
User avatar
protempore
Power Poster
Power Poster
Posts: 599
Joined: Mon Jan 14, 2008 9:08 pm

Re: Ricerca attiva su modulo creato con CTLModuleMaker

Post by protempore »

avevo selezionato l'indicizzazione solo per il campo "name"... per questo motivo compariva solo quello... per indicizzarne anche altri dovrebbe bastare modificare la riga:

Code: Select all

	$text = "$item->descrizione $item->name";
la questione rimane di che uso farne per l'utilizzo nel modulo "Search"... e qui il buio è totale...

mi sa che rischio di vedermi assegnato il titolo di "paraguru" solo per la parodia della locuzione originale...  ;D
An eye for an eye will make the whole world blind
Mahatma Gandhi (1869-1948)
nervino
Power Poster
Power Poster
Posts: 448
Joined: Sun Dec 28, 2008 12:15 pm
Location: Roma, Italy

Re: Ricerca attiva su modulo creato con CTLModuleMaker

Post by nervino »

protempore wrote:
la questione rimane di che uso farne per l'utilizzo nel modulo "Search"... e qui il buio è totale...
Non ti seguo. Secondo me, aggiungendo altri campi all'indicizzazione, quando si effettua una ricerca tramite il modulo Search quest'ultimo cercherà anche in quei campi. A te serve un comportamento diverso?
User avatar
protempore
Power Poster
Power Poster
Posts: 599
Joined: Mon Jan 14, 2008 9:08 pm

Re: Ricerca attiva su modulo creato con CTLModuleMaker

Post by protempore »

nervino wrote:
protempore wrote:
la questione rimane di che uso farne per l'utilizzo nel modulo "Search"... e qui il buio è totale...
Non ti seguo. Secondo me, aggiungendo altri campi all'indicizzazione, quando si effettua una ricerca tramite il modulo Search quest'ultimo cercherà anche in quei campi. A te serve un comportamento diverso?
no, magari mi sfugge qualcosa... ma a me non ricerca nulla nemmeno se inserisco quei campi...

Siamo sicuri che non serve "agganciare" in qualche modo il mio modulo al modulo "search"?
An eye for an eye will make the whole world blind
Mahatma Gandhi (1869-1948)
alby

Re: Ricerca attiva su modulo creato con CTLModuleMaker

Post by alby »

Infatti ti manca un pezzo.
SearchResult() cerca utilizzando il modulo Search
SearchReindex() è chiamato quando re-indicizzi tramite il modulo Search

ma manca il pezzo di quando inserisci un nuovo (modifica/cancella) item, se no devi re-indicizzare tutto manualmente ad ogni inserimento/modifica/cancella  :-X

Sarà del tipo:

In inserimento/modfica:
$search =& $this->GetModuleInstance('Search');
if(false !== $search) $search->AddWords($this->GetName(), $id, 'qualcosa', ' testo');

In cancella:
$search =& $this->GetModuleInstance('Search');
if(false !== $search) $search->DeleteWords($this->GetName(), $id, 'qualcosa');

Alby
User avatar
protempore
Power Poster
Power Poster
Posts: 599
Joined: Mon Jan 14, 2008 9:08 pm

Re: Ricerca attiva su modulo creato con CTLModuleMaker

Post by protempore »

alby wrote: Infatti ti manca un pezzo....
sono un pollo...  ;D

in effetti il pezzo di codice c'era anche quello... solo che non avevo aggiunto tutti i campi da indicizzare lasciando solo "name"... l'ho fatto e reindicizzato manualmente dal modulo Search... e tutto funziona...

grazie
An eye for an eye will make the whole world blind
Mahatma Gandhi (1869-1948)
Post Reply

Return to “Italian - Italiano”