Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8154207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:15:51+00:00 2026-06-06T16:15:51+00:00

I have a database with almost 100,000 comments and I would like to detect

  • 0

I have a database with almost 100,000 comments and I would like to detect the most used words (using stop words to avoid common words).

I want to do this only one time, and then use a few of the most popular words to Tag the comments that contains them.

Can you help me with the Query and PHP code to do this?
Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T16:15:54+00:00Added an answer on June 6, 2026 at 4:15 pm

    The easiest approach I guess would be:

    • Create two new tables: keywords (id, word) and keywords_comments (keyword_id, comment_id, count)
      • keywords saves an unique id and the keyword you found in a text
      • keywords_comments stores one row for each connection between each comment that contains that keyword. In count you wil save the number of times this keyword occurred in the comment. The two columns keyword_id + comment_id together form a unique or directly the primary key.
    • Retrieve all comments from the database
    • Parse through all comments and split by non-characters (or other boundaries)
    • Write these entries to your tables

    Example

    You have the following two comments:

    Hello, how are you?!

    Wow, hello. My name is Stefan.

    Now you would iterate over both of them and split them by non-characters. This would result in the following lowercase words for each text:
    – First text: hello, how, are, you
    – Second text: wow, hello, my, name, is, stefan

    As soon as you have parsed one of this text, you can already insert it into the database again. I guess you do not want to load 100.000 comments to RAM.

    So it would go this:

    • Parse first text an get the keywords above
    • Write each keyword into the tabke keywords if it is not there yet
    • Set a reference from the keyword to the comment (keywords_comments) and set the count correctly (in our example each word occurs only once in each text, you have to count that).
    • Parse second text
    • …

    Minor improvement

    A very easy improvement you probably have to use for 100.000 comments, is to use a counting variable or add a new field has_been_analyzed to each comment. Then you can read them comment by comment from the database.

    I usually use counting variables when I read data chunkwise and know that the data cannot not change from the direction I am starting (i.e. it will stay consistent up to the point I currently am). Then I do something like:

    SELECT * FROM table ORDER BY created ASC LIMIT 0, 100
    SELECT * FROM table ORDER BY created ASC LIMIT 100, 100
    SELECT * FROM table ORDER BY created ASC LIMIT 200, 100
    …
    

    Consider that this only works if we know for sure that there are no dates to be added at a place we think we already read. E.g. using DESC would not work, as there could be data inserted. Then the whole offset would break and we would read one article twice and never read the new article.

    If you cannot make sure that the outside counting variable stays consistent, you can add a new field analyzed which you set to true as soon as you have read the comment. Then you can always see which comments have already been read and which not. An SQL query would then look like this:

    SELECT * FROM table WHERE analyzed = 0 LIMIT 100 /* Reading chunks of 100 */
    

    This works as long as you do not parallelize the workload (with multiple clients or threads). Otherwise you would have to make sure that reading + setting true is atomar (synchronized).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table (session) in a database which has almost 72,000 rows. I
I have Database with date field. I see the time like: 1900-01-01 13:38:00.000 How
My DB seems to have almost 100 sleep connections and I believe it would
I have a CouchDB database with documents representing 100,000 events. Each event has, among
I would like to copy one database (almost all tables) to another server. So
I have two websites that have an almost identical database schema. the only difference
i have database table like this +-------+--------------+----------+ | id | ip | date |
that my problem: I have database table like that: id (AI) market_id 1 6
Consider a database(MSSQL 2005) that consists of 100+ tables which have primary keys defined
I would like to know how to benchmark a php/mysql site. We have a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.