integrare apache solr in typo3

50
Milano 14/15 Marzo 2014 Ricerche evolute mediante Apache Solr Mauro Lorenzutti T3Camp Italia Il quarto evento italiano dedicato a TYPO3

Upload: mauro-lorenzutti

Post on 27-Jun-2015

406 views

Category:

Technology


9 download

DESCRIPTION

Un'introduzione ai motori di ricerca nativi di TYPO3 e presentazione dei loro limiti. Presentazione di Apache Solr e delle modalità di integrazione in TYPO3

TRANSCRIPT

Page 1: Integrare Apache Solr in TYPO3

Milano 14/15 Marzo 2014

Ricerche evolute mediante Apache Solr Mauro Lorenzutti

T3Camp Italia Il quarto evento italiano dedicato a TYPO3

Page 2: Integrare Apache Solr in TYPO3

Mauro Lorenzutti

CTO di Webformat

Sviluppatore e consulente TYPO3 dal 2004

TYPO3 Certified Integrator dal 2009

Sviluppatore di numerose estensioni, tra cui: DB Integration (wfqbe)

Webformat Shop System (extendedshop)

TYPO3-Alfresco Connector

TYPO3-Magento Connector

Speaker in varie conferenze: T3DD07

T3CON07

T3CON09US

Pag. 2 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

T3CON13DE

MageDay

4 x T3CampItalia ;-)

Page 3: Integrare Apache Solr in TYPO3

Di cosa parleremo

La ricerca integrata di TYPO3

Indexed Search Engine

Introduzione ad Apache Solr

Integrare Solr in TYPO3

Pag. 3 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 4: Integrare Apache Solr in TYPO3

50 slide… Tutti pronti?

Pag. 4 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 5: Integrare Apache Solr in TYPO3

Io si!

Page 6: Integrare Apache Solr in TYPO3

La ricerca nei siti

Molto spesso trascurata e sottovalutata

Ma…

Se ho un database con >100k eventi?

Se ho un catalogo con 20k prodotti strutturato in categorie e con caratteristiche sulla base delle quali vorrei che gli utenti potessero filtrare i prodotti?

Pag. 6 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 7: Integrare Apache Solr in TYPO3

La ricerca standard di TYPO3

Pag. 7 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 8: Integrare Apache Solr in TYPO3

Un contenuto standard

Pag. 8 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 9: Integrare Apache Solr in TYPO3
Page 10: Integrare Apache Solr in TYPO3
Page 11: Integrare Apache Solr in TYPO3

Le funzionalità della ricerca standard

Consente all’utente di scegliere se cercare nelle keyword della pagina o nel contenuto

Consente di configurare più tabelle via typoscript

Output configurabile via typoscript

La ricerca si basa sul operatore “LIKE %...%”

Pag. 11 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 12: Integrare Apache Solr in TYPO3

Pro & Contro della ricerca standard

Pag. 12 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

+ Integrata + Facile da configurare

- Funzionalità di base - Cerca solo nel database - LIKE %...%

Page 13: Integrare Apache Solr in TYPO3

Indexed Search Engine

Pag. 13 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 14: Integrare Apache Solr in TYPO3

Un’estensione di sistema

Pag. 14 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 15: Integrare Apache Solr in TYPO3
Page 16: Integrare Apache Solr in TYPO3

Indice

Pag. 16 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 17: Integrare Apache Solr in TYPO3

Statistiche

Pag. 17 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 18: Integrare Apache Solr in TYPO3

Le funzionalità della ricerca standard

Consente di indicizzare pagine, record nel database, documenti, immagini, url esterni, ecc.

Costruisce un indice di parole chiave per ciascun contenuto ed esegue la ricerca su questo

Fornisce una percentuale di pertinenza del risultato

I contenuti vengono indicizzati contestualmente alla prima visualizzazione

È disponibile un crawler per indicizzare massivamente il sito

Pag. 18 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 19: Integrare Apache Solr in TYPO3
Page 20: Integrare Apache Solr in TYPO3
Page 21: Integrare Apache Solr in TYPO3

Pro & Contro di Indexed search engine

Pag. 21 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

+ Integrata + Indicizza pagine, record, file, url, … + Ordinamento per rilevanza + Statistiche di ricerca + Molte estensioni disponibili

- Configurazione non immediata - Può rallentare la navigazione - Solo le pagine in cache vengono indicizzate - Indice salvato nel db (problemi di prestazioni)

Page 22: Integrare Apache Solr in TYPO3

Pag. 22 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 23: Integrare Apache Solr in TYPO3

Apache Solr?

• SolrTM is the popular, blazing fast open source enterprise search platform from the Apache LuceneTM project. Its major features include powerful full-text search, hit highlighting, faceted search, near real-time indexing, dynamic clustering, database integration, rich document (e.g., Word, PDF) handling, and geospatial search. Solr is highly reliable, scalable and fault tolerant, providing distributed indexing, replication and load-balanced querying, automated failover and recovery, centralized configuration and more. Solr powers the search and navigation features of many of the world's largest internet sites. https://lucene.apache.org/solr/

Pag. 23 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 24: Integrare Apache Solr in TYPO3

Download

Download:

http://www.apache.org/dyn/closer.cgi/lucene/solr/4.7.0

Apache License, versione 2.0

http://www.apache.org/licenses/LICENSE-2.0

Requisiti:

Java 1.6

Un application server (Tomcat, Jetty, JBoss, ecc.)

Pag. 24 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 25: Integrare Apache Solr in TYPO3

Ma cos’è Apache Solr?

Solr è un “enterprise search server”

Espone delle API REST per l’interazione

Vi si possono caricare documenti (ovvero qualsiasi tipo di contenuto) via XML, JSON e CSV tramite chiamate HTTP

Si possono cercare e scaricare documenti in formato XML, JSON e CSV tramite chiamate HTTP

Un database NoSQL?

Pag. 25 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 26: Integrare Apache Solr in TYPO3

Funzionalità principali

Ricerche Full-text

Faceted navigation

Spellchecking: “Did you mean…”

Raccomandazioni: “More like this”

Indicizzazione di documenti (PDF, DOC, ecc.)

Gestione dei sinonimi e delle stopword

Ricerche geospaziali

Ottimizzato per elevato traffico e mole di dati

Estendibile mediante plugin

Pag. 26 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 27: Integrare Apache Solr in TYPO3

Schemaless

Permette di definire dinamicamente i campi che descrivono il documento

Pag. 27 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 28: Integrare Apache Solr in TYPO3

Interfaccia di amministrazione

Pag. 28 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 29: Integrare Apache Solr in TYPO3

Come integrarlo in TYPO3?

Due possibilità:

Apache Solr for TYPO3 (ext: solr)

DIY (ext: arrangiati)

Pag. 29 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 30: Integrare Apache Solr in TYPO3

Apache Solr for TYPO3

Pag. 30 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 31: Integrare Apache Solr in TYPO3

DIY

Sono disponibili diversi client PHP, ad es.:

http://www.solarium-project.org/

https://code.google.com/p/solr-php-client/

Due soluzioni “quick and dirty”:

cURL

file_get_contents()

Pag. 31 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 32: Integrare Apache Solr in TYPO3

DIY

Costruiamo un esempio molto semplice

Indicizziamo le news del nostro sito

Implementiamo una funzionalità di ricerca

Costruiamo dei filtri a faccette

Pag. 32 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 33: Integrare Apache Solr in TYPO3

Configuriamo il core

core.properties

name=news

config=solrconfig.xml

schema=schema.xml

loadOnStartup=true

Pag. 33 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 34: Integrare Apache Solr in TYPO3

solrconfig.xml

[…]

<requestHandler name="/newsImporter" class="org.apache.solr.handler.dataimport.DataImportHandler">

<lst name="defaults">

<str name="update.chain">data-extraction</str>

<str name="config">newsImporter.xml</str>

</lst>

</requestHandler>

[…]

Pag. 34 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 35: Integrare Apache Solr in TYPO3

newsImporter.xml

<dataConfig>

<dataSource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost/typo3_61?user=typo3_61&amp;password=typo3_61" batchSize="1" />

<document name="news_document">

<entity name="news" pk="uid" transformer="script:GenerateId" query="SELECT uid, pid, title, teaser, bodytext, keywords, author FROM tx_news_domain_model_news WHERE deleted=0 AND hidden=0">

</entity>

</document>

</dataConfig>

Pag. 35 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 36: Integrare Apache Solr in TYPO3

schema.xml 1/3

<schema name="typo3_news" version="1.1">

<types>

<fieldtype name="string" class="solr.StrField" />

<fieldType name="long" class="solr.TrieLongField" />

<fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">

<analyzer>

<charFilter class="solr.MappingCharFilterFactory" mapping="mappa- accenti.txt"/>

<tokenizer class="solr.StandardTokenizerFactory" />

<filter class="solr.LowerCaseFilterFactory" />

</analyzer>

</fieldType>

</types>

Pag. 36 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 37: Integrare Apache Solr in TYPO3

schema.xml 2/3

<fields>

<field name="uid" type="long" indexed="true" stored="true" multiValued="false" required="true" />

<field name="title" type="text_general" indexed="true" stored="true" multiValued="false" />

<field name="teaser" type="text_general" indexed="true" stored="true" multiValued="false" />

<field name="bodytext" type="text_general" indexed="true" stored="true" multiValued="false" />

<field name="author" type="string" indexed="true" stored="true" multiValued="false" />

<field name="keywords" type="string" indexed="true" stored="true" multiValued="false" />

Pag. 37 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 38: Integrare Apache Solr in TYPO3

schema.xml 3/3

<field name="_version_" type="long" indexed="true" stored="true" multiValued="false" />

<field name="fullText" type="text_general" indexed="true" stored="true" multiValued="true" />

<copyField source="title" dest="fullText" />

<copyField source="teaser" dest="fullText" />

<copyField source="bodytext" dest="fullText" />

<copyField source="author" dest="fullText" />

<copyField source="keywords" dest="fullText" />

</fields>

<defaultSearchField>fullText</defaultSearchField>

<solrQueryParser defaultOperator="OR" />

<uniqueKey>uid</uniqueKey>

</schema>

Pag. 38 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 39: Integrare Apache Solr in TYPO3

DataImport

Pag. 39 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 40: Integrare Apache Solr in TYPO3

Interroghiamo l’indice

http://localhost:8983/solr/news/select? q=fullText:celebr* &wt=json &indent=true &facet=true &facet.field=author &facet.sort=index

Pag. 40

Page 41: Integrare Apache Solr in TYPO3

Facciamolo da TYPO3

Pag. 41 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 42: Integrare Apache Solr in TYPO3

Setup.txt

Pag. 42 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 43: Integrare Apache Solr in TYPO3

NewsSolrController.php

Pag. 43 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 44: Integrare Apache Solr in TYPO3

SolrService.php 1/2

Pag. 44 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 45: Integrare Apache Solr in TYPO3

SolrService.php 2/2

Pag. 45 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 46: Integrare Apache Solr in TYPO3

Search.html

Pag. 46 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 47: Integrare Apache Solr in TYPO3

Un dettaglio:

Pag. 47 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 48: Integrare Apache Solr in TYPO3

Pro & Contro di Apache Solr

Pag. 48 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

+ Tante tante tante tante funzionalità! + Adatto a gestire elevati volumi di dati + Molto veloce

- Non integrato in TYPO3 - Impegnativo da configurare - Richiede Java - C’è molto da studiare… - Può creare dipendenza

Page 49: Integrare Apache Solr in TYPO3

Alcuni libri utili

Pag. 49 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr

Page 50: Integrare Apache Solr in TYPO3

Q & A

[email protected]

http://it.linkedin.com/in/maurolorenzutti

https://twitter.com/MauroLorenzutti

http://www.slideshare.net/mauro.lorenzutti

Pag. 50 Mauro Lorenzutti: Ricerche evolute mediante Apache Solr