DocHelperpublic class DocHelper extends Object Copyright 2005 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. |
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 | FIELD_3_TEXT | public static final String | TEXT_FIELD_3_KEY | public static Field | textField3 | public static final String | KEYWORD_TEXT | public static final String | KEYWORD_FIELD_KEY | public static Field | keyField | public static final String | NO_NORMS_TEXT | public static final String | NO_NORMS_KEY | public static Field | noNormsField | 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 | public static Field[] | fields | public static Map | all | public static Map | indexed | public static Map | stored | public static Map | unstored | public static Map | unindexed | public static Map | termvector | public static Map | notermvector | public static Map | noNorms |
Methods Summary |
---|
private static void | add(java.util.Map map, org.apache.lucene.document.Field field)
for (int i=0; i<fields.length; i++) {
Field f = fields[i];
add(all,f);
if (f.isIndexed()) add(indexed,f);
else add(unindexed,f);
if (f.isTermVectorStored()) add(termvector,f);
if (f.isIndexed() && !f.isTermVectorStored()) add(notermvector,f);
if (f.isStored()) add(stored,f);
else add(unstored,f);
if (f.getOmitNorms()) add(noNorms,f);
}
map.put(field.name(), field);
| public static int | numFields(org.apache.lucene.document.Document doc)
Enumeration fields = doc.fields();
int result = 0;
while (fields.hasMoreElements()) {
String name = fields.nextElement().toString();
name += ""; // avoid compiler warning
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(TEXT_FIELD_3_KEY, FIELD_3_TEXT);
nameValues.put(KEYWORD_FIELD_KEY, KEYWORD_TEXT);
nameValues.put(NO_NORMS_KEY, NO_NORMS_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);
for (int i=0; i<fields.length; i++) {
doc.add(fields[i]);
}
| 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
Similarity similarity = Similarity.getDefault();
writeDoc(dir, new WhitespaceAnalyzer(), 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);
writer.addDocument(segment, doc);
|
|