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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T18:00:00+00:00 2026-05-29T18:00:00+00:00

I have written a program that is compiled and run in Netbeans and Eclipse

  • 0

I have written a program that is compiled and run in Netbeans and Eclipse without any problem. But when I try to compile it in command line via:

javac -classpath .:lucene-core-3.4.0.jar Indexer.java

I get the error:

Note: Indexer.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

When I try to compile with -Xlint:deprecation option I get:

javac -classpath .:lucene-core-3.4.0.jar Indexer.java -Xlint:deprecation
Indexer.java:14: warning: [deprecation] org.apache.lucene.index.IndexWriter.MaxFieldLength in org.apache.lucene.index.IndexWriter has been deprecated
import org.apache.lucene.index.IndexWriter.MaxFieldLength;
                                          ^
1 warning

My source code seems to be pure and without any problem! can anyone help me compile and run it in command line?

Code

import java.io.File;
import java.io.FileFilter;
import java.io.FileReader;
import java.io.IOException;
import java.io.File;
import java.io.FileReader;
import java.io.BufferedReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriter.MaxFieldLength;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.Document;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.analysis.StopAnalyzer;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Version;
import org.apache.lucene.index.TermFreqVector;

public class Indexer {

    public static void main(String[] args) throws Exception {
        // TODO code application logic here

        //Indexing begins
            String indexDir;
            String dataDir;
            if (args.length != 2) {
                    dataDir = new String("/home/norc/Ranking/Hamshahri/Data/");
                    indexDir = new String("/media/5E62D9BD62D99A5B/indexes/");
            //throw new IllegalArgumentException("Usage: java " + Indexer.class.getName() + " <index dir> <data dir>");
        }
                else {
                    dataDir = args[0];
                    indexDir = args[1];
                }
        long start = System.currentTimeMillis();
        Indexer indexer = new Indexer(indexDir);
        int numIndexed;
        try {
            numIndexed = indexer.index(dataDir, new TextFilesFilter());
        } finally {
            indexer.close();
        }
        long end = System.currentTimeMillis();
        System.out.println("Indexing " + numIndexed + " files took " + (end - start) + " milliseconds");

    }

    private IndexWriter writer;

    @SuppressWarnings("deprecation")
    public Indexer(String indexDir) throws IOException {
        Directory dir = FSDirectory.open(new File(indexDir));
        writer = new IndexWriter(dir,
             new StopAnalyzer(Version.LUCENE_34, new File("/home/norc/Ranking/Hamshahri/stopwords.txt")),
             true,
             IndexWriter.MaxFieldLength.UNLIMITED);
    }

    public void close() throws IOException {
        writer.close();
    }

    public int index(String dataDir, FileFilter filter) throws Exception {
        File[] dires = new File(dataDir).listFiles();
        for (File d: dires) {
            if (d.isDirectory()) {
            File[] files = new File(d.getAbsolutePath()).listFiles();
            for (File f: files) {
                if (!f.isDirectory() &&
                !f.isHidden() &&
                f.exists() &&
                f.canRead() &&
                (filter == null || filter.accept(f))) {
                    indexFile(f);
                }
            }
            }
        }
        return writer.numDocs();
    }

    private static class TextFilesFilter implements FileFilter {
        public boolean accept(File path) {
            return path.getName().toLowerCase().endsWith(".txt");
        }
    }


    protected Document getDocument(File f) throws Exception {
        Document doc = new Document();
        if (f.exists()) {
        doc.add(new Field("contents", new FileReader(f), Field.TermVector.YES));
        doc.add(new Field("path", f.getAbsolutePath(), Field.Store.YES, Field.Index.NOT_ANALYZED));
        String cat = "WIR";
        cat = f.getAbsolutePath().substring(0, f.getAbsolutePath().length()-f.getName().length()-1);
        cat = cat.substring(cat.lastIndexOf('/')+1, cat.length());
        //doc.add(new Field("category", cat.subSequence(0, cat.length()), Field.Store.YES));
        //System.out.println(cat.subSequence(0, cat.length()));
        }
        return doc;
    }

    private void indexFile(File f) throws Exception {
        System.out.println("Indexing " + f.getAbsolutePath());
        Document doc = getDocument(f);
        writer.addDocument(doc);
    }

}
  • 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-29T18:00:02+00:00Added an answer on May 29, 2026 at 6:00 pm

    org.apache.lucene.index.IndexWriter.MaxFieldLength is deprecated and should not be used any more, see https://lucene.apache.org/core/old_versioned_docs/versions/3_4_0/api/all/org/apache/lucene/index/IndexWriter.MaxFieldLength.html#IndexWriter.MaxFieldLength%28int%29

    It’s just a warning. You may use it, but it’s not recommended.

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

Sidebar

Related Questions

I have written c++ program on NetBeans, now I want to run it on
I have written several program and found out that when compiled in 64bit, the
I have written a program that will etablish a network connection with a remote
I have written a program that uses qhttp to get a webpage. This works
I have written a java program that is actually works as a gui to
I have written a c# program that calls a c++ dll that echoes the
Below I have written a sample program that I have written to learn about
I have written an ActionScript client program that tries to connect to a local
I have a PHP program that has been written keeping in mind a single
I have a program written in VB.Net (Visual Studio 2008) that uses a DLL

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.