FileDocCategorySizeDatePackage
GdataDateStrategy.javaAPI DocApache Lucene 2.1.03709Wed Feb 14 10:46:04 GMT 2007org.apache.lucene.gdata.search.analysis

GdataDateStrategy

public class GdataDateStrategy extends ContentStrategy
This content strategy retrieves a so called GData Date from a RFC 3339 timestamp format. The format will be parsed and indexed as a timestamp value.
author
Simon Willnauer

Fields Summary
Constructors Summary
protected GdataDateStrategy(org.apache.lucene.gdata.search.config.IndexSchemaField fieldConfiguration)

        super(fieldConfiguration);

    
Methods Summary
public org.apache.lucene.document.Field[]createLuceneField()

see
org.apache.lucene.gdata.search.analysis.ContentStrategy#createLuceneField()

        if(this.fieldName == null)
            throw new GdataIndexerException(
                    "Required field 'name' is null -- " +this.config);
        if(this.content == null)
            throw new GdataIndexerException(
                    "Required field 'content' is null -- " +this.config);
        if(this.content.length()==0)
            return new Field[0];
            Field retValue = new Field(this.fieldName, this.content,
                    Field.Store.YES, Field.Index.UN_TOKENIZED);
            float boost = this.config.getBoost();
            if (boost != 1.0f)
                retValue.setBoost(boost);
            return new Field[] { retValue };
        
    
private static java.lang.StringgetTimeStamp(java.lang.String dateString)

        return Long.toString(DateTime.parseDateTimeChoice(dateString).getValue());
    
public voidprocessIndexable(Indexable indexable)

throws
NotIndexableException
see
org.apache.lucene.gdata.search.analysis.ContentStrategy#processIndexable(org.apache.lucene.gdata.search.analysis.Indexable)

        String path = this.config.getPath();
        Node node;
        try {
            node = indexable.applyPath(path);
        } catch (XPathExpressionException e1) {
            throw new NotIndexableException("Can not apply path -- " + path
                    + " FieldConfig: " + this.config);
        }
        if (node == null)
            throw new NotIndexableException(
                    "Could not retrieve content for schema field: "
                            + this.config);
        String textContent = node.getTextContent();
        try {
            this.content = getTimeStamp(textContent);
        } catch (NumberFormatException e) {
            throw new NotIndexableException("Can not parse GData date -- "
                    + textContent);
        }