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
9 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.apache.lucene.benchmark.quality;
22 * A QualityQuery has an ID and some name-value pairs.
24 * The ID allows to map the quality query with its judgements.
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}.
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.
35 public class QualityQuery implements Comparable<QualityQuery> {
36 private String queryID;
37 private Map<String,String> nameValPairs;
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.
44 public QualityQuery(String queryID, Map<String,String> nameValPairs) {
45 this.queryID = queryID;
46 this.nameValPairs = nameValPairs;
50 * Return all the names of name-value-pairs in this QualityQuery.
52 public String[] getNames() {
53 return nameValPairs.keySet().toArray(new String[0]);
57 * Return the value of a certain name-value pair.
58 * @param name the name whose value should be returned.
60 public String getValue(String name) {
61 return nameValPairs.get(name);
65 * Return the ID of this query.
66 * The ID allows to map the quality query with its judgements.
68 public String getQueryID() {
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) {
76 // compare as ints when ids ints
77 int n = Integer.parseInt(queryID);
78 int nOther = Integer.parseInt(other.queryID);
80 } catch (NumberFormatException e) {
81 // fall back to string comparison
82 return queryID.compareTo(other.queryID);