SlideShare une entreprise Scribd logo
1  sur  65
Télécharger pour lire hors ligne
Mateusz Herych
Android Developer - Base CRM
Co-organizer - GDG Krakow
Co-organizer - KrakDroid
Stats
LIKE ‘%smth%’
LIKE ‘%smth%’
is not the way.
Search
Search
Offline.
Why?
Why?
Let the backend guys do the job
Why?
Internet is not everywhere.
Why?
Internet is not everywhere.
It takes time. (especially SSL)
Why?
Internet is not everywhere.
It takes time. (especially SSL)
And sometimes it’s shitty.
Why?
Internet is not everywhere.
It takes time. (especially SSL)
And sometimes it’s shitty.
Sure, some apps don’
t really need it
You need an Internet to order
that taxi anyway
Do you keep offline
content?
Let your users navigate fast.
Did I say fast?
How?
Let’s go deeper.
Context
CRM
- Contacts
- Deals
- Notes
- ...
CRM
- Contacts (~100)
- Deals (~50)
- Notes (~100)
- ...2011
select id from deals where name LIKE ‘%
something%’
CRM
- Contacts (~40K)
- Deals (~20K)
- Notes (~300K)
- ...
HOW DOES “LIKE” WORKS
LIKE?
Docs saying
I tried to put all the
conditions that need to be
satisfied so SQLite can use
indices combined with LIKE
operator.
Docs saying
They didn’t fit.
Docs saying
http://www.sqlite.
org/optoverview.html
Docs saying
Hey, you, SQLite!
EXPLAIN (my) QUERY PLAN
PRAGMA case_sensitive_like=1;
PRAGMA case_sensitive_like=1;
CREATE INDEX search_index on deals(name);
PRAGMA case_sensitive_like=1;
CREATE INDEX search_index on deals(name);
SELECT id FROM deals WHERE name LIKE
‘Some%’;
EXPLAIN QUERY PLAN
SELECT id FROM deals WHERE
name LIKE ‘Some%’;
SEARCH TABLE deals USING COVERING
INDEX search_index (name>? AND name<?)
(~31250 rows)
EXPLAIN QUERY PLAN
SELECT id FROM deals WHERE
name LIKE ‘%Some%’;
EXPLAIN QUERY PLAN
SELECT id FROM deals WHERE
name LIKE ‘%Some%’;
SCAN TABLE deals (~500000 rows)
EXPLAIN QUERY PLAN
SELECT id FROM deals WHERE
name LIKE ‘%Some%’;
SCAN TABLE deals (~500000 rows)
(And then you die)
first_name || ‘ ‘ || last_name?
complicated queries, VIEWs?
Like is NOT the way
to go.
What people think SQLite is
What SQLite really is
SQLite is
powerful
Not kidding.
FTS3
Full Text Search
CREATE VIRTUAL TABLE
search USING fts3 (tokens)
?
CREATE VIRTUAL TABLE
search USING fts3 (tokens INT)
Nope.
PRAGMA table_info(search);
cid|name|type|notnull|dflt_value|pk
0|word||0||0
All is TEXT, except for hidden
rowid.
What is virtual table?
Imagine it’s a Java interface.
interface VirtualTable {
void insert(Params p);
void update(Params p);
// etc, also createTable.
}
What is a virtual table?
class Fts3 implements VirtualTable {
// …
}
MATCH
Let’s go make some magic.
SELECT * FROM search WHERE
content MATCH ‘something’
SELECT rowid, * FROM search
WHERE content MATCH
‘something’
rowid|word
1|something
2|not something special
3|SoMeThInG
SELECT rowid, * FROM search
WHERE content
MATCH ‘some* spe*’
rowid|word
2|not something special
CREATE VIRTUAL TABLE
search USING fts3 (author, lyrics)
SELECT * FROM search WHERE
lyrics
MATCH ‘author:Giorgio Synthesizer
author |lyrics
Giorgio Moroder|..Why don’t I use a
synthesizer...
Cool?
Cool?
Look at this.
SELECT * FROM search WHERE
lyrics
MATCH ‘why NEAR synthesizer’
author |lyrics
Giorgio Moroder|..Why don’t I use
synthesizer...
SELECT * FROM search WHERE
lyrics
MATCH ‘why NEAR/3 synthesizer’
author |lyrics
Giorgio Moroder|..Why don’t I use
synthesizer...
Tips.
1. Your FTS vtable should contain
only tokens. Divided into sections.
2. Link your FTS table’s records
with other table (containing real
object’s id and type) using rowid.
3. Remember. FTS is fast enough
for searching purposes. But it’s
always slower than ‘=’ based query
on indexed field.
4. EXPLAIN QUERY PLAN doesn’t
work for fts tables. Try to measure
it with .timer ON.
5. ???
6. QUESTIONS TIME!

Contenu connexe

Similaire à Mateusz herych content search problem on android

Creative Data Analysis with Python
Creative Data Analysis with PythonCreative Data Analysis with Python
Creative Data Analysis with Python
Grant Paton-Simpson
 
Rocky Nevin's presentation at eComm 2008
Rocky Nevin's presentation at eComm 2008Rocky Nevin's presentation at eComm 2008
Rocky Nevin's presentation at eComm 2008
eComm2008
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup Performance
Justin Cataldo
 

Similaire à Mateusz herych content search problem on android (20)

Extreme Swift
Extreme SwiftExtreme Swift
Extreme Swift
 
Tools and Tips: From Accidental to Efficient Data Warehouse Developer (SQLSat...
Tools and Tips: From Accidental to Efficient Data Warehouse Developer (SQLSat...Tools and Tips: From Accidental to Efficient Data Warehouse Developer (SQLSat...
Tools and Tips: From Accidental to Efficient Data Warehouse Developer (SQLSat...
 
Intro to PySpark: Python Data Analysis at scale in the Cloud
Intro to PySpark: Python Data Analysis at scale in the CloudIntro to PySpark: Python Data Analysis at scale in the Cloud
Intro to PySpark: Python Data Analysis at scale in the Cloud
 
When to no sql and when to know sql javaone
When to no sql and when to know sql   javaoneWhen to no sql and when to know sql   javaone
When to no sql and when to know sql javaone
 
Web Application Hacking
Web Application HackingWeb Application Hacking
Web Application Hacking
 
Coding Ajax
Coding AjaxCoding Ajax
Coding Ajax
 
The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016The Road To Reactive with RxJava JEEConf 2016
The Road To Reactive with RxJava JEEConf 2016
 
Tools and Tips: From Accidental to Efficient Data Warehouse Developer (SQLBit...
Tools and Tips: From Accidental to Efficient Data Warehouse Developer (SQLBit...Tools and Tips: From Accidental to Efficient Data Warehouse Developer (SQLBit...
Tools and Tips: From Accidental to Efficient Data Warehouse Developer (SQLBit...
 
Working with Complex Types in DataFrames: Optics to the Rescue
Working with Complex Types in DataFrames: Optics to the RescueWorking with Complex Types in DataFrames: Optics to the Rescue
Working with Complex Types in DataFrames: Optics to the Rescue
 
Reinventing the Transaction Script (NDC London 2020)
Reinventing the Transaction Script (NDC London 2020)Reinventing the Transaction Script (NDC London 2020)
Reinventing the Transaction Script (NDC London 2020)
 
Creative Data Analysis with Python
Creative Data Analysis with PythonCreative Data Analysis with Python
Creative Data Analysis with Python
 
Collaboration between LINE, Microsoft and AI by the developers, for the devel...
Collaboration between LINE, Microsoft and AI by the developers, for the devel...Collaboration between LINE, Microsoft and AI by the developers, for the devel...
Collaboration between LINE, Microsoft and AI by the developers, for the devel...
 
Rocky Nevin's presentation at eComm 2008
Rocky Nevin's presentation at eComm 2008Rocky Nevin's presentation at eComm 2008
Rocky Nevin's presentation at eComm 2008
 
CrossLanguageSpotter: A Library for Detecting Relations in Polyglot Frameworks
CrossLanguageSpotter: A Library for Detecting Relations in Polyglot FrameworksCrossLanguageSpotter: A Library for Detecting Relations in Polyglot Frameworks
CrossLanguageSpotter: A Library for Detecting Relations in Polyglot Frameworks
 
#NewMeetup Performance
#NewMeetup Performance#NewMeetup Performance
#NewMeetup Performance
 
Coding Ajax
Coding AjaxCoding Ajax
Coding Ajax
 
Social media analytics using Azure Technologies
Social media analytics using Azure TechnologiesSocial media analytics using Azure Technologies
Social media analytics using Azure Technologies
 
The Art of Clean code
The Art of Clean codeThe Art of Clean code
The Art of Clean code
 
Javascript leverage: Isomorphic Applications by Luciano Colosio at Codemotion...
Javascript leverage: Isomorphic Applications by Luciano Colosio at Codemotion...Javascript leverage: Isomorphic Applications by Luciano Colosio at Codemotion...
Javascript leverage: Isomorphic Applications by Luciano Colosio at Codemotion...
 
Back to the future: Isomorphic javascript applications
Back to the future:  Isomorphic javascript applicationsBack to the future:  Isomorphic javascript applications
Back to the future: Isomorphic javascript applications
 

Plus de apps4allru

демьянов олег Wa особенности разработки детских приложений - практические с...
демьянов олег Wa   особенности разработки детских приложений - практические с...демьянов олег Wa   особенности разработки детских приложений - практические с...
демьянов олег Wa особенности разработки детских приложений - практические с...
apps4allru
 
Jose l ugia 6 wunderkinder, momenta
Jose l ugia  6 wunderkinder, momentaJose l ugia  6 wunderkinder, momenta
Jose l ugia 6 wunderkinder, momenta
apps4allru
 
Philipp kandal droidcon futureoflbs
Philipp kandal   droidcon futureoflbsPhilipp kandal   droidcon futureoflbs
Philipp kandal droidcon futureoflbs
apps4allru
 
Messerschmidt, tim
Messerschmidt, timMesserschmidt, tim
Messerschmidt, tim
apps4allru
 
Thibaut rouffineau
Thibaut rouffineauThibaut rouffineau
Thibaut rouffineau
apps4allru
 
писаревский алексей
писаревский алексейписаревский алексей
писаревский алексей
apps4allru
 
Joanna chwastowska responsive layout - droid con
Joanna chwastowska   responsive layout - droid conJoanna chwastowska   responsive layout - droid con
Joanna chwastowska responsive layout - droid con
apps4allru
 
зиновьев алексей Droid con(16_9) android geo apps_ in soviet russia latitude ...
зиновьев алексей Droid con(16_9) android geo apps_ in soviet russia latitude ...зиновьев алексей Droid con(16_9) android geo apps_ in soviet russia latitude ...
зиновьев алексей Droid con(16_9) android geo apps_ in soviet russia latitude ...
apps4allru
 
артем демьянов
артем демьяновартем демьянов
артем демьянов
apps4allru
 
резников дмитрий
резников дмитрийрезников дмитрий
резников дмитрий
apps4allru
 
михаил дударев
михаил дударевмихаил дударев
михаил дударев
apps4allru
 
Георгий Яковлев
Георгий ЯковлевГеоргий Яковлев
Георгий Яковлев
apps4allru
 
Алексей Исайченко
Алексей ИсайченкоАлексей Исайченко
Алексей Исайченко
apps4allru
 
митякин вадим
митякин вадиммитякин вадим
митякин вадим
apps4allru
 

Plus de apps4allru (15)

Alex negara
Alex negaraAlex negara
Alex negara
 
демьянов олег Wa особенности разработки детских приложений - практические с...
демьянов олег Wa   особенности разработки детских приложений - практические с...демьянов олег Wa   особенности разработки детских приложений - практические с...
демьянов олег Wa особенности разработки детских приложений - практические с...
 
Jose l ugia 6 wunderkinder, momenta
Jose l ugia  6 wunderkinder, momentaJose l ugia  6 wunderkinder, momenta
Jose l ugia 6 wunderkinder, momenta
 
Philipp kandal droidcon futureoflbs
Philipp kandal   droidcon futureoflbsPhilipp kandal   droidcon futureoflbs
Philipp kandal droidcon futureoflbs
 
Messerschmidt, tim
Messerschmidt, timMesserschmidt, tim
Messerschmidt, tim
 
Thibaut rouffineau
Thibaut rouffineauThibaut rouffineau
Thibaut rouffineau
 
писаревский алексей
писаревский алексейписаревский алексей
писаревский алексей
 
Joanna chwastowska responsive layout - droid con
Joanna chwastowska   responsive layout - droid conJoanna chwastowska   responsive layout - droid con
Joanna chwastowska responsive layout - droid con
 
зиновьев алексей Droid con(16_9) android geo apps_ in soviet russia latitude ...
зиновьев алексей Droid con(16_9) android geo apps_ in soviet russia latitude ...зиновьев алексей Droid con(16_9) android geo apps_ in soviet russia latitude ...
зиновьев алексей Droid con(16_9) android geo apps_ in soviet russia latitude ...
 
артем демьянов
артем демьяновартем демьянов
артем демьянов
 
резников дмитрий
резников дмитрийрезников дмитрий
резников дмитрий
 
михаил дударев
михаил дударевмихаил дударев
михаил дударев
 
Георгий Яковлев
Георгий ЯковлевГеоргий Яковлев
Георгий Яковлев
 
Алексей Исайченко
Алексей ИсайченкоАлексей Исайченко
Алексей Исайченко
 
митякин вадим
митякин вадиммитякин вадим
митякин вадим
 

Dernier

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Dernier (20)

Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...How to Choose the Right Laravel Development Partner in New York City_compress...
How to Choose the Right Laravel Development Partner in New York City_compress...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
The Guide to Integrating Generative AI into Unified Continuous Testing Platfo...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 

Mateusz herych content search problem on android