use of org.apache.lucene.document.Fieldable in project zm-mailbox by Zimbra.
the class LuceneViewer method dumpDocument.
private void dumpDocument(int docNum, Document doc) throws IOException {
outputLn();
outputLn("Document " + docNum);
if (doc == null) {
outputLn(" deleted");
return;
}
// note: only stored fields will be returned
for (Fieldable field : doc.getFields()) {
String fieldName = field.name();
boolean isDate = "l.date".equals(fieldName);
outputLn(" Field [" + fieldName + "]: " + field.toString());
String[] values = doc.getValues(fieldName);
if (values != null) {
int i = 0;
for (String value : values) {
output(" " + "(" + i++ + ") " + value);
if (isDate) {
try {
Date date = DateTools.stringToDate(value);
output(" (" + date.toString() + " (" + date.getTime() + "))");
} catch (java.text.ParseException e) {
assert false;
}
}
outputLn();
}
}
}
}
use of org.apache.lucene.document.Fieldable in project exhibitor by soabase.
the class LogSearch method toResult.
public SearchItem toResult(int documentId) throws IOException {
Document document = searcher.doc(documentId);
String type = document.getFieldable(FieldNames.TYPE).stringValue();
NumericField date = (NumericField) document.getFieldable(FieldNames.DATE);
Fieldable path = document.getFieldable(FieldNames.PATH);
NumericField version = (NumericField) document.getFieldable(FieldNames.VERSION);
return new SearchItem(Integer.parseInt(type), path.stringValue(), (version != null) ? version.getNumericValue().intValue() : -1, new Date(date.getNumericValue().longValue()));
}
use of org.apache.lucene.document.Fieldable in project graphdb by neo4j-attic.
the class LuceneBatchInserterIndex method removeFromCache.
private void removeFromCache(long entityId) throws IOException, CorruptIndexException {
IndexSearcher searcher = searcher();
Query query = type.idTermQuery(entityId);
TopDocs docs = searcher.search(query, 1);
if (docs.totalHits > 0) {
Document document = searcher.doc(docs.scoreDocs[0].doc);
for (Fieldable field : document.getFields()) {
String key = field.name();
Object value = field.stringValue();
removeFromCache(entityId, key, value);
}
}
}
use of org.apache.lucene.document.Fieldable in project polymap4-core by Polymap4.
the class LuceneRecordState method remove.
public LuceneRecordState remove(String key) {
checkCopyOnWrite();
doc.removeField(key);
// remove additional fields generated by ValueCoder
for (Iterator<Fieldable> it = doc.getFields().iterator(); it.hasNext(); ) {
Fieldable field = it.next();
if (field.name().startsWith(key)) {
it.remove();
}
}
return this;
}
use of org.apache.lucene.document.Fieldable in project eol-globi-data by jhpoelen.
the class TaxonLookupServiceImpl method findTaxon.
private Taxon[] findTaxon(String fieldName1, String fieldValue) throws IOException {
Taxon[] terms = new TaxonImpl[0];
if (StringUtils.isNotBlank(fieldValue) && indexSearcher != null) {
PhraseQuery query = new PhraseQuery();
query.add(new Term(fieldName1, fieldValue));
TopDocs docs = indexSearcher.search(query, getMaxHits());
if (docs.totalHits > 0) {
int maxResults = Math.min(docs.totalHits, getMaxHits());
terms = new TaxonImpl[maxResults];
for (int i = 0; i < maxResults; i++) {
ScoreDoc scoreDoc = docs.scoreDocs[i];
Document foundDoc = indexSearcher.doc(scoreDoc.doc);
Taxon term = new TaxonImpl();
Fieldable idField = foundDoc.getFieldable(FIELD_ID);
if (idField != null) {
term.setExternalId(idField.stringValue());
}
Fieldable rankPathField = foundDoc.getFieldable(FIELD_RANK_PATH);
if (rankPathField != null) {
term.setPath(rankPathField.stringValue());
}
Fieldable rankPathIdsField = foundDoc.getFieldable(FIELD_RANK_PATH_IDS);
if (rankPathIdsField != null) {
term.setPathIds(rankPathIdsField.stringValue());
}
Fieldable rankPathNamesField = foundDoc.getFieldable(FIELD_RANK_PATH_NAMES);
if (rankPathNamesField != null) {
term.setPathNames(rankPathNamesField.stringValue());
}
Fieldable commonNamesFields = foundDoc.getFieldable(FIELD_COMMON_NAMES);
if (commonNamesFields != null) {
term.setCommonNames(commonNamesFields.stringValue());
}
Fieldable fieldName = foundDoc.getFieldable(FIELD_RECOMMENDED_NAME);
if (fieldName != null) {
term.setName(fieldName.stringValue());
}
terms[i] = term;
}
}
}
return terms;
}
Aggregations