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 615773
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:15:21+00:00 2026-05-13T18:15:21+00:00

I have a log file containing search queries entered into my site’s search engine.

  • 0

I have a log file containing search queries entered into my site’s search engine. I’d like to “group” related search queries together for a report. I’m using Python for most of my webapp – so the solution can either be Python based or I can load the strings into Postgres if it is easier to do this with SQL.

Example data:

dog food
good dog trainer
cat food
veterinarian

Groups should include:

cat:
cat food

dog:

dog food
good dog trainer

food:

dog food
cat food

etc…

Ideas? Some sort of “indexing algorithm” perhaps?

  • 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-05-13T18:15:22+00:00Added an answer on May 13, 2026 at 6:15 pm
    f = open('data.txt', 'r')
    raw = f.readlines()
    
    #generate set of all possible groupings
    groups = set()
    for lines in raw:
        data = lines.strip().split()
        for items in data:
            groups.add(items)
    
    #parse input into groups
    for group in groups:
        print "Group \'%s\':" % group
        for line in raw:
            if line.find(group) is not -1:
                print line.strip()
        print
    
    #consider storing into a dictionary instead of just printing
    

    This could be heavily optimized, but this will print the following result, assuming you place the raw data in an external text file:

    Group 'trainer':
    good dog trainer
    
    Group 'good':
    good dog trainer
    
    Group 'food':
    dog food
    cat food
    
    Group 'dog':
    dog food
    good dog trainer
    
    Group 'cat':
    cat food
    
    Group 'veterinarian':
    veterinarian
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a CSV file containing log on data for users and would like
I have a log file containing statistics from different servers. I am separating the
I have a log.txt file on the root of my application. I would like
I have a huge log file containing log messages prefixed with timestamp. The timestamp
I would like to have a log file of every access to my phpmyadmin
I have a log file containing such output: [mvn] Running com.mypackage.MyTest ... [mvn] Tests
I have a log file containing a stack trace split over a number of
I have a log file containing the following data: Shortest path(2)::RV3280-RV0973C-RV2888C Shortest path(1)::RV3280-RV2502C Shortest
I have a log file that I'm trying to append data to the end
I have a log file that I am reading to a string public static

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.