DocHelperpublic 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 |
Methods Summary |
---|
public static int | numFields(org.apache.lucene.document.Document doc)
Enumeration fields = doc.fields();
int result = 0;
while (fields.hasMoreElements()) {
fields.nextElement();
result++;
}
return result;
| public static void | setupDoc(org.apache.lucene.document.Document doc)Adds the fields above to a document
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 void | writeDoc(org.apache.lucene.store.Directory dir, org.apache.lucene.document.Document doc)Writes the document to the directory using a segment named "test"
writeDoc(dir, "test", doc);
| public static void | writeDoc(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
Analyzer analyzer = new WhitespaceAnalyzer();
Similarity similarity = Similarity.getDefault();
writeDoc(dir, analyzer, similarity, segment, doc);
| public static void | writeDoc(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
writeDoc(dir, analyzer, similarity, "test", doc);
| public static void | writeDoc(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
DocumentWriter writer = new DocumentWriter(dir, analyzer, similarity, 50);
try {
writer.addDocument(segment, doc);
} catch (IOException e) {
e.printStackTrace();
}
|
|