001: /*
002: * Copyright 2003-2004 Michael Franken, Zilverline.
003: *
004: * The contents of this file, or the files included with this file, are subject to
005: * the current version of ZILVERLINE Collaborative Source License for the
006: * Zilverline Search Engine (the "License"); You may not use this file except in
007: * compliance with the License.
008: *
009: * You may obtain a copy of the License at
010: *
011: * http://www.zilverline.org.
012: *
013: * See the License for the rights, obligations and
014: * limitations governing use of the contents of the file.
015: *
016: * The Original and Upgraded Code is the Zilverline Search Engine. The developer of
017: * the Original and Upgraded Code is Michael Franken. Michael Franken owns the
018: * copyrights in the portions it created. All Rights Reserved.
019: *
020: */
021:
022: package org.zilverline.lucene;
023:
024: import java.util.HashMap;
025: import java.util.Iterator;
026: import java.util.Map;
027:
028: import org.apache.commons.logging.Log;
029: import org.apache.commons.logging.LogFactory;
030:
031: /**
032: * Represents boosting factors per Field.
033: *
034: * These are factors used by zilverline to boost a query. By default a given query such as 'java "method invocation" rmi' looks for
035: * these terms in the contents of a document. By setting boost factors for other attributes of a document, such as title, name, and
036: * summary you can tune the result of a query. Normally you start with contents (boostfactor 1.0), and then specify that you want a
037: * occurence of the query terms within the name of a document to be twice as important as a hit within the contents, you specify a
038: * boostfactor of 2.0. The example below rates an occurrence of query terms within summary to be three times as important as within
039: * contents, and the title four times. These are typically read from Spring configuration:
040: *
041: * <pre>
042: *
043: *
044: *
045: * <bean id="boostFactor" class="org.zilverline.lucene.BoostFactor">
046: * <property name="factors">
047: * <props>
048: * <prop key="contents">1.0</prop>
049: * <prop key="name">2</prop>
050: * <prop key="summary">3</prop>
051: * <prop key="title">4</prop>
052: * </props>
053: * </property>
054: * </bean>
055: *
056: *
057: *
058: * </pre>
059: *
060: * @author Michael Franken
061: * @version $Revision: 1.13 $
062: */
063: public class BoostFactor {
064: /** logger for Commons logging. */
065: private static Log log = LogFactory.getLog(BoostFactor.class);
066:
067: /** Map holding field names with to boostfactors. */
068: private Map factors = new HashMap();
069:
070: /**
071: * Constructs BoostFactor with defualt boosts. For testing purposes and backward compatibility, overwritten be external
072: * configuration, if any
073: */
074: public BoostFactor() {
075: factors.put("contents", new Float(1.0));
076: factors.put("title", new Float(3.0));
077: factors.put("summary", new Float(2.0));
078: factors.put("name", new Float(4.0));
079: }
080:
081: /**
082: * Set Factors from a Map object. The Factors Fields with commands as values. For instance 'content=1.0'.
083: *
084: * @param props properties as a Map with extension as key and command as value
085: */
086: public final void setFactors(final Map props) {
087: factors.clear();
088: // convert the keys to lowercase
089: Iterator iter = props.entrySet().iterator();
090: while (iter.hasNext()) {
091: Map.Entry element = (Map.Entry) iter.next();
092: factors.put(((String) element.getKey()).toLowerCase(),
093: Float.valueOf((String) element.getValue()));
094: }
095: }
096:
097: /**
098: * Get the Factors for the Fields.
099: *
100: * @return the Factors
101: */
102: public final Map getFactors() {
103: return factors;
104: }
105: }
|