/* ===================================================================
 * IndexField.java
 * 
 * Copyright (c) 2006 Matt Magoffin.
 * 
 * This program is free software; you can redistribute it and/or 
 * modify it under the terms of the GNU General Public License as 
 * published by the Free Software Foundation; either version 2 of 
 * the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License 
 * along with this program; if not, write to the Free Software 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 
 * 02111-1307 USA
 * ===================================================================
 * $Id: IndexField.java 72 2009-05-14 02:11:56Z msqr $
 * ===================================================================
 */

package magoffin.matt.ieat.biz.impl.lucene;

/**
 * An enumeration of Tidbits Lucene index fields.
 * 
 * @author Matt Magoffin (spamsqr@msqr.us)
 * @version $Revision: 72 $ $Date: 2009-05-14 14:11:56 +1200 (Thu, 14 May 2009) $
 */
public enum IndexField {
	
	/** The index field for an item's unique ID. */
	ITEM_ID,
	
	/** The index field for an item's name. */
	ITEM_NAME,
	
	/** The index field for an item's comment. */
	ITEM_COMMENT,
	
	/** The index field for an item's data. */
	ITEM_DATA,
	
	/** An index key appropriate for this item. */
	ITEM_INDEX_KEY,
	
	/** The ID of the owner of an item. */
	ITEM_OWNER,
	
	/** The index field for a Recipe's directions. */
	RECIPE_DIRECTIONS,
	
	/** The index field for a Recipe's excerpt. */
	RECIPE_EXCERPT,
	
	/** The index field for a RecipeIngredient's Ingredient ID. */
	RECIPE_INGREDIENT_ID,
	
	/** The index field for a RecipeIngredient's Ingredient name. */
	RECIPE_INGREDIENT_NAME,
	
	/** The index field for a Recipe rating. */
	RECIPE_RATING,
	
	/** The average value of a recipe's ratings. */
	RECIPE_RATING_AVERAGE,
	
	/** The index field for a Recipe's step. */
	RECIPE_STEP,
	
	/** The index field for a Recipe's system. */
	RECIPE_SYSTEM,

	/** The index field for an item's creation date. */
	CREATED_DATE,
	
	/** The created by login. */
	CREATED_BY,

	/** An item's modified date. */
	MODIFIED_DATE,
	
	/** A unit abbreviation. */
	UNIT_ABBREVIATION,
	
	/** A User's access level. */
	USER_ACCESS_LEVEL,
	
	/** A User's email address. */
	USER_EMAIL,
	
	/** A Users's last login date. */
	USER_LAST_LOGIN_DATE,
	
	/** A User's login. */
	USER_LOGIN,
	
	/** The index field (not stored) for tokenized free-form text. */
	GENERAL_TEXT;

	/**
	 * Get a Lucene field name for this enum.
	 * @return field name
	 * @see #fromFieldName(String)
	 */
	public String getFieldName() {
		switch ( this ) {
			case CREATED_BY: return "cby";
			case CREATED_DATE: return "cdate";
			case GENERAL_TEXT: return "Gtext";
			case ITEM_COMMENT: return "cmnt";
			case ITEM_DATA: return "data";
			case ITEM_ID: return "id";
			case ITEM_INDEX_KEY: return "idx";
			case ITEM_NAME: return "name";
			case ITEM_OWNER: return "own";
			case MODIFIED_DATE: return "mdate";
			case RECIPE_DIRECTIONS: return "dir";
			case RECIPE_EXCERPT: return "excrp";
			case RECIPE_INGREDIENT_ID: return "riid";
			case RECIPE_INGREDIENT_NAME: return "riname";
			case RECIPE_RATING: return "rrat";
			case RECIPE_RATING_AVERAGE: return "rratavg";
			case RECIPE_STEP: return "step";
			case RECIPE_SYSTEM: return "sys";
			case UNIT_ABBREVIATION: return "abvr";
			case USER_ACCESS_LEVEL: return "uacc";
			case USER_EMAIL: return "mail";
			case USER_LAST_LOGIN_DATE: return "llogin";
			case USER_LOGIN: return "uid";
		}
		throw new AssertionError(this);
	}
	
	/**
	 * Get an IndexField from a Lucene field name.
	 * @param field field name
	 * @return the IndexField
	 * @throws IllegalArgumentException if the field name is not supported
	 * @see IndexField#getFieldName()
	 */
	public static IndexField fromFieldName(String field) {
		if ( "abvr".equals(field) ) return UNIT_ABBREVIATION;
		if ( "cby".equals(field) ) return CREATED_BY;
		if ( "cdate".equals(field) ) return CREATED_DATE;
		if ( "cmnt".equals(field) ) return ITEM_COMMENT;
		if ( "data".equals(field) ) return ITEM_DATA;
		if ( "dir".equals(field) ) return RECIPE_DIRECTIONS;
		if ( "excrp".equals(field) ) return RECIPE_EXCERPT;
		if ( "Gtext".equals(field) ) return GENERAL_TEXT;
		if ( "id".equals(field) ) return ITEM_ID;
		if ( "idx".equals(field) ) return ITEM_INDEX_KEY;
		if ( "llogin".equals(field) ) return USER_LAST_LOGIN_DATE;
		if ( "name".equals(field) ) return ITEM_NAME;
		if ( "mail".equals(field) ) return USER_EMAIL;
		if ( "mdate".equals(field) ) return MODIFIED_DATE;
		if ( "own".equals(field) ) return ITEM_OWNER;
		if ( "riid".equals(field) ) return RECIPE_INGREDIENT_ID;
		if ( "riname".equals(field) ) return RECIPE_INGREDIENT_NAME;
		if ( "rrat".equals(field) ) return RECIPE_RATING;
		if ( "rratavg".equals(field) ) return RECIPE_RATING_AVERAGE;
		if ( "step".equals(field) ) return RECIPE_STEP;
		if ( "sys".equals(field) ) return RECIPE_SYSTEM;
		if ( "uacc".equals(field) ) return USER_ACCESS_LEVEL;
		if ( "uid".equals(field) ) return USER_LOGIN;
		throw new IllegalArgumentException(field);
	}
	
}
