SlideShare ist ein Scribd-Unternehmen logo
1 von 35
Downloaden Sie, um offline zu lesen
Sphinx: Open Source Search Server

Matteo Baccan
matteo@baccan.it
Jug Novara, PUG Novara
Sphinx: Open Source Search Server
•   Relatore:           Matteo Baccan
•   Area:               Open Source
•   Target:             Expert, Developer, Power User
•   Difficoltà:         Media-Bassa
    Sporchiamoci le mani con un'alternativa a Lucene e MySQL. Un prodotto
    OpenSource, portabile, veloce, attento alle prestazioni e ai consumi di spazio e
    memoria. Vedremo come distribuire il carico, come effettuare hotswap di indici, come
    usare lo stesso JDBC per accedere a MySQL e Sphinx, come gestire indici dinamici e
    statici. Utilizzeremo query, subquery, strategia di ricerca diverse. Studieremo le
    migliori tecniche per indicizzare milioni di documenti, il tutto tramite PHP e JAVA su
    casi reali
Da 0 a 100 in 40 minuti, allacciate le cinture ;)
                                                                                Matteo Baccan   2
                                                    matteo@baccan.it – Jug Novara, PUG Novara
Chi sono?
  Divulgatore informatico, giornalista per riviste
  tecniche nazionali oltre 700 articoli per :Dev, Login,
  Computer Programming, Mokabyte. Relatore
  tecnico ad eventi di programmazione: Borland
  Forum 2000, Webbit 2004, JIP day 2005, Javaday
  (2006,2007,2010) PHPDay (2008, 2010), CONFSL
  2010, WebTech 2010, Codemotin (2011,2012).
  Autore di Corso di C# ISBN 8881500167. Autore di
  JobCrawler e HTML2POP3 (Oltre 900.000
  download su SourceForge)



                                         Matteo Baccan   3
             matteo@baccan.it – Jug Novara, PUG Novara
Cos'è Sphinx?
•   Acronimo di SQL Phrase Index
•   Un motore di ricerca “full text”
•   Un “emulatore” MySQL
•   Veloce, Compatto, Scalabile



                                                          Matteo Baccan   4
                              matteo@baccan.it – Jug Novara, PUG Novara
Perché usare Sphinx?
• Uso già MySQL/Lucene/Solr                              no
• Uso Lucene in deep                                     no
• Uso Lucene, ma è lento a indicizzare                   forse
• Ho molto spazio allocato dagli indici                  forse
• Con java non conosco alternative                       forse
• Devo convertire molto codice SQL                       si
• Non ho un motore di ricerca                            si
• Ho bisogno di una soluzione veloce                     si
                                                                 Matteo Baccan   5
                                     matteo@baccan.it – Jug Novara, PUG Novara
Alcuni numeri?
• 10-1000x volte più veloce di MySQL sulle ricerche
  full-text
   – MySQL è veloce solo con gli indici in RAM)
• 2-3x volte più veloce sulle ricerche non full-text
   – Sphinx ha meno feature da supportare ;)
• 2-4x volte più veloce di Lucene sulle ricerche full-text
  [fonte Sphinx Technologies Inc.] ;)
                                                             Matteo Baccan   6
                                 matteo@baccan.it – Jug Novara, PUG Novara
Risultati rilevanti
• Sphinx ha diversi algoritmi per il calcolo del rank
   – phrase proximity (aka LCS) : posizione delle
     parole
   – BM25 : frequenza delle parole
  La combinazione di questi algoritmi può variare la
  qualità dei dati cercati

                                                          Matteo Baccan   7
                              matteo@baccan.it – Jug Novara, PUG Novara
Alcuni algoritmi di rilevanza
• SPH_RANK_PROXIMITY_BM25: combina LCS e BM25
• SPH_RANK_BM25: solo BM25
• SPH_RANK_NONE: nessun rank
• SPH_RANK_WORDCOUNT: solo per numero di parole, in
  base alla priorità dei campi
• SPH_RANK_SPH04: LCS e BM25, ma portando in testa gli
  exact match
• SPH_RANK_EXPR: basato su espressione

                                                           Matteo Baccan   8
                               matteo@baccan.it – Jug Novara, PUG Novara
Ma chi lo usa?
• boardreader.com, 1.000.000 query/day, 16.000.000.000
  documenti, 5TB, 27 sphinx box
• craigslist.org, 200.000.000 query/day (2.000 al secondo) 15
  sphinx box
  http://sphinxsearch.com/info/powered/
• moonlab.it network: 500.000 query/day, 10.000.000
  documenti, 300 millesimi tempo medio di risposta 2 sphinx
  box bilanciate da macchine dual core con 4g di RAM (con
  jboss, mysql, sphinx e altri processi in concorrenza)
                                                               Matteo Baccan   9
                                   matteo@baccan.it – Jug Novara, PUG Novara
Architettura base
• sphinx.conf file di configurazione

• Indexer      indicizzatore

• SearchD      demone di ricerca

• Search       ricerca command line
                                                           Matteo Baccan   10
                               matteo@baccan.it – Jug Novara, PUG Novara
Come indicizzo?
• Definisco un datasource : connessione e
  stringa di selezione dei dati
• Definisco un indice: posizione nel file system e
  tipologia
• Indicizzo: dico all'indexer di creare l'indice
  appena definito

                                                        Matteo Baccan   11
                            matteo@baccan.it – Jug Novara, PUG Novara
Come indicizzo? Il datasource
source job {
  type             = mysql
  sql_host         = localhost
  sql_user         = sphinx
  sql_pass         =
  sql_db           = jobcrawler
  sql_port         = 3306
  sql_query        = SELECT id, descrizione FROM `job`
  sql_query_info   = SELECT id, titolo FROM job WHERE id=$id
}

                                                                    Matteo Baccan   12
                                        matteo@baccan.it – Jug Novara, PUG Novara
Come indicizzo? L'indice
index job {
   source         = job
   path           = ./data/job
   docinfo        = none
   mlock          =0
   morphology     = none
   min_word_len   =1
   charset_type   = sbcs
   html_strip     =0
}

                                                             Matteo Baccan   13
                                 matteo@baccan.it – Jug Novara, PUG Novara
Come indicizzo? L'indexer
indexer.exe job
Sphinx 2.0.4-id64-release (r3135)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, Sphinx Technologies Inc (http://sphinxsearch.com)
using config file './sphinx.conf'...
indexing index 'job'...
collected 125565 docs, 61.9 MB
sorted 8.9 Mhits, 100.0% done
total 125565 docs, 61894430 bytes
total 7.319 sec, 8456618 bytes/sec, 17155.91 docs/sec
total 2 reads, 0.155 sec, 12707.9 kb/call avg, 77.6 msec/call avg
total 67 writes, 0.258 sec, 890.2 kb/call avg, 3.8 msec/call avg
                                                                           Matteo Baccan   14
                                               matteo@baccan.it – Jug Novara, PUG Novara
Come cerco?
• Da riga comando con Search
• Lanciando il demone SearchD e interrogandolo
  con
  – SphinxAPI (PHP, Java e altri)
  – SphinxQL : tramite SQL
  – SphinxSE : MySQL storage engine

                                                        Matteo Baccan   15
                            matteo@baccan.it – Jug Novara, PUG Novara
SphinxAPI - Java
SphinxClient cl = new SphinxClient( "localhost", 3307 );
SphinxResult res = cl.Query("j2ee php", "job");
if ( res!=null ) {
   for ( int i=0; i<res.matches.length; i++ ) {
      SphinxMatch info = res.matches[i];
      System.out.println( (i+1) + ". id=" + info.docId );
   }
}
                                                                Matteo Baccan   16
                                    matteo@baccan.it – Jug Novara, PUG Novara
SphinxAPI - PHP
require ( "sphinxapi.php" );
$cl = new SphinxClient ();
$cl->SetServer( "127.0.0.1", 3307 ); $cl->SetArrayResult ( true );
$res = $cl->Query( "j2ee php", "job" );
if ( $res ) {
    $n = 0;
    foreach ( $res["matches"] as $docinfo ) {
       $n++; print "$n. doc_id=$docinfo[id]<br/>";
    }
}

                                                                        Matteo Baccan   17
                                            matteo@baccan.it – Jug Novara, PUG Novara
SphinxQL
Sphinx è in grado di emulare il protocollo MySQL
Al suo interno è presente un interprete SQL

            MySQL non è più necessario

Molti client sono in grado di usare Sphinx come se
fosse un server MySQL
                                                           Matteo Baccan   18
                               matteo@baccan.it – Jug Novara, PUG Novara
SphinxQL - JDBC
Connection conn =
DriverManager.getConnection("jdbc:mysql://127.0.0.1:3308");
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from job
where match('j2ee php')");
while( rs.next() )
  System.out.println( rs.getString(1) );


                                                             Matteo Baccan   19
                                 matteo@baccan.it – Jug Novara, PUG Novara
SphinxSE
• Occorre ricompilare MySQL
  – Oppure scaricarlo da http://www.coreseek.cn
• Si verifica guardando gli
  engine installati
    SHOW ENGINES



                                                          Matteo Baccan   20
                              matteo@baccan.it – Jug Novara, PUG Novara
SphinxSE
CREATE TABLE jobsp (
   id       BIGINT,
   weight   INTEGER NOT NULL,
   query    VARCHAR(3072) NOT NULL,
   group_id INTEGER,
   INDEX(query)
) ENGINE=SPHINX
CONNECTION="sphinx://localhost:3307/job";
                                                           Matteo Baccan   21
                               matteo@baccan.it – Jug Novara, PUG Novara
SphinxSE
La tabella si usa mettendola in Join con la
tabella contenente i dati, indicando come query
il dato da cercare
SELECT job.id, titolo FROM job
JOIN jobsp ON (job.id=jobsp.id)
WHERE QUERY='j2ee php;mode=any';

                                                     Matteo Baccan   22
                         matteo@baccan.it – Jug Novara, PUG Novara
Indici distribuiti
• In caso di alto traffico, è possibile creare indici
  dati dalla somma dei risultati di differenti
  istanze di Sphinx e indici locali
• Quello che varia, rispetto all'indice standard, è
  la dichiarazione di agent di ricerca, al posto/in
  concomitanza di indici fisici

                                                          Matteo Baccan   23
                              matteo@baccan.it – Jug Novara, PUG Novara
Indici distribuiti – nodo master
index job {
   type       = distributed

    agent      = localhost:3310:job
    agent      = localhost:3311:job

    agent_connect_timeout     = 1000
    agent_query_timeout       = 3000
}

                                                                   Matteo Baccan   24
                                       matteo@baccan.it – Jug Novara, PUG Novara
Indici distribuiti – interrogazione nodi
java -jar sphinxapi.jar -p 3310 -i job j2ee php
  'j2ee' found 1005 times in 632 documents
  'php' found 337 times in 255 documents


java -jar sphinxapi.jar -p 3311 -i job j2ee php
  'j2ee' found 933 times in 598 documents
  'php' found 371 times in 268 documents
                                                         Matteo Baccan   25
                             matteo@baccan.it – Jug Novara, PUG Novara
Indici distribuiti – interrogazione master
java -jar sphinxapi.jar -p 3312 -i job j2ee php
  'j2ee' found 1938 times in 1230 documents
  'php' found 708 times in 523 documents




                                                       Matteo Baccan   26
                           matteo@baccan.it – Jug Novara, PUG Novara
RT Index (RealTime)
• Indici dinamici in grado di gestire
  – INSERT
  – UPDATE
  – DELETE
  – SELECT
• Più dinamici, ma tendono a degradare le performance
  per frammentazione e su grandi quantità di dati


                                                               Matteo Baccan   27
                                   matteo@baccan.it – Jug Novara, PUG Novara
RT Index
index rt {
   type           = rt
   path           = data/rt
   rt_field       = descrizione # full text
   rt_attr_uint   = gid
}
                                                        Matteo Baccan   28
                            matteo@baccan.it – Jug Novara, PUG Novara
RT Index
Non è MySQL è Sphinx

Class.forName("org.gjt.mm.mysql.Driver");
Connection conn =
DriverManager.getConnection("jdbc:mysql://127.0.0.1:3320");
Statement stmt = conn.createStatement();
      stmt.execute("delete from rt where id in(1,2,3)");
      stmt.execute("insert into rt values(1,'primo record' ,100)");
      stmt.execute("insert into rt values(2,'secondo record',111)");
      stmt.execute("insert into rt values(3,'terzo record' ,122)");

                                                                         Matteo Baccan   29
                                             matteo@baccan.it – Jug Novara, PUG Novara
RT Index
mysql -h 127.0.0.1 -P 3320
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 1
Server version: 2.0.4-id64-release (r3135)

Type 'help;' or 'h' for help. Type 'c' to clear the buffer.

mysql>
                                                                    Matteo Baccan   30
                                        matteo@baccan.it – Jug Novara, PUG Novara
RT Index
mysql> select * from rt;
+------+--------+------+
| id   | weight | gid |
+------+--------+------+
|    1 |      1 | 100 |
|    2 |      1 | 111 |
|    3 |      1 | 122 |
+------+--------+------+
3 rows in set (0.00 sec)

mysql> select * from rt where match('secondo');
+------+--------+------+
| id   | weight | gid |
+------+--------+------+
|    2 |   1680 | 111 |
+------+--------+------+
1 row in set (0.00 sec)


                                                                              Matteo Baccan   31
                                                  matteo@baccan.it – Jug Novara, PUG Novara
Di cosa non abbiamo parlato
•   XMLPipe datasource
•   Main e Delta index
•   Index merge
•   Stopwords
•   Wordforms
•   Sorting Mode
•   Group by
•   …. e molte altre cose ...
                                                            Matteo Baccan   32
                                matteo@baccan.it – Jug Novara, PUG Novara
Matteo Baccan   33
matteo@baccan.it – Jug Novara, PUG Novara
Qualche link
• http://www.sphinxsearch.com/       Sphinx (source, info)
• http://www.coreseek.cn/news/14/99/ SphinxSE (binari)
• http://www.moonlab.it              Cosa facciamo
• http://www.baccan.it                    Cosa faccio




                                                               Matteo Baccan   34
                                   matteo@baccan.it – Jug Novara, PUG Novara
Matteo Baccan

matteo@baccan.it



                             Matteo Baccan   35
 matteo@baccan.it – Jug Novara, PUG Novara

Weitere ähnliche Inhalte

Andere mochten auch

Learning Pool Finance: E-learning for budget managers
Learning Pool Finance:  E-learning for budget managersLearning Pool Finance:  E-learning for budget managers
Learning Pool Finance: E-learning for budget managersPaul McElvaney
 
Webinar: Upravljanje poslom - produktivnost u praksi
Webinar: Upravljanje poslom - produktivnost u praksiWebinar: Upravljanje poslom - produktivnost u praksi
Webinar: Upravljanje poslom - produktivnost u praksiMaja Vujovic
 
Webtech 2010: facebook framework
Webtech 2010: facebook frameworkWebtech 2010: facebook framework
Webtech 2010: facebook frameworkMatteo Baccan
 
Presentatie Starterslift Breda - Online marketing
Presentatie Starterslift Breda - Online marketingPresentatie Starterslift Breda - Online marketing
Presentatie Starterslift Breda - Online marketingSjef Kerkhofs
 
Phpday 2009 php e java
Phpday 2009 php e javaPhpday 2009 php e java
Phpday 2009 php e javaMatteo Baccan
 
Niver Paula - 28.11.07
Niver Paula - 28.11.07Niver Paula - 28.11.07
Niver Paula - 28.11.07Jubrac Jacui
 
lezing Online netwerken
lezing Online netwerkenlezing Online netwerken
lezing Online netwerkenSjef Kerkhofs
 
Lezing valid webversie
Lezing valid webversieLezing valid webversie
Lezing valid webversieSjef Kerkhofs
 
Introduction to chef framework
Introduction to chef frameworkIntroduction to chef framework
Introduction to chef frameworkmorgoth
 
Семинар по генным сетям. Mirob.
Семинар по генным сетям. Mirob.Семинар по генным сетям. Mirob.
Семинар по генным сетям. Mirob.bifurcafe
 
Paragraphs and topic sentences
Paragraphs and topic sentencesParagraphs and topic sentences
Paragraphs and topic sentencesSussan Roo
 
Joanne jacobs at LP2010
Joanne jacobs at LP2010Joanne jacobs at LP2010
Joanne jacobs at LP2010Paul McElvaney
 
Aag presentatie 3 februari
Aag presentatie 3 februariAag presentatie 3 februari
Aag presentatie 3 februariSjef Kerkhofs
 
Learning Pool: What you ought to know about www.learningpool.com
Learning Pool: What you ought to know about www.learningpool.com Learning Pool: What you ought to know about www.learningpool.com
Learning Pool: What you ought to know about www.learningpool.com Paul McElvaney
 
Ficha de Dados Pessoais 2010 8º ano
Ficha de Dados Pessoais 2010 8º anoFicha de Dados Pessoais 2010 8º ano
Ficha de Dados Pessoais 2010 8º anoNelson Silva
 
Best practices for_scaling_java_applications_with_distributed_caching
Best practices for_scaling_java_applications_with_distributed_cachingBest practices for_scaling_java_applications_with_distributed_caching
Best practices for_scaling_java_applications_with_distributed_cachingyamingd
 
Lcu14 wrap up meeting. Summary of Core Develoment teams achievements
Lcu14 wrap up meeting. Summary of Core Develoment teams achievementsLcu14 wrap up meeting. Summary of Core Develoment teams achievements
Lcu14 wrap up meeting. Summary of Core Develoment teams achievementsAgustin Benito Bethencourt
 

Andere mochten auch (20)

Learning Pool Finance: E-learning for budget managers
Learning Pool Finance:  E-learning for budget managersLearning Pool Finance:  E-learning for budget managers
Learning Pool Finance: E-learning for budget managers
 
Social media and job search
Social media and job searchSocial media and job search
Social media and job search
 
Webinar: Upravljanje poslom - produktivnost u praksi
Webinar: Upravljanje poslom - produktivnost u praksiWebinar: Upravljanje poslom - produktivnost u praksi
Webinar: Upravljanje poslom - produktivnost u praksi
 
Webtech 2010: facebook framework
Webtech 2010: facebook frameworkWebtech 2010: facebook framework
Webtech 2010: facebook framework
 
I gala premios peridotita
I gala premios peridotitaI gala premios peridotita
I gala premios peridotita
 
Presentatie Starterslift Breda - Online marketing
Presentatie Starterslift Breda - Online marketingPresentatie Starterslift Breda - Online marketing
Presentatie Starterslift Breda - Online marketing
 
Tema ii
Tema iiTema ii
Tema ii
 
Phpday 2009 php e java
Phpday 2009 php e javaPhpday 2009 php e java
Phpday 2009 php e java
 
Niver Paula - 28.11.07
Niver Paula - 28.11.07Niver Paula - 28.11.07
Niver Paula - 28.11.07
 
lezing Online netwerken
lezing Online netwerkenlezing Online netwerken
lezing Online netwerken
 
Lezing valid webversie
Lezing valid webversieLezing valid webversie
Lezing valid webversie
 
Introduction to chef framework
Introduction to chef frameworkIntroduction to chef framework
Introduction to chef framework
 
Семинар по генным сетям. Mirob.
Семинар по генным сетям. Mirob.Семинар по генным сетям. Mirob.
Семинар по генным сетям. Mirob.
 
Paragraphs and topic sentences
Paragraphs and topic sentencesParagraphs and topic sentences
Paragraphs and topic sentences
 
Joanne jacobs at LP2010
Joanne jacobs at LP2010Joanne jacobs at LP2010
Joanne jacobs at LP2010
 
Aag presentatie 3 februari
Aag presentatie 3 februariAag presentatie 3 februari
Aag presentatie 3 februari
 
Learning Pool: What you ought to know about www.learningpool.com
Learning Pool: What you ought to know about www.learningpool.com Learning Pool: What you ought to know about www.learningpool.com
Learning Pool: What you ought to know about www.learningpool.com
 
Ficha de Dados Pessoais 2010 8º ano
Ficha de Dados Pessoais 2010 8º anoFicha de Dados Pessoais 2010 8º ano
Ficha de Dados Pessoais 2010 8º ano
 
Best practices for_scaling_java_applications_with_distributed_caching
Best practices for_scaling_java_applications_with_distributed_cachingBest practices for_scaling_java_applications_with_distributed_caching
Best practices for_scaling_java_applications_with_distributed_caching
 
Lcu14 wrap up meeting. Summary of Core Develoment teams achievements
Lcu14 wrap up meeting. Summary of Core Develoment teams achievementsLcu14 wrap up meeting. Summary of Core Develoment teams achievements
Lcu14 wrap up meeting. Summary of Core Develoment teams achievements
 

Ähnlich wie Codemotion 2012 : Sphinx: Open Source Search Server

Elasticsearch a quick introduction
Elasticsearch a quick introductionElasticsearch a quick introduction
Elasticsearch a quick introductionFederico Panini
 
MongoDb and Scala SpringFramework Meeting
MongoDb and Scala SpringFramework MeetingMongoDb and Scala SpringFramework Meeting
MongoDb and Scala SpringFramework Meetingguest67beeb9
 
SQL Saturday 2019 - Event Processing with Spark
SQL Saturday 2019 - Event Processing with SparkSQL Saturday 2019 - Event Processing with Spark
SQL Saturday 2019 - Event Processing with SparkAlessio Biasiutti
 
Diventare famosi con lo stack ELK - Alfonso Iannotta
Diventare famosi con lo stack ELK - Alfonso IannottaDiventare famosi con lo stack ELK - Alfonso Iannotta
Diventare famosi con lo stack ELK - Alfonso IannottaData Driven Innovation
 
PostgrSQL 9.3&9.4 - DjangoVillage
PostgrSQL 9.3&9.4 - DjangoVillagePostgrSQL 9.3&9.4 - DjangoVillage
PostgrSQL 9.3&9.4 - DjangoVillageMiriade Spa
 
Back to Basics, webinar 6: Messa in esercizio
Back to Basics, webinar 6: Messa in esercizioBack to Basics, webinar 6: Messa in esercizio
Back to Basics, webinar 6: Messa in esercizioMongoDB
 
Elasticsearch in architetture Big Data - EsInADay-2017
Elasticsearch in architetture Big Data - EsInADay-2017Elasticsearch in architetture Big Data - EsInADay-2017
Elasticsearch in architetture Big Data - EsInADay-2017Alberto Paro
 
LinuxDay2013 - Web2py: make the web easier
LinuxDay2013 - Web2py: make the web easierLinuxDay2013 - Web2py: make the web easier
LinuxDay2013 - Web2py: make the web easierDavide Marzioni
 
Come l’Open Source può essere alla base di un business di successo: il caso H...
Come l’Open Source può essere alla base di un business di successo: il caso H...Come l’Open Source può essere alla base di un business di successo: il caso H...
Come l’Open Source può essere alla base di un business di successo: il caso H...MariaDB plc
 
CDays15 - AZ08 - DocumentDB: il NoSql secondo Azure
CDays15 - AZ08 - DocumentDB: il NoSql secondo AzureCDays15 - AZ08 - DocumentDB: il NoSql secondo Azure
CDays15 - AZ08 - DocumentDB: il NoSql secondo AzureDavide Benvegnù
 
Progettazione di uno strumento per la reingegnerizzazione di applicazioni legacy
Progettazione di uno strumento per la reingegnerizzazione di applicazioni legacyProgettazione di uno strumento per la reingegnerizzazione di applicazioni legacy
Progettazione di uno strumento per la reingegnerizzazione di applicazioni legacyGiacomo Russo
 
How create a single page apps using html5 and javascript
How create a single page apps using html5 and javascript How create a single page apps using html5 and javascript
How create a single page apps using html5 and javascript Stefano Marchisio
 
Big data analytics quanto vale e come sfruttarlo con stream analytics e power bi
Big data analytics quanto vale e come sfruttarlo con stream analytics e power biBig data analytics quanto vale e come sfruttarlo con stream analytics e power bi
Big data analytics quanto vale e come sfruttarlo con stream analytics e power biMarco Pozzan
 
Json Web Tokens
Json Web TokensJson Web Tokens
Json Web TokensNaLUG
 
Back to Basics, webinar 1: Introduzione a NoSQL
Back to Basics, webinar 1: Introduzione a NoSQLBack to Basics, webinar 1: Introduzione a NoSQL
Back to Basics, webinar 1: Introduzione a NoSQLMongoDB
 
SQL Saturday 871 - Sardegna 2019 - SQL Server DR on Azure
SQL Saturday 871 - Sardegna 2019 - SQL Server DR on AzureSQL Saturday 871 - Sardegna 2019 - SQL Server DR on Azure
SQL Saturday 871 - Sardegna 2019 - SQL Server DR on AzureMarco Obinu
 
javaday 2006 - Tiger
javaday 2006 - Tigerjavaday 2006 - Tiger
javaday 2006 - TigerMatteo Baccan
 
Dynamic Language Programming For The Statically Typed Programmer
Dynamic Language Programming For The Statically Typed ProgrammerDynamic Language Programming For The Statically Typed Programmer
Dynamic Language Programming For The Statically Typed ProgrammerMarco Parenzan
 
JWT: JSON Web Tokens - bye bye Session and Cookie - RFC7519
JWT: JSON Web Tokens - bye bye Session and Cookie - RFC7519JWT: JSON Web Tokens - bye bye Session and Cookie - RFC7519
JWT: JSON Web Tokens - bye bye Session and Cookie - RFC7519Mario Rossano
 

Ähnlich wie Codemotion 2012 : Sphinx: Open Source Search Server (20)

Elasticsearch a quick introduction
Elasticsearch a quick introductionElasticsearch a quick introduction
Elasticsearch a quick introduction
 
MongoDb and Scala SpringFramework Meeting
MongoDb and Scala SpringFramework MeetingMongoDb and Scala SpringFramework Meeting
MongoDb and Scala SpringFramework Meeting
 
SQL Saturday 2019 - Event Processing with Spark
SQL Saturday 2019 - Event Processing with SparkSQL Saturday 2019 - Event Processing with Spark
SQL Saturday 2019 - Event Processing with Spark
 
Diventare famosi con lo stack ELK - Alfonso Iannotta
Diventare famosi con lo stack ELK - Alfonso IannottaDiventare famosi con lo stack ELK - Alfonso Iannotta
Diventare famosi con lo stack ELK - Alfonso Iannotta
 
PostgrSQL 9.3&9.4 - DjangoVillage
PostgrSQL 9.3&9.4 - DjangoVillagePostgrSQL 9.3&9.4 - DjangoVillage
PostgrSQL 9.3&9.4 - DjangoVillage
 
Back to Basics, webinar 6: Messa in esercizio
Back to Basics, webinar 6: Messa in esercizioBack to Basics, webinar 6: Messa in esercizio
Back to Basics, webinar 6: Messa in esercizio
 
Elasticsearch in architetture Big Data - EsInADay-2017
Elasticsearch in architetture Big Data - EsInADay-2017Elasticsearch in architetture Big Data - EsInADay-2017
Elasticsearch in architetture Big Data - EsInADay-2017
 
LinuxDay2013 - Web2py: make the web easier
LinuxDay2013 - Web2py: make the web easierLinuxDay2013 - Web2py: make the web easier
LinuxDay2013 - Web2py: make the web easier
 
Come l’Open Source può essere alla base di un business di successo: il caso H...
Come l’Open Source può essere alla base di un business di successo: il caso H...Come l’Open Source può essere alla base di un business di successo: il caso H...
Come l’Open Source può essere alla base di un business di successo: il caso H...
 
Mashlight
MashlightMashlight
Mashlight
 
CDays15 - AZ08 - DocumentDB: il NoSql secondo Azure
CDays15 - AZ08 - DocumentDB: il NoSql secondo AzureCDays15 - AZ08 - DocumentDB: il NoSql secondo Azure
CDays15 - AZ08 - DocumentDB: il NoSql secondo Azure
 
Progettazione di uno strumento per la reingegnerizzazione di applicazioni legacy
Progettazione di uno strumento per la reingegnerizzazione di applicazioni legacyProgettazione di uno strumento per la reingegnerizzazione di applicazioni legacy
Progettazione di uno strumento per la reingegnerizzazione di applicazioni legacy
 
How create a single page apps using html5 and javascript
How create a single page apps using html5 and javascript How create a single page apps using html5 and javascript
How create a single page apps using html5 and javascript
 
Big data analytics quanto vale e come sfruttarlo con stream analytics e power bi
Big data analytics quanto vale e come sfruttarlo con stream analytics e power biBig data analytics quanto vale e come sfruttarlo con stream analytics e power bi
Big data analytics quanto vale e come sfruttarlo con stream analytics e power bi
 
Json Web Tokens
Json Web TokensJson Web Tokens
Json Web Tokens
 
Back to Basics, webinar 1: Introduzione a NoSQL
Back to Basics, webinar 1: Introduzione a NoSQLBack to Basics, webinar 1: Introduzione a NoSQL
Back to Basics, webinar 1: Introduzione a NoSQL
 
SQL Saturday 871 - Sardegna 2019 - SQL Server DR on Azure
SQL Saturday 871 - Sardegna 2019 - SQL Server DR on AzureSQL Saturday 871 - Sardegna 2019 - SQL Server DR on Azure
SQL Saturday 871 - Sardegna 2019 - SQL Server DR on Azure
 
javaday 2006 - Tiger
javaday 2006 - Tigerjavaday 2006 - Tiger
javaday 2006 - Tiger
 
Dynamic Language Programming For The Statically Typed Programmer
Dynamic Language Programming For The Statically Typed ProgrammerDynamic Language Programming For The Statically Typed Programmer
Dynamic Language Programming For The Statically Typed Programmer
 
JWT: JSON Web Tokens - bye bye Session and Cookie - RFC7519
JWT: JSON Web Tokens - bye bye Session and Cookie - RFC7519JWT: JSON Web Tokens - bye bye Session and Cookie - RFC7519
JWT: JSON Web Tokens - bye bye Session and Cookie - RFC7519
 

Mehr von Matteo Baccan

Matteo Baccan - Valerio Tognozzi - Novara LinuxDay 2015
Matteo Baccan - Valerio Tognozzi - Novara LinuxDay 2015Matteo Baccan - Valerio Tognozzi - Novara LinuxDay 2015
Matteo Baccan - Valerio Tognozzi - Novara LinuxDay 2015Matteo Baccan
 
Matteo baccan raspberry pi - linox 2015 - corso parte 3
Matteo baccan   raspberry pi - linox 2015 - corso parte 3Matteo baccan   raspberry pi - linox 2015 - corso parte 3
Matteo baccan raspberry pi - linox 2015 - corso parte 3Matteo Baccan
 
Matteo baccan raspberry pi - linox 2015 - corso parte 2
Matteo baccan   raspberry pi - linox 2015 - corso parte 2Matteo baccan   raspberry pi - linox 2015 - corso parte 2
Matteo baccan raspberry pi - linox 2015 - corso parte 2Matteo Baccan
 
Matteo baccan raspberry pi - linox 2015 - corso parte 1
Matteo baccan   raspberry pi - linox 2015 - corso parte 1Matteo baccan   raspberry pi - linox 2015 - corso parte 1
Matteo baccan raspberry pi - linox 2015 - corso parte 1Matteo Baccan
 
Creazione di una stazione meteo con prodotti opensource. Linux day 2014 - Lin...
Creazione di una stazione meteo con prodotti opensource. Linux day 2014 - Lin...Creazione di una stazione meteo con prodotti opensource. Linux day 2014 - Lin...
Creazione di una stazione meteo con prodotti opensource. Linux day 2014 - Lin...Matteo Baccan
 
Matteo baccan raspberry pi - linox 2014
Matteo baccan   raspberry pi - linox 2014Matteo baccan   raspberry pi - linox 2014
Matteo baccan raspberry pi - linox 2014Matteo Baccan
 
Codemotion 2014 : ottimizzare JAVA e PHP su un’architettura Raspberry Pi Cluster
Codemotion 2014 : ottimizzare JAVA e PHP su un’architettura Raspberry Pi ClusterCodemotion 2014 : ottimizzare JAVA e PHP su un’architettura Raspberry Pi Cluster
Codemotion 2014 : ottimizzare JAVA e PHP su un’architettura Raspberry Pi ClusterMatteo Baccan
 
Javaday 2009 php e java
Javaday 2009 php e javaJavaday 2009 php e java
Javaday 2009 php e javaMatteo Baccan
 
Confsl 2010 Facebook Framework
Confsl 2010 Facebook FrameworkConfsl 2010 Facebook Framework
Confsl 2010 Facebook FrameworkMatteo Baccan
 
Codemotion 2013: Succo di lampone: come ottimizzare JAVA e PHP su un’architet...
Codemotion 2013: Succo di lampone: come ottimizzare JAVA e PHP su un’architet...Codemotion 2013: Succo di lampone: come ottimizzare JAVA e PHP su un’architet...
Codemotion 2013: Succo di lampone: come ottimizzare JAVA e PHP su un’architet...Matteo Baccan
 
Stack Overflow meetup html2pop3
Stack Overflow meetup html2pop3 Stack Overflow meetup html2pop3
Stack Overflow meetup html2pop3 Matteo Baccan
 
Codemotion twitter programming
Codemotion twitter programmingCodemotion twitter programming
Codemotion twitter programmingMatteo Baccan
 
Webtech 2010: twitter programming
Webtech 2010: twitter programmingWebtech 2010: twitter programming
Webtech 2010: twitter programmingMatteo Baccan
 
Webbit 2004: Tiger, java
Webbit 2004: Tiger, javaWebbit 2004: Tiger, java
Webbit 2004: Tiger, javaMatteo Baccan
 
Webbit 2004: Aspectj
Webbit 2004: AspectjWebbit 2004: Aspectj
Webbit 2004: AspectjMatteo Baccan
 
JIPDay 2005: Xlet Java Programming
JIPDay 2005: Xlet Java ProgrammingJIPDay 2005: Xlet Java Programming
JIPDay 2005: Xlet Java ProgrammingMatteo Baccan
 
Javaday 2006: Java 5
Javaday 2006: Java 5Javaday 2006: Java 5
Javaday 2006: Java 5Matteo Baccan
 
Javaday 2007: skype4java
Javaday 2007: skype4javaJavaday 2007: skype4java
Javaday 2007: skype4javaMatteo Baccan
 
Phpday 2010: facebook php framework
Phpday 2010: facebook php frameworkPhpday 2010: facebook php framework
Phpday 2010: facebook php frameworkMatteo Baccan
 

Mehr von Matteo Baccan (20)

Gmail e google app
Gmail e google appGmail e google app
Gmail e google app
 
Matteo Baccan - Valerio Tognozzi - Novara LinuxDay 2015
Matteo Baccan - Valerio Tognozzi - Novara LinuxDay 2015Matteo Baccan - Valerio Tognozzi - Novara LinuxDay 2015
Matteo Baccan - Valerio Tognozzi - Novara LinuxDay 2015
 
Matteo baccan raspberry pi - linox 2015 - corso parte 3
Matteo baccan   raspberry pi - linox 2015 - corso parte 3Matteo baccan   raspberry pi - linox 2015 - corso parte 3
Matteo baccan raspberry pi - linox 2015 - corso parte 3
 
Matteo baccan raspberry pi - linox 2015 - corso parte 2
Matteo baccan   raspberry pi - linox 2015 - corso parte 2Matteo baccan   raspberry pi - linox 2015 - corso parte 2
Matteo baccan raspberry pi - linox 2015 - corso parte 2
 
Matteo baccan raspberry pi - linox 2015 - corso parte 1
Matteo baccan   raspberry pi - linox 2015 - corso parte 1Matteo baccan   raspberry pi - linox 2015 - corso parte 1
Matteo baccan raspberry pi - linox 2015 - corso parte 1
 
Creazione di una stazione meteo con prodotti opensource. Linux day 2014 - Lin...
Creazione di una stazione meteo con prodotti opensource. Linux day 2014 - Lin...Creazione di una stazione meteo con prodotti opensource. Linux day 2014 - Lin...
Creazione di una stazione meteo con prodotti opensource. Linux day 2014 - Lin...
 
Matteo baccan raspberry pi - linox 2014
Matteo baccan   raspberry pi - linox 2014Matteo baccan   raspberry pi - linox 2014
Matteo baccan raspberry pi - linox 2014
 
Codemotion 2014 : ottimizzare JAVA e PHP su un’architettura Raspberry Pi Cluster
Codemotion 2014 : ottimizzare JAVA e PHP su un’architettura Raspberry Pi ClusterCodemotion 2014 : ottimizzare JAVA e PHP su un’architettura Raspberry Pi Cluster
Codemotion 2014 : ottimizzare JAVA e PHP su un’architettura Raspberry Pi Cluster
 
Javaday 2009 php e java
Javaday 2009 php e javaJavaday 2009 php e java
Javaday 2009 php e java
 
Confsl 2010 Facebook Framework
Confsl 2010 Facebook FrameworkConfsl 2010 Facebook Framework
Confsl 2010 Facebook Framework
 
Codemotion 2013: Succo di lampone: come ottimizzare JAVA e PHP su un’architet...
Codemotion 2013: Succo di lampone: come ottimizzare JAVA e PHP su un’architet...Codemotion 2013: Succo di lampone: come ottimizzare JAVA e PHP su un’architet...
Codemotion 2013: Succo di lampone: come ottimizzare JAVA e PHP su un’architet...
 
Stack Overflow meetup html2pop3
Stack Overflow meetup html2pop3 Stack Overflow meetup html2pop3
Stack Overflow meetup html2pop3
 
Codemotion twitter programming
Codemotion twitter programmingCodemotion twitter programming
Codemotion twitter programming
 
Webtech 2010: twitter programming
Webtech 2010: twitter programmingWebtech 2010: twitter programming
Webtech 2010: twitter programming
 
Webbit 2004: Tiger, java
Webbit 2004: Tiger, javaWebbit 2004: Tiger, java
Webbit 2004: Tiger, java
 
Webbit 2004: Aspectj
Webbit 2004: AspectjWebbit 2004: Aspectj
Webbit 2004: Aspectj
 
JIPDay 2005: Xlet Java Programming
JIPDay 2005: Xlet Java ProgrammingJIPDay 2005: Xlet Java Programming
JIPDay 2005: Xlet Java Programming
 
Javaday 2006: Java 5
Javaday 2006: Java 5Javaday 2006: Java 5
Javaday 2006: Java 5
 
Javaday 2007: skype4java
Javaday 2007: skype4javaJavaday 2007: skype4java
Javaday 2007: skype4java
 
Phpday 2010: facebook php framework
Phpday 2010: facebook php frameworkPhpday 2010: facebook php framework
Phpday 2010: facebook php framework
 

Codemotion 2012 : Sphinx: Open Source Search Server

  • 1. Sphinx: Open Source Search Server Matteo Baccan matteo@baccan.it Jug Novara, PUG Novara
  • 2. Sphinx: Open Source Search Server • Relatore: Matteo Baccan • Area: Open Source • Target: Expert, Developer, Power User • Difficoltà: Media-Bassa Sporchiamoci le mani con un'alternativa a Lucene e MySQL. Un prodotto OpenSource, portabile, veloce, attento alle prestazioni e ai consumi di spazio e memoria. Vedremo come distribuire il carico, come effettuare hotswap di indici, come usare lo stesso JDBC per accedere a MySQL e Sphinx, come gestire indici dinamici e statici. Utilizzeremo query, subquery, strategia di ricerca diverse. Studieremo le migliori tecniche per indicizzare milioni di documenti, il tutto tramite PHP e JAVA su casi reali Da 0 a 100 in 40 minuti, allacciate le cinture ;) Matteo Baccan 2 matteo@baccan.it – Jug Novara, PUG Novara
  • 3. Chi sono? Divulgatore informatico, giornalista per riviste tecniche nazionali oltre 700 articoli per :Dev, Login, Computer Programming, Mokabyte. Relatore tecnico ad eventi di programmazione: Borland Forum 2000, Webbit 2004, JIP day 2005, Javaday (2006,2007,2010) PHPDay (2008, 2010), CONFSL 2010, WebTech 2010, Codemotin (2011,2012). Autore di Corso di C# ISBN 8881500167. Autore di JobCrawler e HTML2POP3 (Oltre 900.000 download su SourceForge) Matteo Baccan 3 matteo@baccan.it – Jug Novara, PUG Novara
  • 4. Cos'è Sphinx? • Acronimo di SQL Phrase Index • Un motore di ricerca “full text” • Un “emulatore” MySQL • Veloce, Compatto, Scalabile Matteo Baccan 4 matteo@baccan.it – Jug Novara, PUG Novara
  • 5. Perché usare Sphinx? • Uso già MySQL/Lucene/Solr no • Uso Lucene in deep no • Uso Lucene, ma è lento a indicizzare forse • Ho molto spazio allocato dagli indici forse • Con java non conosco alternative forse • Devo convertire molto codice SQL si • Non ho un motore di ricerca si • Ho bisogno di una soluzione veloce si Matteo Baccan 5 matteo@baccan.it – Jug Novara, PUG Novara
  • 6. Alcuni numeri? • 10-1000x volte più veloce di MySQL sulle ricerche full-text – MySQL è veloce solo con gli indici in RAM) • 2-3x volte più veloce sulle ricerche non full-text – Sphinx ha meno feature da supportare ;) • 2-4x volte più veloce di Lucene sulle ricerche full-text [fonte Sphinx Technologies Inc.] ;) Matteo Baccan 6 matteo@baccan.it – Jug Novara, PUG Novara
  • 7. Risultati rilevanti • Sphinx ha diversi algoritmi per il calcolo del rank – phrase proximity (aka LCS) : posizione delle parole – BM25 : frequenza delle parole La combinazione di questi algoritmi può variare la qualità dei dati cercati Matteo Baccan 7 matteo@baccan.it – Jug Novara, PUG Novara
  • 8. Alcuni algoritmi di rilevanza • SPH_RANK_PROXIMITY_BM25: combina LCS e BM25 • SPH_RANK_BM25: solo BM25 • SPH_RANK_NONE: nessun rank • SPH_RANK_WORDCOUNT: solo per numero di parole, in base alla priorità dei campi • SPH_RANK_SPH04: LCS e BM25, ma portando in testa gli exact match • SPH_RANK_EXPR: basato su espressione Matteo Baccan 8 matteo@baccan.it – Jug Novara, PUG Novara
  • 9. Ma chi lo usa? • boardreader.com, 1.000.000 query/day, 16.000.000.000 documenti, 5TB, 27 sphinx box • craigslist.org, 200.000.000 query/day (2.000 al secondo) 15 sphinx box http://sphinxsearch.com/info/powered/ • moonlab.it network: 500.000 query/day, 10.000.000 documenti, 300 millesimi tempo medio di risposta 2 sphinx box bilanciate da macchine dual core con 4g di RAM (con jboss, mysql, sphinx e altri processi in concorrenza) Matteo Baccan 9 matteo@baccan.it – Jug Novara, PUG Novara
  • 10. Architettura base • sphinx.conf file di configurazione • Indexer indicizzatore • SearchD demone di ricerca • Search ricerca command line Matteo Baccan 10 matteo@baccan.it – Jug Novara, PUG Novara
  • 11. Come indicizzo? • Definisco un datasource : connessione e stringa di selezione dei dati • Definisco un indice: posizione nel file system e tipologia • Indicizzo: dico all'indexer di creare l'indice appena definito Matteo Baccan 11 matteo@baccan.it – Jug Novara, PUG Novara
  • 12. Come indicizzo? Il datasource source job { type = mysql sql_host = localhost sql_user = sphinx sql_pass = sql_db = jobcrawler sql_port = 3306 sql_query = SELECT id, descrizione FROM `job` sql_query_info = SELECT id, titolo FROM job WHERE id=$id } Matteo Baccan 12 matteo@baccan.it – Jug Novara, PUG Novara
  • 13. Come indicizzo? L'indice index job { source = job path = ./data/job docinfo = none mlock =0 morphology = none min_word_len =1 charset_type = sbcs html_strip =0 } Matteo Baccan 13 matteo@baccan.it – Jug Novara, PUG Novara
  • 14. Come indicizzo? L'indexer indexer.exe job Sphinx 2.0.4-id64-release (r3135) Copyright (c) 2001-2012, Andrew Aksyonoff Copyright (c) 2008-2012, Sphinx Technologies Inc (http://sphinxsearch.com) using config file './sphinx.conf'... indexing index 'job'... collected 125565 docs, 61.9 MB sorted 8.9 Mhits, 100.0% done total 125565 docs, 61894430 bytes total 7.319 sec, 8456618 bytes/sec, 17155.91 docs/sec total 2 reads, 0.155 sec, 12707.9 kb/call avg, 77.6 msec/call avg total 67 writes, 0.258 sec, 890.2 kb/call avg, 3.8 msec/call avg Matteo Baccan 14 matteo@baccan.it – Jug Novara, PUG Novara
  • 15. Come cerco? • Da riga comando con Search • Lanciando il demone SearchD e interrogandolo con – SphinxAPI (PHP, Java e altri) – SphinxQL : tramite SQL – SphinxSE : MySQL storage engine Matteo Baccan 15 matteo@baccan.it – Jug Novara, PUG Novara
  • 16. SphinxAPI - Java SphinxClient cl = new SphinxClient( "localhost", 3307 ); SphinxResult res = cl.Query("j2ee php", "job"); if ( res!=null ) { for ( int i=0; i<res.matches.length; i++ ) { SphinxMatch info = res.matches[i]; System.out.println( (i+1) + ". id=" + info.docId ); } } Matteo Baccan 16 matteo@baccan.it – Jug Novara, PUG Novara
  • 17. SphinxAPI - PHP require ( "sphinxapi.php" ); $cl = new SphinxClient (); $cl->SetServer( "127.0.0.1", 3307 ); $cl->SetArrayResult ( true ); $res = $cl->Query( "j2ee php", "job" ); if ( $res ) { $n = 0; foreach ( $res["matches"] as $docinfo ) { $n++; print "$n. doc_id=$docinfo[id]<br/>"; } } Matteo Baccan 17 matteo@baccan.it – Jug Novara, PUG Novara
  • 18. SphinxQL Sphinx è in grado di emulare il protocollo MySQL Al suo interno è presente un interprete SQL MySQL non è più necessario Molti client sono in grado di usare Sphinx come se fosse un server MySQL Matteo Baccan 18 matteo@baccan.it – Jug Novara, PUG Novara
  • 19. SphinxQL - JDBC Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3308"); Statement stmt = conn.createStatement(); ResultSet rs = stmt.executeQuery("select * from job where match('j2ee php')"); while( rs.next() ) System.out.println( rs.getString(1) ); Matteo Baccan 19 matteo@baccan.it – Jug Novara, PUG Novara
  • 20. SphinxSE • Occorre ricompilare MySQL – Oppure scaricarlo da http://www.coreseek.cn • Si verifica guardando gli engine installati SHOW ENGINES Matteo Baccan 20 matteo@baccan.it – Jug Novara, PUG Novara
  • 21. SphinxSE CREATE TABLE jobsp ( id BIGINT, weight INTEGER NOT NULL, query VARCHAR(3072) NOT NULL, group_id INTEGER, INDEX(query) ) ENGINE=SPHINX CONNECTION="sphinx://localhost:3307/job"; Matteo Baccan 21 matteo@baccan.it – Jug Novara, PUG Novara
  • 22. SphinxSE La tabella si usa mettendola in Join con la tabella contenente i dati, indicando come query il dato da cercare SELECT job.id, titolo FROM job JOIN jobsp ON (job.id=jobsp.id) WHERE QUERY='j2ee php;mode=any'; Matteo Baccan 22 matteo@baccan.it – Jug Novara, PUG Novara
  • 23. Indici distribuiti • In caso di alto traffico, è possibile creare indici dati dalla somma dei risultati di differenti istanze di Sphinx e indici locali • Quello che varia, rispetto all'indice standard, è la dichiarazione di agent di ricerca, al posto/in concomitanza di indici fisici Matteo Baccan 23 matteo@baccan.it – Jug Novara, PUG Novara
  • 24. Indici distribuiti – nodo master index job { type = distributed agent = localhost:3310:job agent = localhost:3311:job agent_connect_timeout = 1000 agent_query_timeout = 3000 } Matteo Baccan 24 matteo@baccan.it – Jug Novara, PUG Novara
  • 25. Indici distribuiti – interrogazione nodi java -jar sphinxapi.jar -p 3310 -i job j2ee php 'j2ee' found 1005 times in 632 documents 'php' found 337 times in 255 documents java -jar sphinxapi.jar -p 3311 -i job j2ee php 'j2ee' found 933 times in 598 documents 'php' found 371 times in 268 documents Matteo Baccan 25 matteo@baccan.it – Jug Novara, PUG Novara
  • 26. Indici distribuiti – interrogazione master java -jar sphinxapi.jar -p 3312 -i job j2ee php 'j2ee' found 1938 times in 1230 documents 'php' found 708 times in 523 documents Matteo Baccan 26 matteo@baccan.it – Jug Novara, PUG Novara
  • 27. RT Index (RealTime) • Indici dinamici in grado di gestire – INSERT – UPDATE – DELETE – SELECT • Più dinamici, ma tendono a degradare le performance per frammentazione e su grandi quantità di dati Matteo Baccan 27 matteo@baccan.it – Jug Novara, PUG Novara
  • 28. RT Index index rt { type = rt path = data/rt rt_field = descrizione # full text rt_attr_uint = gid } Matteo Baccan 28 matteo@baccan.it – Jug Novara, PUG Novara
  • 29. RT Index Non è MySQL è Sphinx Class.forName("org.gjt.mm.mysql.Driver"); Connection conn = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3320"); Statement stmt = conn.createStatement(); stmt.execute("delete from rt where id in(1,2,3)"); stmt.execute("insert into rt values(1,'primo record' ,100)"); stmt.execute("insert into rt values(2,'secondo record',111)"); stmt.execute("insert into rt values(3,'terzo record' ,122)"); Matteo Baccan 29 matteo@baccan.it – Jug Novara, PUG Novara
  • 30. RT Index mysql -h 127.0.0.1 -P 3320 Welcome to the MySQL monitor. Commands end with ; or g. Your MySQL connection id is 1 Server version: 2.0.4-id64-release (r3135) Type 'help;' or 'h' for help. Type 'c' to clear the buffer. mysql> Matteo Baccan 30 matteo@baccan.it – Jug Novara, PUG Novara
  • 31. RT Index mysql> select * from rt; +------+--------+------+ | id | weight | gid | +------+--------+------+ | 1 | 1 | 100 | | 2 | 1 | 111 | | 3 | 1 | 122 | +------+--------+------+ 3 rows in set (0.00 sec) mysql> select * from rt where match('secondo'); +------+--------+------+ | id | weight | gid | +------+--------+------+ | 2 | 1680 | 111 | +------+--------+------+ 1 row in set (0.00 sec) Matteo Baccan 31 matteo@baccan.it – Jug Novara, PUG Novara
  • 32. Di cosa non abbiamo parlato • XMLPipe datasource • Main e Delta index • Index merge • Stopwords • Wordforms • Sorting Mode • Group by • …. e molte altre cose ... Matteo Baccan 32 matteo@baccan.it – Jug Novara, PUG Novara
  • 33. Matteo Baccan 33 matteo@baccan.it – Jug Novara, PUG Novara
  • 34. Qualche link • http://www.sphinxsearch.com/ Sphinx (source, info) • http://www.coreseek.cn/news/14/99/ SphinxSE (binari) • http://www.moonlab.it Cosa facciamo • http://www.baccan.it Cosa faccio Matteo Baccan 34 matteo@baccan.it – Jug Novara, PUG Novara
  • 35. Matteo Baccan matteo@baccan.it Matteo Baccan 35 matteo@baccan.it – Jug Novara, PUG Novara