Ludicrous001 / Ludicrous001/StackOverflowOffline

SQL Queries for search are slow

Aperta
#2 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

@Ludicrous001 ci sta già lavorando.

Dal 18/5/2018.

bug help wanted
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 command
SELECT * 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

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.