+ *
+ * Name |
+ * Type |
+ * required |
+ * Description |
+ * Multi-valued |
+ *
+ *
+ * analysis.fieldname |
+ * string |
+ * no |
+ * When present, the text will be analyzed based on the type of this field name. |
+ * Yes, this parameter may hold a comma-separated list of values and the analysis will be performed for each of the specified fields |
+ *
+ *
+ * analysis.fieldtype |
+ * string |
+ * no |
+ * When present, the text will be analyzed based on the specified type |
+ * Yes, this parameter may hold a comma-separated list of values and the analysis will be performed for each of the specified field types |
+ *
+ *
+ * analysis.fieldvalue |
+ * string |
+ * yes |
+ * The text that will be analyzed. The analysis will mimic the index-time analysis. |
+ * No |
+ *
+ *
+ * {@code analysis.query} OR {@code q} |
+ * string |
+ * no |
+ * When present, the text that will be analyzed. The analysis will mimic the query-time analysis. Note that the
+ * {@code analysis.query} parameter as precedes the {@code q} parameters. |
+ * No |
+ *
+ *
+ * analysis.showmatch |
+ * boolean |
+ * no |
+ * When set to {@code true} and when query analysis is performed, the produced tokens of the field value
+ * analysis will be marked as "matched" for every token that is produces by the query analysis |
+ * No |
+ *
+ *
+ *
+ * @version $Id$
+ * @since solr 1.4
+ */
+public class FieldAnalysisRequestHandler extends AnalysisRequestHandlerBase {
+
+ /**
+ * {@inheritDoc}
+ */
+ protected NamedList doAnalysis(SolrQueryRequest req) throws Exception {
+ FieldAnalysisRequest analysisRequest = resolveAnalysisRequest(req.getParams());
+ IndexSchema indexSchema = req.getCore().getSchema();
+ return handleAnalysisRequest(analysisRequest, indexSchema);
+ }
+
+ @Override
+ public String getDescription() {
+ return "Provide a breakdown of the analysis process of field/query text";
+ }
+
+ @Override
+ public String getVersion() {
+ return "$Revision$";
+ }
+
+ @Override
+ public String getSourceId() {
+ return "$Id$";
+ }
+
+ @Override
+ public String getSource() {
+ return "$URL$";
+ }
+
+ // ================================================= Helper methods ================================================
+
+ /**
+ * Resolves the AnalysisRequest based on the parameters in the given SolrParams.
+ *
+ * @param solrParams SolrParams taken from request
+ *
+ * @return AnalysisRequest containing all the information about what needs to be analyzed, and using what
+ * fields/types
+ */
+ FieldAnalysisRequest resolveAnalysisRequest(SolrParams solrParams) {
+ FieldAnalysisRequest analysisRequest = new FieldAnalysisRequest();
+
+ if (solrParams.get(AnalysisParams.FIELD_TYPE) != null) {
+ analysisRequest.setFieldTypes(Arrays.asList(solrParams.get(AnalysisParams.FIELD_TYPE).split(",")));
+ }
+ if (solrParams.get(AnalysisParams.FIELD_NAME) != null) {
+ analysisRequest.setFieldNames(Arrays.asList(solrParams.get(AnalysisParams.FIELD_NAME).split(",")));
+ }
+ analysisRequest.setQuery(solrParams.get(AnalysisParams.QUERY, solrParams.get(CommonParams.Q)));
+ analysisRequest.setFieldValue(solrParams.get(AnalysisParams.FIELD_VALUE));
+ analysisRequest.setShowMatch(solrParams.getBool(AnalysisParams.SHOW_MATCH, false));
+ return analysisRequest;
+ }
+
+ /**
+ * Handles the resolved analysis request and returns the analysis breakdown response as a named list.
+ *
+ * @param request The request to handle.
+ * @param schema The index schema.
+ *
+ * @return The analysis breakdown as a named list.
+ */
+ protected NamedList