Ludicrous001 / Ludicrous001/StackOverflowOffline

SQL Queries for search are slow

Open
#2 0 comments 0 reactions 1 assignee View on GitHub

@Ludicrous001 is already working on this.

Since May 18, 2018.

bug help wanted
Dominant language
JavaScript
Stars
4
Forks
0
PR merge metrics
No merged PRs in 30d

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.