0

这是我的代码:

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import org.apache.lucene.index.CorruptIndexException;

public class Main 
{
    public static void main()
    {
        //Index index = new Index();
        String[] titleAndContent = parseFile("files/methode.txt");
        Index index = new Index("files",null);
        try 
        {
            index.openIndex(true);
            index.addDocument(titleAndContent[0], titleAndContent[1], "files/methode.txt");
        } 
        catch (CorruptIndexException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
        catch (IOException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    public static String[] parseFile(String path)
    {
        String[] titleAndContent = new String[2];
        File file = new File(path);
        try 
        {
            FileReader fr = new FileReader(file); 
            BufferedReader br = new BufferedReader(fr); 
            String line = new String();
            String content = new String();
            try 
            {
                while((line = br.readLine()) != null) 
                { 
                     if (line.substring(0,min(6,line.length())).equals("title:"))
                     {
                         titleAndContent[0] = line.substring(6,line.length());
                     }
                     else
                     {
                         if (line.substring(0,min(8,line.length())).equals("content:"))
                         {
                             content += line.substring(8,line.length())+"\n";
                         }
                         else
                         {
                             content += line+"\n";
                         }
                     }
                }
            } 
            catch (IOException e1) 
            {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            titleAndContent[1] = content;
            try 
            {
                fr.close();
            } 
            catch (IOException e) 
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        } 
        catch (FileNotFoundException e) 
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return titleAndContent;
    }

    public static int max (int a, int b)
    {
        if (a<b)
        {
            return b;
        }
        return a;
    }

    public static int min (int a, int b)
    {
        if (a<b)
        {
            return a;
        }
        return b;
    }
}

问题是,我无法在 Eclipse 下编译我的 Lucene 项目。它不断告诉我:

ERROR: index path not specified

Usage: java org.apache.lucene.index.CheckIndex pathToIndex [-fix] [-segment X] [-segment Y]

  -fix: actually write a new segments_N file, removing any problematic segments
  -segment X: only check the specified segments.  This can be specified multiple
              times, to check more than one segment, eg '-segment _2 -segment _a'.
              You can't use this with the -fix option

**WARNING**: -fix should only be used on an emergency basis as it will cause
documents (perhaps many) to be permanently removed from the index.  Always make
a backup copy of your index before running this!  Do not run this tool on an index
that is actively being written to.  You have been warned!

Run without -fix, this tool will open the index, report version information
and report any exceptions it hits and what action it would take if -fix were
specified.  With -fix, this tool will remove any segments that have issues and
write a new segments_N file.  This means all documents contained in the affected
segments will be removed.

This tool exits with exit code 1 if the index cannot be opened or has any
corruption, else 0.

尽一切努力让它工作,正如整个网络所说,我用

-ea:org.apache.lucene... pathToIndex -fix

作为编译的参数。但是无论我放什么而不是 pathToIndex,它一直在告诉我

Unexpected argument pathToIndex (or whatever instead)

我怎样才能得到这个f...项目的工作?先感谢您。

编辑:当然我已经导入了所有的 Lucene JAR。

4

1 回答 1

0

实际上,我通过在其中创建一个简单的 Main 类和一个 main 方法来重新启动项目,并尝试立即编译它。这次它工作得很好。请注意,在 Eclipse 中编译之前,您应该在屏幕选项卡上显示 Main 类。

于 2013-02-12T22:44:47.937 回答