Save This Page
Home » lucene-3.0.1-src » org.apache » lucene » benchmark » quality » [javadoc | source]
    1   /**
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *     http://www.apache.org/licenses/LICENSE-2.0
   10    *
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   package org.apache.lucene.benchmark.quality;
   18   
   19   import java.util.Map;
   20   
   21   /**
   22    * A QualityQuery has an ID and some name-value pairs.
   23    * <p> 
   24    * The ID allows to map the quality query with its judgements.
   25    * <p>
   26    * The name-value pairs are used by a 
   27    * {@link org.apache.lucene.benchmark.quality.QualityQueryParser}
   28    * to create a Lucene {@link org.apache.lucene.search.Query}.
   29    * <p>
   30    * It is very likely that name-value-pairs would be mapped into fields in a Lucene query,
   31    * but it is up to the QualityQueryParser how to map - e.g. all values in a single field, 
   32    * or each pair as its own field, etc., - and this of course must match the way the 
   33    * searched index was constructed.
   34    */
   35   public class QualityQuery implements Comparable<QualityQuery> {
   36     private String queryID;
   37     private Map<String,String> nameValPairs;
   38   
   39     /**
   40      * Create a QualityQuery with given ID and name-value pairs.
   41      * @param queryID ID of this quality query.
   42      * @param nameValPairs the contents of this quality query.
   43      */
   44     public QualityQuery(String queryID, Map<String,String> nameValPairs) {
   45       this.queryID = queryID;
   46       this.nameValPairs = nameValPairs;
   47     }
   48     
   49     /**
   50      * Return all the names of name-value-pairs in this QualityQuery.
   51      */
   52     public String[] getNames() {
   53       return nameValPairs.keySet().toArray(new String[0]);
   54     }
   55   
   56     /**
   57      * Return the value of a certain name-value pair.
   58      * @param name the name whose value should be returned. 
   59      */
   60     public String getValue(String name) {
   61       return nameValPairs.get(name);
   62     }
   63   
   64     /**
   65      * Return the ID of this query.
   66      * The ID allows to map the quality query with its judgements.
   67      */
   68     public String getQueryID() {
   69       return queryID;
   70     }
   71   
   72     /* for a nicer sort of input queries before running them.
   73      * Try first as ints, fall back to string if not int. */ 
   74     public int compareTo(QualityQuery other) {
   75       try {
   76         // compare as ints when ids ints
   77         int n = Integer.parseInt(queryID);
   78         int nOther = Integer.parseInt(other.queryID);
   79         return n - nOther;
   80       } catch (NumberFormatException e) {
   81         // fall back to string comparison
   82         return queryID.compareTo(other.queryID);
   83       }
   84     }
   85     
   86   }

Save This Page
Home » lucene-3.0.1-src » org.apache » lucene » benchmark » quality » [javadoc | source]