SlideShare uma empresa Scribd logo
1 de 17
Sphinxsearch 1.10
Část 1 – základy
http://sphinxsearch.com/docs/manual-1.10
Úvod
• Fulltextové hledání
• Linux daemon
• Hlednání
– TCP socket (9312)
– SphinxQL – odnož sql jazyka
– SphinxSE – ukladání indexu do samotné DB od 5.1
• API pro PHP, Perl, Ruby, Java
DB
• MySQL
• PostgreSQL
• ODBC
– MS SQL
– Oracle
– atd.
• První pole určuje identifikátor řádku
• Další pole sloupce pro hledání, pokud není určeno jinak
ID Pole1 Pole2 Pole3
1 Monitor Asus nejaka verze 100 Pobocka1 1
2 Asus Monitor verze 100 nejaka Pobocka2 0
3 Monitor Asus modra verze s puntíky Pobocka1 1
4 Monitor Asus modra verze s puntíky Pobocka2 1
Konfigurace - Source
source [jmeno_indexu]
{
type = mysql
sql_host = host
sql_user = user
sql_pass = password
sql_db= db
sql_port = 3306 # optional, default is 3306
sql_query_pre = SET NAMES utf8
sql_query = SELECT id, pole1, pole2, pole3 FROM tabulka;
sql_attr_uint = pole3
sql_query_info = SELECT id, pole1, pole2 FROM products WHERE id=$id
}
Konfigurace - Source
type - typ DB
sql_host , sql_user, sql_pass, sql_db, sql_port – pripojeni k DB
sql_query_pre – co provést před indexací
sql_query_post_index – co provést po indexaci
sql_query - dotaz k indexování
sql_attr_uint, sql_attr_bool, sql_attr_bigint, sql_attr_float – atributy k nastavení hledání
sql_query_info – pouze pro CLI
sql_ranged_throttle – pauza mezi generovanim SQL dotazu
Konfigurace - Index
index [jmeno_indexu]
{
charset_type = utf-8
charset_table = U+FF10..U+FF19->0..9, U+FF21..U+FF3A->a..z,U+FF41..U+FF5A->a..z, 0..9,
A..Z->a..z, a..z atd...
source = [jmeno_indexu]
path = [cesta_k_souboru]
enable_star = 1
morphology = stem_cz
min_word_len = 1
min_prefix_len = 1
min_infix_len = 1
}
Konfigurace - Index
source - zdroj dat indexu
path - kam uložit
enable_star - povolit wildcards
morphology - zda upravit tvar uložených slov (psi, pes => pes )
min_word_len - min. délka slova k indexaci
min_prefix_len - min. délka předpony slova pro indexaci
min_infix_len - zda indexovat části slova a jaký počet
stopwords - co neidexovat (stopwords = stopwords-cz.txt stopwords-en.txt)
wordforms - zkratky (core 2 duo > c2d, procesor > c2d, ...)
(wordforms = /usr/local/sphinx/data/wordforms.txt)
prefix_fields - pro které sloupce zpracovat předpony (prefix_fields = pole1, pole2)
infix_fields - pro které sloupce zpracovat části slov (infix_fields = pole1, pole2)
CLI
• indexer [volby] [jmeno_indexu]
– Indexer [jmeno_indexu]
– Indexer --rotate [jmeno_indexu]
– Indexer -- rotate --all
• search [volby] [co_hledame]
– search –i [jmeno_indexu] [vyraz]
• -a = any
• -p = phrase
• -ext = extended
• searchd - daemon
• /etc/init.d/sphinx restart | start | stop
– netstat -nat | grep 9312 (tcp 0 0 0.0.0.0:9312 0.0.0.0:* LISTEN)
– telnet localhost 3312
Hledání
ALL
• výchozí nastavení
• vrátí záznam pouze po shodě všech slov z předaného výrazu
• SPH_MATCH_ANY
ANY
• vrátí záznam při libovolné shodě z předaného výrazu
• SPH_MATCH_ALL
PHRASE
• Vrátí záznam při přesné schodě
• SPH_MATCH_PHRASE
Hledání
Boolean
• Vrátí záznamy vyhovující schodě předaným výrazem
• SPH_MATCH_BOOLEAN (&, |, - !)
• SELECT id, pole1, pole2 FROM tabulka
(nejaka | puntiky) – vrátí vše
(nejaka & puntiky) – nevratí nic
(monitor -pobocka1) – vrátí id 2,4
ID Pole1 Pole2 Pole3
1 Monitor Asus nejaka verze 100 Pobocka1 1
2 Asus Monitor verze 100 nejaka Pobocka2 0
3 Monitor Asus modra verze s puntíky Pobocka1 1
4 Monitor Asus modra verze s puntíky Pobocka2 1
Hledání
Extended
• Vrátí záznamy vyhovující schodě předaným výrazem
• SPH_MATCH_EXTENDED (&, |, - !) + plus „sphinx operatory“
• Více na http://sphinxsearch.com/docs/manual-1.10.html#extended-syntax
Váha(relevance),Třídění
Váha
• Záleží na módu hledání
– phrase rank
– statistical rank
• BOOLEAN - váha se neurčuje
• ALL, PHRASE – součet jednotlivých vah nalezenych slov
• ANY – stejně jako ALL ale navíc se bere v úvahu váha jednotlivých sloupců
• EXTENDED – podobně jako ANY, plus se bere v úvahu výsledek váha algoritmu BM25
Třídění
• Relevance
• Definovaného atributu
• Času
• Matematického výrazu
PHP API
• sphinxapi - třída dodaná autorem
– http://code.google.com/p/sphinxsearch/source/browse/trunk/api/?r=2014
– http://sphinxsearch.com/docs/manual-1.10.html#api-reference
• PECL – ShinxClient
– http://www.php.net/manual/en/class.sphinxclient.php
PHP API – příklad
• require_once(“sphinxapi.php“);
• $clCode = new SphinxClient();
• $clCode->SetServer( “localhost“, 9312);
• $clCode->SetLimits(0,99999);
• $clCode->SetMatchMode( SPH_MATCH_ANY );
• $clCode->SetFieldWeights(array(“pole1“ =>20, “pole2“=>1));
• $clCode->SetFilter ( “pole3“, array(“pobocka2“) );
• $resultCode = $clCode->Query( “monitor“, “test“ );
$resultCode[“matches“] = array
1=>Array(
“weight“=> 1000,
“attrs“=> array()
),
2=>Array(…),
PHP API – příklad
• $result_ids = array_key($resultCode[“matches“]);
• $sql = “SELECT id,pole1,pole2 FROM tabulka WHERE id IN (“ . Implode(“,“, $result_ids) . “)“;
Pak další zpracování
Závěr
• Dotazy …

Mais conteúdo relacionado

Destaque

Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
Kurio // The Social Media Age(ncy)
 

Destaque (20)

PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 
12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work12 Ways to Increase Your Influence at Work
12 Ways to Increase Your Influence at Work
 
ChatGPT webinar slides
ChatGPT webinar slidesChatGPT webinar slides
ChatGPT webinar slides
 
More than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike RoutesMore than Just Lines on a Map: Best Practices for U.S Bike Routes
More than Just Lines on a Map: Best Practices for U.S Bike Routes
 
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
Ride the Storm: Navigating Through Unstable Periods / Katerina Rudko (Belka G...
 
Barbie - Brand Strategy Presentation
Barbie - Brand Strategy PresentationBarbie - Brand Strategy Presentation
Barbie - Brand Strategy Presentation
 

Sphinxsearch by Pavel Severýn

  • 1. Sphinxsearch 1.10 Část 1 – základy http://sphinxsearch.com/docs/manual-1.10
  • 2. Úvod • Fulltextové hledání • Linux daemon • Hlednání – TCP socket (9312) – SphinxQL – odnož sql jazyka – SphinxSE – ukladání indexu do samotné DB od 5.1 • API pro PHP, Perl, Ruby, Java
  • 3. DB • MySQL • PostgreSQL • ODBC – MS SQL – Oracle – atd.
  • 4. • První pole určuje identifikátor řádku • Další pole sloupce pro hledání, pokud není určeno jinak ID Pole1 Pole2 Pole3 1 Monitor Asus nejaka verze 100 Pobocka1 1 2 Asus Monitor verze 100 nejaka Pobocka2 0 3 Monitor Asus modra verze s puntíky Pobocka1 1 4 Monitor Asus modra verze s puntíky Pobocka2 1
  • 5. Konfigurace - Source source [jmeno_indexu] { type = mysql sql_host = host sql_user = user sql_pass = password sql_db= db sql_port = 3306 # optional, default is 3306 sql_query_pre = SET NAMES utf8 sql_query = SELECT id, pole1, pole2, pole3 FROM tabulka; sql_attr_uint = pole3 sql_query_info = SELECT id, pole1, pole2 FROM products WHERE id=$id }
  • 6. Konfigurace - Source type - typ DB sql_host , sql_user, sql_pass, sql_db, sql_port – pripojeni k DB sql_query_pre – co provést před indexací sql_query_post_index – co provést po indexaci sql_query - dotaz k indexování sql_attr_uint, sql_attr_bool, sql_attr_bigint, sql_attr_float – atributy k nastavení hledání sql_query_info – pouze pro CLI sql_ranged_throttle – pauza mezi generovanim SQL dotazu
  • 7. Konfigurace - Index index [jmeno_indexu] { charset_type = utf-8 charset_table = U+FF10..U+FF19->0..9, U+FF21..U+FF3A->a..z,U+FF41..U+FF5A->a..z, 0..9, A..Z->a..z, a..z atd... source = [jmeno_indexu] path = [cesta_k_souboru] enable_star = 1 morphology = stem_cz min_word_len = 1 min_prefix_len = 1 min_infix_len = 1 }
  • 8. Konfigurace - Index source - zdroj dat indexu path - kam uložit enable_star - povolit wildcards morphology - zda upravit tvar uložených slov (psi, pes => pes ) min_word_len - min. délka slova k indexaci min_prefix_len - min. délka předpony slova pro indexaci min_infix_len - zda indexovat části slova a jaký počet stopwords - co neidexovat (stopwords = stopwords-cz.txt stopwords-en.txt) wordforms - zkratky (core 2 duo > c2d, procesor > c2d, ...) (wordforms = /usr/local/sphinx/data/wordforms.txt) prefix_fields - pro které sloupce zpracovat předpony (prefix_fields = pole1, pole2) infix_fields - pro které sloupce zpracovat části slov (infix_fields = pole1, pole2)
  • 9. CLI • indexer [volby] [jmeno_indexu] – Indexer [jmeno_indexu] – Indexer --rotate [jmeno_indexu] – Indexer -- rotate --all • search [volby] [co_hledame] – search –i [jmeno_indexu] [vyraz] • -a = any • -p = phrase • -ext = extended • searchd - daemon • /etc/init.d/sphinx restart | start | stop – netstat -nat | grep 9312 (tcp 0 0 0.0.0.0:9312 0.0.0.0:* LISTEN) – telnet localhost 3312
  • 10. Hledání ALL • výchozí nastavení • vrátí záznam pouze po shodě všech slov z předaného výrazu • SPH_MATCH_ANY ANY • vrátí záznam při libovolné shodě z předaného výrazu • SPH_MATCH_ALL PHRASE • Vrátí záznam při přesné schodě • SPH_MATCH_PHRASE
  • 11. Hledání Boolean • Vrátí záznamy vyhovující schodě předaným výrazem • SPH_MATCH_BOOLEAN (&, |, - !) • SELECT id, pole1, pole2 FROM tabulka (nejaka | puntiky) – vrátí vše (nejaka & puntiky) – nevratí nic (monitor -pobocka1) – vrátí id 2,4 ID Pole1 Pole2 Pole3 1 Monitor Asus nejaka verze 100 Pobocka1 1 2 Asus Monitor verze 100 nejaka Pobocka2 0 3 Monitor Asus modra verze s puntíky Pobocka1 1 4 Monitor Asus modra verze s puntíky Pobocka2 1
  • 12. Hledání Extended • Vrátí záznamy vyhovující schodě předaným výrazem • SPH_MATCH_EXTENDED (&, |, - !) + plus „sphinx operatory“ • Více na http://sphinxsearch.com/docs/manual-1.10.html#extended-syntax
  • 13. Váha(relevance),Třídění Váha • Záleží na módu hledání – phrase rank – statistical rank • BOOLEAN - váha se neurčuje • ALL, PHRASE – součet jednotlivých vah nalezenych slov • ANY – stejně jako ALL ale navíc se bere v úvahu váha jednotlivých sloupců • EXTENDED – podobně jako ANY, plus se bere v úvahu výsledek váha algoritmu BM25 Třídění • Relevance • Definovaného atributu • Času • Matematického výrazu
  • 14. PHP API • sphinxapi - třída dodaná autorem – http://code.google.com/p/sphinxsearch/source/browse/trunk/api/?r=2014 – http://sphinxsearch.com/docs/manual-1.10.html#api-reference • PECL – ShinxClient – http://www.php.net/manual/en/class.sphinxclient.php
  • 15. PHP API – příklad • require_once(“sphinxapi.php“); • $clCode = new SphinxClient(); • $clCode->SetServer( “localhost“, 9312); • $clCode->SetLimits(0,99999); • $clCode->SetMatchMode( SPH_MATCH_ANY ); • $clCode->SetFieldWeights(array(“pole1“ =>20, “pole2“=>1)); • $clCode->SetFilter ( “pole3“, array(“pobocka2“) ); • $resultCode = $clCode->Query( “monitor“, “test“ ); $resultCode[“matches“] = array 1=>Array( “weight“=> 1000, “attrs“=> array() ), 2=>Array(…),
  • 16. PHP API – příklad • $result_ids = array_key($resultCode[“matches“]); • $sql = “SELECT id,pole1,pole2 FROM tabulka WHERE id IN (“ . Implode(“,“, $result_ids) . “)“; Pak další zpracování