lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From petite_abeille <petite_abei...@mac.com>
Subject Re: moving documents from one index to another?
Date Thu, 20 Nov 2003 14:54:02 GMT

On Nov 20, 2003, at 14:34, Eric Jain wrote:

>> I see. Assuming I have the relevant terms for a given document, how
>> would a build a new document based on those terms? Something like
>> adding each term's field and text to the new document?
>
> Yes.

Ok. Retrieving the term for a document turns out to be pretty 
straightforward, but building a new document turns out to be slightly 
more convoluted than expected... I basically need to know which kind of 
field to create (Stored, Indexed, Tokenized), but this information 
doesn't seem to be available in the document I'm trying to clone. I 
thought I could use the original Document's getField() method to 
retrieve this information, but aside from the Keyword field, none of 
the other fields are available... where can I get this info at this 
stage?

Here is the problematic method for cloning a document:

	private Document cloneDocumentWithTerms(final Document aDocument, 
final Collection someTerms)
	{
		if ( aDocument != null )
		{
			if ( someTerms != null )
			{
				Document	anotherDocument = new Document();
				
				anotherDocument.setBoost( aDocument.getBoost() );
				
				 for ( Iterator anIterator = someTerms.iterator(); 
anIterator.hasNext(); )
				 {
					Term    aTerm = (Term) anIterator.next();
					String  aKey = aTerm.field();
					String  aValue = aTerm.text();
					Field   aField = aDocument.getField( aKey );
					boolean isStored = aField.isStored();
					boolean isIndexed = aField.isIndexed();
					boolean isTokenized = aField.isTokenized();
					Field   anotherField = new Field( aKey, aValue, isStored, 
isIndexed, isTokenized );
					
					anotherField.setBoost( aField.getBoost() );
					
					anotherDocument.add( anotherField );
				 }
				
				 return anotherDocument;
			}

			throw new IllegalArgumentException( "Index.cloneDocumentWithTerms: 
null terms." );
		}

		throw new IllegalArgumentException( "Index.cloneDocumentWithTerms: 
null document." );
	}

The problem is that aDocument.getField( aKey ) returns null most of the 
time. What gives?

TIA.

PA.


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


Mime
View raw message