001: /**
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */package org.apache.solr.util;
017:
018: import org.apache.solr.core.SolrCore;
019: import org.apache.solr.core.SolrInfoMBean;
020: import org.apache.solr.core.SolrException;
021:
022: import org.apache.solr.util.StrUtils;
023: import org.apache.solr.util.NamedList;
024:
025: import java.util.logging.Logger;
026: import java.util.logging.Level;
027: import java.util.logging.Handler;
028:
029: import java.util.Arrays;
030: import java.util.ArrayList;
031: import java.util.List;
032: import java.util.Collection;
033: import java.util.Set;
034: import java.util.HashSet;
035: import java.util.Map;
036: import java.util.HashMap;
037: import java.util.regex.Pattern;
038: import java.io.IOException;
039:
040: /**
041: * A collection of params used in DisMaxRequestHandler,
042: * both for Plugin initialization and for Requests.
043: */
044: public class DisMaxParams extends CommonParams {
045:
046: /** query and init param for tiebreaker value */
047: public static String TIE = "tie";
048: /** query and init param for query fields */
049: public static String QF = "qf";
050: /** query and init param for phrase boost fields */
051: public static String PF = "pf";
052: /** query and init param for MinShouldMatch specification */
053: public static String MM = "mm";
054: /**
055: * query and init param for Phrase Slop value in phrase
056: * boost query (in pf fields)
057: */
058: public static String PS = "ps";
059: /**
060: * query and init param for phrase Slop value in phrases
061: * explicitly included in the user's query string ( in qf fields)
062: */
063: public static String QS = "qs";
064: /** query and init param for boosting query */
065: public static String BQ = "bq";
066: /** query and init param for boosting functions */
067: public static String BF = "bf";
068: /**
069: * Alternate query (expressed in Solr QuerySyntax)
070: * to use if main query (q) is empty
071: */
072: public static String ALTQ = "q.alt";
073: /** query and init param for filtering query
074: * @deprecated use SolrParams.FQ or SolrPluginUtils.parseFilterQueries
075: */
076: public static String FQ = "fq";
077: /** query and init param for field list */
078: public static String GEN = "gen";
079:
080: /**
081: * the default tie breaker to use in DisjunctionMaxQueries
082: * @deprecated - use explicit default with SolrParams.getFloat
083: */
084: public float tiebreaker = 0.0f;
085: /**
086: * the default query fields to be used
087: * @deprecated - use explicit default with SolrParams.get
088: */
089: public String qf = null;
090: /**
091: * the default phrase boosting fields to be used
092: * @deprecated - use explicit default with SolrParams.get
093: */
094: public String pf = null;
095: /**
096: * the default min should match to be used
097: * @deprecated - use explicit default with SolrParams.get
098: */
099: public String mm = "100%";
100: /**
101: * the default phrase slop to be used
102: * @deprecated - use explicit default with SolrParams.getInt
103: */
104: public int pslop = 0;
105: /**
106: * the default boosting query to be used
107: * @deprecated - use explicit default with SolrParams.get
108: */
109: public String bq = null;
110: /**
111: * the default boosting functions to be used
112: * @deprecated - use explicit default with SolrParams.get
113: */
114: public String bf = null;
115: /**
116: * the default filtering query to be used
117: * @deprecated - use explicit default with SolrParams.get
118: */
119: public String fq = null;
120:
121: /**
122: * Sets the params using values from a NamedList, usefull in the
123: * init method for your handler.
124: *
125: * <p>
126: * If any param is not of the expected type, a severe error is
127: * logged,and the param is skipped.
128: * </p>
129: *
130: * <p>
131: * If any param is not of in the NamedList, it is skipped and the
132: * old value is left alone.
133: * </p>
134: * @deprecated use SolrParams.toSolrParams
135: */
136: public void setValues(NamedList args) {
137:
138: super .setValues(args);
139:
140: Object tmp;
141:
142: tmp = args.get(TIE);
143: if (null != tmp) {
144: if (tmp instanceof Float) {
145: tiebreaker = ((Float) tmp).floatValue();
146: } else {
147: SolrCore.log
148: .severe("init param is not a float: " + TIE);
149: }
150: }
151:
152: tmp = args.get(QF);
153: if (null != tmp) {
154: if (tmp instanceof String) {
155: qf = tmp.toString();
156: } else {
157: SolrCore.log.severe("init param is not a str: " + QF);
158: }
159: }
160:
161: tmp = args.get(PF);
162: if (null != tmp) {
163: if (tmp instanceof String) {
164: pf = tmp.toString();
165: } else {
166: SolrCore.log.severe("init param is not a str: " + PF);
167: }
168: }
169:
170: tmp = args.get(MM);
171: if (null != tmp) {
172: if (tmp instanceof String) {
173: mm = tmp.toString();
174: } else {
175: SolrCore.log.severe("init param is not a str: " + MM);
176: }
177: }
178:
179: tmp = args.get(PS);
180: if (null != tmp) {
181: if (tmp instanceof Integer) {
182: pslop = ((Integer) tmp).intValue();
183: } else {
184: SolrCore.log.severe("init param is not an int: " + PS);
185: }
186: }
187:
188: tmp = args.get(BQ);
189: if (null != tmp) {
190: if (tmp instanceof String) {
191: bq = tmp.toString();
192: } else {
193: SolrCore.log.severe("init param is not a str: " + BQ);
194: }
195: }
196:
197: tmp = args.get(BF);
198: if (null != tmp) {
199: if (tmp instanceof String) {
200: bf = tmp.toString();
201: } else {
202: SolrCore.log.severe("init param is not a str: " + BF);
203: }
204: }
205:
206: tmp = args.get(FQ);
207: if (null != tmp) {
208: if (tmp instanceof String) {
209: fq = tmp.toString();
210: } else {
211: SolrCore.log.severe("init param is not a str: " + FQ);
212: }
213: }
214:
215: }
216:
217: }
|