forked from mdodsworth/lucene-solr
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SOLR-3670: New CountFieldValuesUpdateProcessorFactory (merge r1372687)
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/branch_4x@1372689 13f79535-47bb-0310-9956-ffa450edef68
- Loading branch information
Showing
4 changed files
with
176 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...ore/src/java/org/apache/solr/update/processor/CountFieldValuesUpdateProcessorFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.apache.solr.update.processor; | ||
|
||
import org.apache.solr.core.SolrCore; | ||
import org.apache.solr.schema.IndexSchema; | ||
import org.apache.solr.schema.FieldType; | ||
import org.apache.solr.schema.SchemaField; | ||
import org.apache.solr.schema.TextField; | ||
import org.apache.solr.schema.StrField; | ||
|
||
import org.apache.solr.common.SolrInputField; | ||
import org.apache.solr.common.util.NamedList; | ||
import org.apache.solr.request.SolrQueryRequest; | ||
import org.apache.solr.response.SolrQueryResponse; | ||
|
||
import org.apache.commons.lang.StringUtils; | ||
|
||
/** | ||
* <p> | ||
* Replaces any list of values for a field matching the specified | ||
* conditions with the the count of the number of values for that field. | ||
* </p> | ||
* <p> | ||
* By default, this processor matches no fields. | ||
* </p> | ||
* <p> | ||
* The typical use case for this processor would be in combination with the | ||
* {@link CloneFieldUpdateProcessorFactory} so that it's possible to query by | ||
* the quantity of values in the source field. | ||
* <p> | ||
* For example, in the configuration below, the end result will be that the | ||
* <code>category_count</code> field can be used to search for documents based | ||
* on how many values they contain in the <code>category</code> field. | ||
* </p> | ||
* | ||
* <pre class="prettyprint"> | ||
* <updateRequestProcessorChain> | ||
* <processor class="solr.CloneFieldUpdateProcessorFactory"> | ||
* <str name="source">category</str> | ||
* <str name="dest">category_count</str> | ||
* </processor> | ||
* <processor class="solr.CountFieldValuesUpdateProcessorFactory"> | ||
* <str name="fieldName">category_count</str> | ||
* </processor> | ||
* <processor class="solr.DefaultValueUpdateProcessorFactory"> | ||
* <str name="fieldName">category_count</str> | ||
* <int name="value">0</int> | ||
* </processor> | ||
* </updateRequestProcessorChain> | ||
* </pre> | ||
* | ||
* <p> | ||
* <b>NOTE:</b> The use of {@link DefaultValueUpdateProcessorFactory} is | ||
* important in this example to ensure that all documents have a value for the | ||
* <code>category_count</code> field, because | ||
* <code>CountFieldValuesUpdateProcessorFactory</code> only <i>replaces</i> the | ||
* list of values with the size of that list. If | ||
* <code>DefaultValueUpdateProcessorFactory</code> was not used, then any | ||
* document that had no values for the <code>category</code> field, would also | ||
* have no value in the <code>category_count</code> field. | ||
* </p> | ||
*/ | ||
public final class CountFieldValuesUpdateProcessorFactory extends FieldMutatingUpdateProcessorFactory { | ||
|
||
@Override | ||
public UpdateRequestProcessor getInstance(SolrQueryRequest req, | ||
SolrQueryResponse rsp, | ||
UpdateRequestProcessor next) { | ||
return new FieldMutatingUpdateProcessor(getSelector(), next) { | ||
protected SolrInputField mutate(final SolrInputField src) { | ||
SolrInputField result = new SolrInputField(src.getName()); | ||
result.setValue(src.getValueCount(), | ||
src.getBoost()); | ||
return result; | ||
} | ||
}; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters