FileDocCategorySizeDatePackage
DocHelper.javaAPI DocApache Lucene 1.95328Mon Feb 20 09:20:32 GMT 2006org.apache.lucene.index

DocHelper

public class DocHelper extends Object

Fields Summary
public static final String
FIELD_1_TEXT
public static final String
TEXT_FIELD_1_KEY
public static Field
textField1
public static final String
FIELD_2_TEXT
public static final int[]
FIELD_2_FREQS
public static final String
TEXT_FIELD_2_KEY
public static Field
textField2
public static final String
KEYWORD_TEXT
public static final String
KEYWORD_FIELD_KEY
public static Field
keyField
public static final String
UNINDEXED_FIELD_TEXT
public static final String
UNINDEXED_FIELD_KEY
public static Field
unIndField
public static final String
UNSTORED_1_FIELD_TEXT
public static final String
UNSTORED_FIELD_1_KEY
public static Field
unStoredField1
public static final String
UNSTORED_2_FIELD_TEXT
public static final String
UNSTORED_FIELD_2_KEY
public static Field
unStoredField2
public static Map
nameValues
Constructors Summary
Methods Summary
public static intnumFields(org.apache.lucene.document.Document doc)

    Enumeration fields = doc.fields();
    int result = 0;
    while (fields.hasMoreElements()) {
      fields.nextElement();
      result++;
    }
    return result;
  
public static voidsetupDoc(org.apache.lucene.document.Document doc)
Adds the fields above to a document

param
doc The document to write

  
  
  
    
    nameValues = new HashMap();
    nameValues.put(TEXT_FIELD_1_KEY, FIELD_1_TEXT);
    nameValues.put(TEXT_FIELD_2_KEY, FIELD_2_TEXT);
    nameValues.put(KEYWORD_FIELD_KEY, KEYWORD_TEXT);
    nameValues.put(UNINDEXED_FIELD_KEY, UNINDEXED_FIELD_TEXT);
    nameValues.put(UNSTORED_FIELD_1_KEY, UNSTORED_1_FIELD_TEXT);
    nameValues.put(UNSTORED_FIELD_2_KEY, UNSTORED_2_FIELD_TEXT);
  
    doc.add(textField1);
    doc.add(textField2);
    doc.add(keyField);
    doc.add(unIndField);
    doc.add(unStoredField1);
    doc.add(unStoredField2);
  
public static voidwriteDoc(org.apache.lucene.store.Directory dir, org.apache.lucene.document.Document doc)
Writes the document to the directory using a segment named "test"

param
dir
param
doc

    
    writeDoc(dir, "test", doc);
  
public static voidwriteDoc(org.apache.lucene.store.Directory dir, java.lang.String segment, org.apache.lucene.document.Document doc)
Writes the document to the directory in the given segment

param
dir
param
segment
param
doc

    Analyzer analyzer = new WhitespaceAnalyzer();
    Similarity similarity = Similarity.getDefault();
    writeDoc(dir, analyzer, similarity, segment, doc);
  
public static voidwriteDoc(org.apache.lucene.store.Directory dir, org.apache.lucene.analysis.Analyzer analyzer, org.apache.lucene.search.Similarity similarity, org.apache.lucene.document.Document doc)
Writes the document to the directory segment named "test" using the specified analyzer and similarity

param
dir
param
analyzer
param
similarity
param
doc

    writeDoc(dir, analyzer, similarity, "test", doc);
  
public static voidwriteDoc(org.apache.lucene.store.Directory dir, org.apache.lucene.analysis.Analyzer analyzer, org.apache.lucene.search.Similarity similarity, java.lang.String segment, org.apache.lucene.document.Document doc)
Writes the document to the directory segment using the analyzer and the similarity score

param
dir
param
analyzer
param
similarity
param
segment
param
doc

    DocumentWriter writer = new DocumentWriter(dir, analyzer, similarity, 50);
    try {
      writer.addDocument(segment, doc);
    } catch (IOException e) {
      e.printStackTrace();
    }