Need help with SQL query. Keyword matching

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Need help with SQL query. Keyword matching

    Hi all,

    I have two tables:

    workgroups (wg_id, wg_name)
    workgroups_keywords (wgk_wg_id, wgk_keyword)

    Each workgroup has an associated list of one or more keywords.

    What I want do to at first was given a particular list of keywords bring back
    a list of workgroups that have at least one matching keyword associated with
    it.

    I have the following query:

    select distinct(wg_id), wg_name
    from workgroups, workgroups_keywords
    where
    wgk_keyword in (#QuotedValueList(Keywords.wgk_keyword)#)
    and
    wg_id = wgk_wg_id
    order by wg_name


    This works great.

    However, is there a way in a single query to order the returned rows by the
    number of keywords that are found to be matching (in other words an order by
    relevancy, the more keywords that match the more relevant the returned row)?

    Thanks in advance.

    David

    Trenchy Guest

  2. Similar Questions and Discussions

    1. Help with Keyword search
      Hi all, I've got a tricky query I hope you guys can help me with. I have a database of a few millions records, representing subjects from...
    2. keyword searching
      hi can anybody tell me how to create a search form on my database where a user would only have to type the first few letters of a paticular product...
    3. Keyword File
      G4 running 10.3 and Photoshop CS In both the cutline box and the keyword box AFTER you enter the cutlines and the keywords, if you look in the box...
    4. matching query.
      Hi all I know this should be easy, but I'm at a loss I want to match Help Help ## match this Helps ## not match this I am using...
    5. Keyword not supported
      Hi, I have an ASP app that queries MS Indexing Service. Below is my code. ############################# Imports System Imports...
  3. #2

    Default Re: Need help with SQL query. Keyword matching

    Hi David,

    You'll need to join a distinct list of the available keywords to the query:

    select count(k.keyword) as kwcount, ws_id,ws_name, k.wgk_keyword
    from workgroups,
    JOIN workgroups_keywords wk on wgk_wg_id = wg_id
    join (select distinct wgk_keyword from workgoups_keywords) k on k.wgk_keyword
    = wk.wgk_keyword
    where wgk_keyword IN(#QuotedValueList(Keywords.wgk_keyword)#)
    GROUP BY ws_id, ws_name
    order by wgk_keywor, kwcount DESC

    You may have to tweak this to get exactly what you want, but that's the
    ballpark idea.

    HTH,

    philh Guest

  4. #3

    Default Re: Need help with SQL query. Keyword matching

    This worked great:

    select distinct(wg_id), count(wg_id) as relevancy, wg_name
    from workgroups, workgroups_keywords
    where wgk_keyword in (#QuotedValueList(Keywords.wgk_keyword)#)
    and
    wg_id = wgk_wg_id
    and
    wg_id <> #wg_id#
    group by wg_id, wg_name
    order by relevancy desc

    Thanks!

    Trenchy Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139