01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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: */package org.apache.lucene.benchmark.quality;
17:
18: import java.util.Map;
19:
20: /**
21: * A QualityQuery has an ID and some name-value pairs.
22: * <p>
23: * The ID allows to map the quality query with its judgements.
24: * <p>
25: * The name-value pairs are used by a
26: * {@link org.apache.lucene.benchmark.quality.QualityQueryParser}
27: * to create a Lucene {@link org.apache.lucene.search.Query}.
28: * <p>
29: * It is very likely that name-value-pairs would be mapped into fields in a Lucene query,
30: * but it is up to the QualityQueryParser how to map - e.g. all values in a single field,
31: * or each pair as its own field, etc., - and this of course must match the way the
32: * searched index was constructed.
33: */
34: public class QualityQuery implements Comparable {
35: private String queryID;
36: private Map nameValPairs;
37:
38: /**
39: * Create a QualityQuery with given ID and name-value pairs.
40: * @param queryID ID of this quality query.
41: * @param nameValPairs the contents of this quality query.
42: */
43: public QualityQuery(String queryID, Map nameValPairs) {
44: this .queryID = queryID;
45: this .nameValPairs = nameValPairs;
46: }
47:
48: /**
49: * Return all the names of name-value-pairs in this QualityQuery.
50: */
51: public String[] getNames() {
52: return (String[]) nameValPairs.keySet().toArray(new String[0]);
53: }
54:
55: /**
56: * Return the value of a certain name-value pair.
57: * @param name the name whose value should be returned.
58: */
59: public String getValue(String name) {
60: return (String) nameValPairs.get(name);
61: }
62:
63: /**
64: * Return the ID of this query.
65: * The ID allows to map the quality query with its judgements.
66: */
67: public String getQueryID() {
68: return queryID;
69: }
70:
71: /* for a nicer sort of input queries before running them.
72: * Try first as ints, fall back to string if not int. */
73: public int compareTo(Object o) {
74: QualityQuery other = (QualityQuery) o;
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: }
|