Ludicrous001 / Ludicrous001/StackOverflowOffline
SQL Queries for search are slow
@Ludicrous001 ci sta già lavorando.
Dal 18/5/2018.
- Lingua principale
- JavaScript
- Stelle
- 4
- Fork
- 0
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
SQL Queries for search are slow
I wonder if I have to include a tags table in the database to improve the query speed
// If the user has typed in search terms, require all search terms to be in the title
else {
var search_terms_split = search_terms.split('+')
sql_query = 'SELECT * FROM posts WHERE '
for (var i = 0; i < search_terms_split.length; i++) {
sql_query += "LOWER(title) LIKE '%" + search_terms_split[i].toLowerCase() + "%' AND "
}
sql_query = sql_query.substring(0, sql_query.length - 4);
sql_query += ' LIMIT ' + questions_per_page + ' OFFSET ' + questions_per_page*page_number
}
// Example querry:
// SELECT * FROM posts WHERE LOWER(title) LIKE '%python%' AND LOWER(title) LIKE '%cmd%' LIMIT 5 OFFSET 0
I've also tried this sql commandSELECT * FROM posts WHERE LOWER(title) ~ '\spython\s' AND LOWER(title) ~ '\scmd\s' LIMIT 5 OFFSET 0
I've learned that I think I need to create an INDEX for the title column... https://www.postgresql.org/docs/9.5/static/textsearch.html
I've tried creating Indexes CREATE INDEX posts_tags ON public.posts USING hash (tags); and various forms of that command... like using btree, or indexing on the title instead of the tag... Making some progress I think
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Valutazione
Questa issue non è ancora stata valutata.