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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:40:08+00:00 2026-05-29T06:40:08+00:00

I working on a new project and I have to develop an inverted index

  • 0

I working on a new project and I have to develop an inverted index that can be stored in a file database (such as CouchDB). I am coding in Ruby 1.8.7.

This is the format of the inverted index:

{
    "en": {
        "#linux": {
            "re": 144,
            "patch": 142,
            "1": 55,
            "to": 53
            },
        "#something": {
            "word": 20
            }
        },
    "fr": {},
    "es": {}
}

I want a way that using something like CouchDB, I can create the entries by a series of checks like the following:

  • If the second hash key (i.e. #linux) has not been created, then create it
  • If the third hash key (i.e. patch) has not been created, then create it and set it’s value to 1
  • Repeat and increase the count (the furthest right values) by one every time the same word appears again ['en']['#linux'] or whatever the variables will be.

I’ve done the problem fine just using basic hashes, but having these in memory aren’t going to be very nice when I set my script to go through about 1TB or more of text.

Selected Answer

The selected answer works perfectly for this. The only difference is a few slight changes to the syntax and works as follows:

@db.collection.update({"_id" => lang}, {"$inc" => {"#{tag}.#{word}" => 1}}, { :upsert => true })
  • 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-29T06:40:09+00:00Added an answer on May 29, 2026 at 6:40 am

    CouchDB is not going to be your best tool for the job. Particularly it is not suited for fast updates that don’t grow document (your increments). Upon each update it creates a new version of document on disk, so your db is going to be pretty massive and disk is going to be busy.

    I would recommend looking at MongoDB. It has fast in-place updates, indexes and richer query language. Example:

    db.collection.update({_id: 'en'},
                         {$inc: {'linux.re': 1}},
                         true);
    

    This will find document with id ‘en’ and increments its ['linux']['re'] field. If a document isn’t found, or ['linux'] doesn’t exist, or ['linux']['re'] doesn’t exist, they will be automatically created. This is one of my most favourite features of this DB.

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

Sidebar

Related Questions

I have a new project working with an existing oracle database. I've always been
I'm working on a new project and I'm using the repository pattern, I have
I'm working on this project and I have to open a new browser tab.
I am currently working on a project that is very new to me, and
In near future I'll need to start working on a new project that consist
I have a pet project that I'm working on that has multiple worker threads.
I'm working in a project that is divided into multiple modules. Each module have
Working on a new project I've run into a major roadblock that has brought
I am working on a new project that makes use of Entity Framework. I
I am working on a new project. Is there any benefit with going with

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.