Writing by corra on Wednesday, 31 of January , 2007 at 7:05 pm
Iniziato oggi a sviluppare la sezione riservata per gli Inter Campus. In pratica le società affiliate all’Inter potranno accedere e scaricare giornalmente programmi e schemi di allenamento delle squadre del settore giovanile. Un servizio più volte richiesto e che presto sarà reso disponibile. Datemi solo una quindicina di giorni per sistemarlo.
Con l’occasione mi sono voluto far del male provando a gestire la generazione dinamica di alcuni campi tipo checkbox e similari mappati su colonne SET in MySQL. Un po’ macchinoso inizialmente, ma ho tratto qualche buono spunto per sviluppi futuri in AAS.
Comments Off Category: Lavoro
Writing by corra on Saturday, 27 of January , 2007 at 10:35 am
Answering yesterday to some newsgroup question about MySQL I have answered about the problem of the full-text searches in natural language.
Create and populate of a simple table with a full-text index.
mysql> create table ft_test(
-> id int not null auto_increment,
-> string text,
-> fulltext index(string),
-> primary key(id));
Query OK, 0 rows affected (0.09 sec)
mysql> insert into ft_test(string) values('forza inter'),('inter'),('viva inter'),('scudetto'),('champions league');
Query OK, 5 rows affected (0.10 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> select * from ft_test;
+----+------------------+
| id | string |
+----+------------------+
| 1 | forza inter |
| 2 | inter |
| 3 | viva inter |
| 4 | scudetto |
| 5 | champions league |
+----+------------------+
Let’s try first a search using the full-text index.
mysql> select * from ft_test where match(string) against('champions');
+----+------------------+
| id | string |
+----+------------------+
| 5 | champions league |
+----+------------------+
This is the expected result!
Try now the query.:
mysql> select * from ft_test where match(string) against('inter');
Empty set (0.00 sec)
It’s strange! I would expect 3 rows; the ones with the “inter” word. Why not?
The reason is that a simple full-text search operates a “NATURAL LANGUAGE” search (also searches “WITH QUERY EXPANSION” use the same mode).
In a “natural language” search, words that are frequently used, in more than 50% of the rows of the table, are considered as “stopwords”. They are considered as “not relevant” words, as the ones in the built-in stopword list.
Knowing that, let’s have a look to our table. The word “inter” is present in 3 rows in a 5-rows table. So, it’s more than 50%. A natural language will not retreive them according to its behaviour. Only a “IN BOOLEAN MODE” search will be able to retreive the word “inter”, because it’s not a built-in stopword.
mysql> select * from ft_test where match(string) against('inter' in boolean mode);
+----+-------------+
| id | string |
+----+-------------+
| 1 | forza inter |
| 2 | inter |
| 3 | viva inter |
+----+-------------+
Now, let’s try to add 2 more rows to the table in order to decrease the percentage of “inter” word presence below 50%.
mysql> insert into ft_test(string) values('Ibrahimovic santo subito'),('Panzaldo al Milan');
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
Re-run the query:
mysql> select * from ft_test where match(string) against('inter');
+----+-------------+
| id | string |
+----+-------------+
| 1 | forza inter |
| 3 | viva inter |
| 2 | inter |
+----+-------------+
OK, rows containing “inter” word are matched.
It’s not strange, it’s just the “natural language” search mode.
P.S. Inter is the name of a famous italian football club (http://www.inter.it)
Writing by corra on Friday, 26 of January , 2007 at 11:41 pm
Dal newsgroup oggi mi è arrivato uno strano problema con le ricerche fulltext.
Lo ripropongo.
Creo e popolo una semplice tabella.
mysql> create table ft_test(
-> id int not null auto_increment,
-> string text,
-> fulltext index(string),
-> primary key(id));
Query OK, 0 rows affected (0.09 sec)
mysql> insert into ft_test(string) values('forza inter'),('inter'),('viva inter'),('scudetto'),('champions league');
Query OK, 5 rows affected (0.10 sec)
Records: 5 Duplicates: 0 Warnings: 0
mysql> select * from ft_test;
+----+------------------+
| id | string |
+----+------------------+
| 1 | forza inter |
| 2 | inter |
| 3 | viva inter |
| 4 | scudetto |
| 5 | champions league |
+----+------------------+
Facciamo adesso un paio di ricerche
mysql> select * from ft_test where match(string) against('champions');
+----+------------------+
| id | string |
+----+------------------+
| 5 | champions league |
+----+------------------+
questa ha il risultato atteso!
Ma adesso facciamo questa ricerca:
mysql> select * from ft_test where match(string) against('inter');
Empty set (0.00 sec)
Non è stano? Non dovrebbero esserci 3 righe di risultato?
Il segreto sta nel fatto che, una ricerca fulltext senza modificatori (anche una con “with query expansion”) opera una ricerca detta in “NATURAL LANGUAGE”.
In una ricerca di tipo “natural language” le parole che sono presenti in più del 50% delle righe di una tabella non vengono considerate e indicizzate, in quanto considerate “troppo di uso comune” per avere rilevanza, esattamente come capita per le stopword comuni (verbi ausiliari, preposizioni articolate e compagnia bella).
Alla luce di quanto detto analizziamo la nostra tabella: la parola “inter” compare in 3 record su 5, quindi ben oltre il 50%. Quindi, con una ricerca “natural language” non sarà mai trovata, mentre con una in “boolean mode” lo sarà certamente.
mysql> select * from ft_test where match(string) against('inter' in boolean mode);
+----+-------------+
| id | string |
+----+-------------+
| 1 | forza inter |
| 2 | inter |
| 3 | viva inter |
+----+-------------+
Per finire, aggiungiamo due nuove righe con non contengano la parola “inter”, in modo da farne scendere l’incidenza al di sotto del 50%.
mysql> insert into ft_test(string) values('Ibrahimovic santo subito'),('Panzaldo al Milan');
Query OK, 2 rows affected (0.01 sec)
Records: 2 Duplicates: 0 Warnings: 0
Rifacciamo la query e vediamo ora cosa succede.
mysql> select * from ft_test where match(string) against('inter');
+----+-------------+
| id | string |
+----+-------------+
| 1 | forza inter |
| 3 | viva inter |
| 2 | inter |
+----+-------------+
C.V.D.
Comments Off Category: MySQL
Writing by corra on Friday, 26 of January , 2007 at 10:31 pm
Ho installato VMWare Player sul portatile e ho creato 4 macchine virtuali, tutte Debian. Installazione minimal.
Mi servono per fare un po’ di prove con MySQL Cluster.
Il portatile ha solo 512 MB di RAM e devo dire che con 4 Debian virtualizzate che girano sopra alla Ubuntu di base lo impiantano mica poco. Ho ridotto del 50% la memoria assegnata ad ogni Debian, ma la situazione non migliora molto. Mi sa che dovrò rivedere le prove almeno con una macchina in meno … o forse mi conviene prendere un portatile più nuovo e carrozzato?
Comments Off Category: Lavoro
Writing by corra on Wednesday, 24 of January , 2007 at 11:10 pm
Inter schiacciasassi. Risultato scontato e partita noiosa. Ormai sembra non esserci più niente e nessuno che possa fermarci.
Cena con Stew al Crazy Coconut. Defilati però, per non farci vedere!
Zuppa di cipolle, fegato al burro e salvia, vino rosso della casa, meneghina al Grand Marnier con gelato al torroncino, caffè. Anche per Stew la zuppa di cipolle e a seguire la solita fiorentina. Grazie di tutto amico “big trousers”.
I server funzionano bene, anche se Zio schizza subito ai suoi canonici 60/70 Mbps appena pubblico i filmati dei gol. Niente di nuovo comunque.