lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Patton <tpat...@dealcatcher.com>
Subject Re: Missing .tii File
Date Tue, 06 Mar 2007 18:37:14 GMT


Tim Patton wrote:
> I'm not sure how, but in moving an index over from 2.0 to 2.1 and 
> changing my own code one of the .tii files got deleted.  I still have 
> the .tis file though, can I rebuild the missing file so I can open my 
> index?  Luke won't open it now and I just want to make sure everything 
> is ok before opening a writer and possibly doing some permanent damage.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
> 
> 
In the interest if helping out the next person with this problem, here 
is all my code to recover the missing .tii file when I still had the 
rest of the index.

Of course now I am also missing one .fN norm file so I will be trying to 
figure out how to recover that.  Looks like everything else is there, I 
have no idea how this happened.

package org.apache.lucene.index;

import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.apache.lucene.index.TermInfo;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;

public class TIIRecover
{
	public static void main(String[] args)
	{
		try
		{
			String segment="_aginr";
			Directory cfsDir=FSDirectory.getDirectory("c:/java/lib/lucene/recover");
			FieldInfos fieldInfos = new FieldInfos(cfsDir, segment + ".fnm");
			SegmentTermEnum origEnum = new 
SegmentTermEnum(cfsDir.openInput(segment + ".tis"), fieldInfos, false);

			List<Term> termList = new LinkedList<Term>();
			List<TermInfo> termInfoList = new LinkedList<TermInfo>();
			int count=0;
			while(origEnum.next())
			{
				Term term = origEnum.term();
				TermInfo ti = origEnum.termInfo();
				termList.add(term);
				termInfoList.add(ti);
				count++;
			}
			origEnum.close();
			System.out.println("Copied: "+count);
			count=0;

			TermInfosWriter termWriter = new TermInfosWriter(cfsDir, segment, 
fieldInfos, 128);//128 taken from TermInfosWriter.java
			Iterator<Term> termItr = termList.iterator();
			Iterator<TermInfo> termInfoItr = termInfoList.iterator();
			while(termItr.hasNext())
			{
				Term term =termItr.next();
				TermInfo ti = termInfoItr.next();
				termWriter.add(term, ti);
				count++;
			}
			termWriter.close();
			System.out.println("Saved: "+count);

		}
		catch(Throwable e)
		{
			System.err.println(e);
		}
	}
}


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message