Note that there are some explanatory texts on larger screens.

plurals
  1. PO"Tag" searching/exclusion query design issue
    primarykey
    data
    text
    <p>Background: I'm working on a homebrew project for managing a collection of my own images, and have been trying to implement a tag-based search so I can easily sift through them.</p> <p>Right now, I'm working with RedBean's tagging API for applying tags to each image's database entry, however I'm stuck on a specific detail of my implementation; currently, to allow search of tags where multiple tags will refine the search (when searching for "ABC XYZ", tagged image must have tags "ABC" <em>and</em> "XYZ"), </p> <p>I'm having to handle some of the processing in the server-side language and not SQL, and then run an (optional) second query to verify that any returned images don't have a tag that has been explicitly excluded from results. (when searching for "ABC -XYZ", tagged image must have tag "ABC" and <strong>not</strong> "XYZ").</p> <p>The problem here is that my current method requires that I run all results by my server-side code, and makes any attempts at sensible pagination/result offsets inaccurate. </p> <p>My goal is to just grab the rows of the <code>post</code> table that contain the requested tags (and not contain any excluded tags) with one query, and still be able to use LIMIT/OFFSET arguments for my query to obtain reasonably paginated results.</p> <p>Table schemas is as follows:</p> <pre><code>Table "post" Columns: id (PRIMARY KEY for post table) (image metadata, not relevant to tag search) Table "tag" Columns: id (PRIMARY KEY for tag table) title (string of varying length - assume varchar(255)) Table "post_tag" Columns: id (PRIMARY KEY for post_tag table) post_id (associated with column "post.id") tag_id (associated with column "tag.id") </code></pre> <p>If possible, I'd like to also be able to have WHERE conditions specific to <code>post</code> table columns as well.</p> <p>What should I be using for query structure? I've been playing with left joins but haven't been able to get the exact structure I need to solve this.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload