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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T11:53:52+00:00 2026-06-08T11:53:52+00:00

I am implementing search feature for a news website. On that website ,users submit

  • 0

I am implementing search feature for a news website. On that website ,users submit news articles containing title and text, currently these articles are inserted directly into a database.I heard that full text searching inside a database containing long..long text would not be efficient.

so i tried using lucene for indexing and searching. i am able to index full database with it and also able to search the content.But i am not sure if i am using the best approach.

Here is my indexer class :

public class LuceneIndexer {
    public static void indexNews(Paste p ,IndexWriter indexWriter) throws IOException {

        Document doc = new Document();
        doc.add(new Field("id", p.getNewsId(), Field.Store.YES, Field.Index.NO));
        doc.add(new Field("title", p.getTitle(), Field.Store.YES, Field.Index.TOKENIZED));
        doc.add(new Field("text", p.getNewsRawText(), Field.Store.YES, Field.Index.UN_TOKENIZED));
        String fullSearchableText = p.getTitle() + " " + p.getNewsRawText();

        doc.add(new Field("content", fullSearchableText, Field.Store.NO, Field.Index.TOKENIZED));
        indexWriter.addDocument(doc);
    }

    public static void rebuildIndexes() {


        try {
            System.out.println("started indexing");
            IndexWriter w = getIndexWriter();
            ArrayList<News> n = new GetNewsInfo().getLastPosts(0);
            for (News news : n) {
                indexNews(news,w );
            }
             closeIndexWriter(w);
             System.out.println("indexing done");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }


    }

    public static IndexWriter getIndexWriter() throws CorruptIndexException, LockObtainFailedException, IOException {

        IndexWriter indexWriter = new IndexWriter(GlobalData.LUCENE_INDEX_STOREAGE, new StandardAnalyzer(), true);
        return indexWriter;
    }

    public static void closeIndexWriter(IndexWriter w) throws CorruptIndexException, IOException {
        w.close();

    }

Is above code efficient ?

I think i should add a document into index when it is submitted by user instead of indexing full database again.

  • Do i need to create new IndexWriter every time an article is submitted?
  • is that efficient to open and close an IndexWriter very frequently?
  • 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-08T11:53:53+00:00Added an answer on June 8, 2026 at 11:53 am

    Do i need to create new IndexWriter every time an article is
    submitted?

    No

    is that efficient to open and close an IndexWriter very frequently?

    Definitely not! You should read the guidelines for indexing here.

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

Sidebar

Related Questions

Hello I am currently working on implementing a spatial search feature for a website
I'm implementing a search feature for an app that uses entity framework. There are
I'm currently implementing a search form in our users database. I would like to
I am implementing a search feature for a table of personnel that is displayed
I am implementing a 'online image search' feature for my app. The flow that
I'm implementing a live search feature on my website(rails). Everytime there is a keypress,
I am confused with building the query. I am implementing the search feature in
In my application i am implementing search, it is like when user enter text
I'm implementing a search in my website, and would like to support searching for
I am looking for a means of implementing a Search routine/page that I can

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.