diff --git a/solr/src/java/org/apache/solr/handler/AnalysisRequestHandlerBase.java b/solr/src/java/org/apache/solr/handler/AnalysisRequestHandlerBase.java index b5216f7b274..b87dcc3d56f 100644 --- a/solr/src/java/org/apache/solr/handler/AnalysisRequestHandlerBase.java +++ b/solr/src/java/org/apache/solr/handler/AnalysisRequestHandlerBase.java @@ -47,6 +47,8 @@ import java.util.*; */ public abstract class AnalysisRequestHandlerBase extends RequestHandlerBase { + public static final Set EMPTY_STRING_SET = Collections.emptySet(); + public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throws Exception { rsp.add("analysis", doAnalysis(req)); } @@ -70,7 +72,7 @@ public abstract class AnalysisRequestHandlerBase extends RequestHandlerBase { * * @return NamedList containing the tokens produced by analyzing the given value */ - protected NamedList> analyzeValue(String value, AnalysisContext context) { + protected NamedList analyzeValue(String value, AnalysisContext context) { Analyzer analyzer = context.getAnalyzer(); @@ -93,7 +95,7 @@ public abstract class AnalysisRequestHandlerBase extends RequestHandlerBase { TokenizerFactory tfac = tokenizerChain.getTokenizerFactory(); TokenFilterFactory[] filtfacs = tokenizerChain.getTokenFilterFactories(); - NamedList> namedList = new NamedList>(); + NamedList namedList = new NamedList(); if( cfiltfacs != null ){ String source = value; @@ -234,7 +236,7 @@ public abstract class AnalysisRequestHandlerBase extends RequestHandlerBase { return tokensNamedLists; } - private String writeCharStream(NamedList out, CharStream input ){ + private String writeCharStream(NamedList out, CharStream input ){ final int BUFFER_SIZE = 1024; char[] buf = new char[BUFFER_SIZE]; int len = 0; @@ -252,7 +254,6 @@ public abstract class AnalysisRequestHandlerBase extends RequestHandlerBase { return sb.toString(); } - // ================================================= Inner classes ================================================= /** @@ -342,7 +343,7 @@ public abstract class AnalysisRequestHandlerBase extends RequestHandlerBase { * */ public AnalysisContext(String fieldName, FieldType fieldType, Analyzer analyzer) { - this(fieldName, fieldType, analyzer, Collections.EMPTY_SET); + this(fieldName, fieldType, analyzer, EMPTY_STRING_SET); } /** diff --git a/solr/src/java/org/apache/solr/handler/DocumentAnalysisRequestHandler.java b/solr/src/java/org/apache/solr/handler/DocumentAnalysisRequestHandler.java index 0f0aead5ec4..519674c782c 100644 --- a/solr/src/java/org/apache/solr/handler/DocumentAnalysisRequestHandler.java +++ b/solr/src/java/org/apache/solr/handler/DocumentAnalysisRequestHandler.java @@ -230,9 +230,8 @@ public class DocumentAnalysisRequestHandler extends AnalysisRequestHandlerBase { if (request.getQuery() != null) { try { - AnalysisContext analysisContext = new AnalysisContext(fieldType, fieldType.getQueryAnalyzer(), Collections.EMPTY_SET); - NamedList> tokens = analyzeValue(request.getQuery(), analysisContext); - fieldTokens.add("query", tokens); + AnalysisContext analysisContext = new AnalysisContext(fieldType, fieldType.getQueryAnalyzer(), EMPTY_STRING_SET); + fieldTokens.add("query", analyzeValue(request.getQuery(), analysisContext)); } catch (Exception e) { // ignore analysis exceptions since we are applying arbitrary text to all fields } @@ -241,10 +240,11 @@ public class DocumentAnalysisRequestHandler extends AnalysisRequestHandlerBase { Analyzer analyzer = fieldType.getAnalyzer(); AnalysisContext analysisContext = new AnalysisContext(fieldType, analyzer, termsToMatch); Collection fieldValues = document.getFieldValues(name); - NamedList>> indexTokens = new SimpleOrderedMap>>(); + NamedList> indexTokens + = new SimpleOrderedMap>(); for (Object fieldValue : fieldValues) { - NamedList> tokens = analyzeValue(fieldValue.toString(), analysisContext); - indexTokens.add(String.valueOf(fieldValue), tokens); + indexTokens.add(String.valueOf(fieldValue), + analyzeValue(fieldValue.toString(), analysisContext)); } fieldTokens.add("index", indexTokens); } diff --git a/solr/src/java/org/apache/solr/handler/DumpRequestHandler.java b/solr/src/java/org/apache/solr/handler/DumpRequestHandler.java index f1190005dfb..d858ef66e15 100644 --- a/solr/src/java/org/apache/solr/handler/DumpRequestHandler.java +++ b/solr/src/java/org/apache/solr/handler/DumpRequestHandler.java @@ -38,7 +38,7 @@ public class DumpRequestHandler extends RequestHandlerBase // Write the streams... if( req.getContentStreams() != null ) { - ArrayList streams = new ArrayList(); + ArrayList> streams = new ArrayList>(); // Cycle through each stream for( ContentStream content : req.getContentStreams() ) { NamedList stream = new SimpleOrderedMap(); diff --git a/solr/src/java/org/apache/solr/handler/JsonLoader.java b/solr/src/java/org/apache/solr/handler/JsonLoader.java index b96430bcd0c..c233ce634e4 100644 --- a/solr/src/java/org/apache/solr/handler/JsonLoader.java +++ b/solr/src/java/org/apache/solr/handler/JsonLoader.java @@ -69,6 +69,7 @@ class JsonLoader extends ContentStreamLoader { } } + @SuppressWarnings("fallthrough") void processUpdate(SolrQueryRequest req, UpdateRequestProcessor processor, JSONParser parser) throws IOException { int ev = parser.nextEvent(); diff --git a/solr/src/java/org/apache/solr/handler/ReplicationHandler.java b/solr/src/java/org/apache/solr/handler/ReplicationHandler.java index ad0cf117caf..a9983c798c8 100644 --- a/solr/src/java/org/apache/solr/handler/ReplicationHandler.java +++ b/solr/src/java/org/apache/solr/handler/ReplicationHandler.java @@ -94,7 +94,7 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAw private volatile IndexCommit indexCommitPoint; - volatile NamedList snapShootDetails; + volatile NamedList snapShootDetails; private AtomicBoolean replicationEnabled = new AtomicBoolean(true); @@ -189,13 +189,13 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAw } } - private List getCommits() { + private List> getCommits() { Map commits = core.getDeletionPolicy().getCommits(); - List l = new ArrayList(); + List> l = new ArrayList>(); for (IndexCommit c : commits.values()) { try { - NamedList nl = new NamedList(); + NamedList nl = new NamedList(); nl.add("indexVersion", c.getVersion()); nl.add(GENERATION, c.getGeneration()); nl.add(CMD_GET_FILE_LIST, c.getFileNames()); @@ -701,7 +701,7 @@ public class ReplicationHandler extends RequestHandlerBase implements SolrCoreAw return details; } - private void addVal(NamedList nl, String key, Properties props, Class clzz) { + private void addVal(NamedList nl, String key, Properties props, Class clzz) { String s = props.getProperty(key); if (s == null || s.trim().length() == 0) return; if (clzz == Date.class) { diff --git a/solr/src/java/org/apache/solr/handler/SnapPuller.java b/solr/src/java/org/apache/solr/handler/SnapPuller.java index 9af131fd1c4..1a41f827680 100644 --- a/solr/src/java/org/apache/solr/handler/SnapPuller.java +++ b/solr/src/java/org/apache/solr/handler/SnapPuller.java @@ -63,6 +63,9 @@ import java.util.zip.InflaterInputStream; public class SnapPuller { private static final Logger LOG = LoggerFactory.getLogger(SnapPuller.class.getName()); + private static final List> EMPTY_LIST_OF_MAPS + = Collections.emptyList(); + private final String masterUrl; private final ReplicationHandler replicationHandler; @@ -192,14 +195,14 @@ public class SnapPuller { return getNamedListResponse(post); } - private NamedList getNamedListResponse(PostMethod method) throws IOException { + private NamedList getNamedListResponse(PostMethod method) throws IOException { try { int status = myHttpClient.executeMethod(method); if (status != HttpStatus.SC_OK) { throw new SolrException(SolrException.ErrorCode.SERVICE_UNAVAILABLE, "Request failed for the url " + method); } - return (NamedList) new JavaBinCodec().unmarshal(method.getResponseBodyAsStream()); + return (NamedList) new JavaBinCodec().unmarshal(method.getResponseBodyAsStream()); } finally { try { method.releaseConnection(); @@ -216,8 +219,12 @@ public class SnapPuller { post.addParameter(COMMAND, CMD_GET_FILE_LIST); post.addParameter(CMD_INDEX_VERSION, String.valueOf(version)); post.addParameter("wt", "javabin"); - NamedList nl = getNamedListResponse(post); - List> f = (List>) nl.get(CMD_GET_FILE_LIST); + + @SuppressWarnings("unchecked") + NamedList>> nl + = (NamedList>>) getNamedListResponse(post); + + List> f = nl.get(CMD_GET_FILE_LIST); if (f != null) filesToDownload = Collections.synchronizedList(f); else { @@ -225,7 +232,7 @@ public class SnapPuller { LOG.error("No files to download for indexversion: "+ version); } - f = (List>) nl.get(CONF_FILES); + f = nl.get(CONF_FILES); if (f != null) confFilesToDownload = Collections.synchronizedList(f); } @@ -704,10 +711,11 @@ public class SnapPuller { */ private Collection> getModifiedConfFiles(List> confFilesToDownload) { if (confFilesToDownload == null || confFilesToDownload.isEmpty()) - return Collections.EMPTY_LIST; + return EMPTY_LIST_OF_MAPS; + //build a map with alias/name as the key Map> nameVsFile = new HashMap>(); - NamedList names = new NamedList(); + NamedList names = new NamedList(); for (Map map : confFilesToDownload) { //if alias is present that is the name the file may have in the slave String name = (String) (map.get(ALIAS) == null ? map.get(NAME) : map.get(ALIAS)); @@ -725,7 +733,7 @@ public class SnapPuller { nameVsFile.remove(name); //checksums are same so the file need not be downloaded } } - return nameVsFile.isEmpty() ? Collections.EMPTY_LIST : nameVsFile.values(); + return nameVsFile.isEmpty() ? EMPTY_LIST_OF_MAPS : nameVsFile.values(); } /** @@ -788,25 +796,25 @@ public class SnapPuller { //make a copy first because it can be null later List> tmp = confFilesToDownload; //create a new instance. or else iterator may fail - return tmp == null ? Collections.EMPTY_LIST : new ArrayList>(tmp); + return tmp == null ? EMPTY_LIST_OF_MAPS : new ArrayList>(tmp); } List> getConfFilesDownloaded() { //make a copy first because it can be null later List> tmp = confFilesDownloaded; // NOTE: it's safe to make a copy of a SynchronizedCollection(ArrayList) - return tmp == null ? Collections.EMPTY_LIST : new ArrayList>(tmp); + return tmp == null ? EMPTY_LIST_OF_MAPS : new ArrayList>(tmp); } List> getFilesToDownload() { //make a copy first because it can be null later List> tmp = filesToDownload; - return tmp == null ? Collections.EMPTY_LIST : new ArrayList>(tmp); + return tmp == null ? EMPTY_LIST_OF_MAPS : new ArrayList>(tmp); } List> getFilesDownloaded() { List> tmp = filesDownloaded; - return tmp == null ? Collections.EMPTY_LIST : new ArrayList>(tmp); + return tmp == null ? EMPTY_LIST_OF_MAPS : new ArrayList>(tmp); } Map getCurrentFile() { diff --git a/solr/src/java/org/apache/solr/handler/SnapShooter.java b/solr/src/java/org/apache/solr/handler/SnapShooter.java index df99c7cb97d..c1992636c2e 100644 --- a/solr/src/java/org/apache/solr/handler/SnapShooter.java +++ b/solr/src/java/org/apache/solr/handler/SnapShooter.java @@ -71,7 +71,8 @@ public class SnapShooter { } void createSnapshot(final IndexCommit indexCommit, ReplicationHandler replicationHandler) { - NamedList details = new NamedList(); + + NamedList details = new NamedList(); details.add("startTime", new Date().toString()); File snapShotDir = null; String directoryName = null; diff --git a/solr/src/java/org/apache/solr/handler/component/StatsComponent.java b/solr/src/java/org/apache/solr/handler/component/StatsComponent.java index 8896d73d172..dc0b4333047 100644 --- a/solr/src/java/org/apache/solr/handler/component/StatsComponent.java +++ b/solr/src/java/org/apache/solr/handler/component/StatsComponent.java @@ -124,8 +124,8 @@ public class StatsComponent extends SearchComponent { StatsInfo si = rb._statsInfo; - NamedList stats = new SimpleOrderedMap(); - NamedList stats_fields = new SimpleOrderedMap(); + NamedList> stats = new SimpleOrderedMap>(); + NamedList stats_fields = new SimpleOrderedMap(); stats.add("stats_fields", stats_fields); for (String field : si.statsFields.keySet()) { NamedList stv = si.statsFields.get(field).getStatsValues(); @@ -209,8 +209,8 @@ class SimpleStats { return res; } - public NamedList getStatsFields() throws IOException { - NamedList> res = new SimpleOrderedMap>(); + public NamedList getStatsFields() throws IOException { + NamedList res = new SimpleOrderedMap(); String[] statsFs = params.getParams(StatsParams.STATS_FIELD); boolean isShard = params.getBool(ShardParams.IS_SHARD, false); if (null != statsFs) { @@ -221,7 +221,7 @@ class SimpleStats { } SchemaField sf = searcher.getSchema().getField(f); FieldType ft = sf.getType(); - NamedList stv; + NamedList stv; // Currently, only UnInvertedField can deal with multi-part trie fields String prefix = TrieField.getMainValuePrefix(ft); @@ -243,7 +243,7 @@ class SimpleStats { return res; } - public NamedList getFieldCacheStats(String fieldName, String[] facet ) { + public NamedList getFieldCacheStats(String fieldName, String[] facet ) { FieldType ft = searcher.getSchema().getFieldType(fieldName); FieldCache.DocTermsIndex si = null; diff --git a/solr/src/java/org/apache/solr/handler/component/TermVectorComponent.java b/solr/src/java/org/apache/solr/handler/component/TermVectorComponent.java index f190ab4ba1f..59310c6fa14 100644 --- a/solr/src/java/org/apache/solr/handler/component/TermVectorComponent.java +++ b/solr/src/java/org/apache/solr/handler/component/TermVectorComponent.java @@ -77,7 +77,7 @@ public class TermVectorComponent extends SearchComponent implements SolrCoreAwar return; } - NamedList termVectors = new NamedList(); + NamedList termVectors = new NamedList(); rb.rsp.add(TERM_VECTORS, termVectors); FieldOptions allFields = new FieldOptions(); //figure out what options we have, and try to get the appropriate vector @@ -106,7 +106,7 @@ public class TermVectorComponent extends SearchComponent implements SolrCoreAwar IndexSchema schema = rb.req.getSchema(); //Build up our per field mapping Map fieldOptions = new HashMap(); - NamedList warnings = new NamedList(); + NamedList> warnings = new NamedList>(); List noTV = new ArrayList(); List noPos = new ArrayList(); List noOff = new ArrayList(); @@ -187,7 +187,7 @@ public class TermVectorComponent extends SearchComponent implements SolrCoreAwar mapper.fieldOptions = allFields; //this will only stay set if fieldOptions.isEmpty() (in other words, only if the user didn't set any fields) while (iter.hasNext()) { Integer docId = iter.next(); - NamedList docNL = new NamedList(); + NamedList docNL = new NamedList(); mapper.docNL = docNL; termVectors.add("doc-" + docId, docNL); @@ -272,7 +272,7 @@ public class TermVectorComponent extends SearchComponent implements SolrCoreAwar private static class TVMapper extends TermVectorMapper { private IndexReader reader; - private NamedList docNL; + private NamedList docNL; //needs to be set for each new field FieldOptions fieldOptions; @@ -280,7 +280,7 @@ public class TermVectorComponent extends SearchComponent implements SolrCoreAwar //internal vars not passed in by construction private boolean useOffsets, usePositions; //private Map idfCache; - private NamedList fieldNL; + private NamedList fieldNL; private Term currentTerm; @@ -289,34 +289,34 @@ public class TermVectorComponent extends SearchComponent implements SolrCoreAwar } public void map(BytesRef term, int frequency, TermVectorOffsetInfo[] offsets, int[] positions) { - NamedList termInfo = new NamedList(); - fieldNL.add(term.utf8ToString(), termInfo); - if (fieldOptions.termFreq == true) { - termInfo.add("tf", frequency); + NamedList termInfo = new NamedList(); + fieldNL.add(term.utf8ToString(), termInfo); + if (fieldOptions.termFreq == true) { + termInfo.add("tf", frequency); + } + if (useOffsets == true) { + NamedList theOffsets = new NamedList(); + termInfo.add("offsets", theOffsets); + for (int i = 0; i < offsets.length; i++) { + TermVectorOffsetInfo offset = offsets[i]; + theOffsets.add("start", offset.getStartOffset()); + theOffsets.add("end", offset.getEndOffset()); } - if (useOffsets == true) { - NamedList theOffsets = new NamedList(); - termInfo.add("offsets", theOffsets); - for (int i = 0; i < offsets.length; i++) { - TermVectorOffsetInfo offset = offsets[i]; - theOffsets.add("start", offset.getStartOffset()); - theOffsets.add("end", offset.getEndOffset()); - } - } - if (usePositions == true) { - NamedList positionsNL = new NamedList(); - for (int i = 0; i < positions.length; i++) { - positionsNL.add("position", positions[i]); - } - termInfo.add("positions", positionsNL); - } - if (fieldOptions.docFreq == true) { - termInfo.add("df", getDocFreq(term)); - } - if (fieldOptions.tfIdf == true) { - double tfIdfVal = ((double) frequency) / getDocFreq(term); - termInfo.add("tf-idf", tfIdfVal); + } + if (usePositions == true) { + NamedList positionsNL = new NamedList(); + for (int i = 0; i < positions.length; i++) { + positionsNL.add("position", positions[i]); } + termInfo.add("positions", positionsNL); + } + if (fieldOptions.docFreq == true) { + termInfo.add("df", getDocFreq(term)); + } + if (fieldOptions.tfIdf == true) { + double tfIdfVal = ((double) frequency) / getDocFreq(term); + termInfo.add("tf-idf", tfIdfVal); + } } private int getDocFreq(BytesRef term) { @@ -343,7 +343,7 @@ public class TermVectorComponent extends SearchComponent implements SolrCoreAwar } useOffsets = storeOffsets && fieldOptions.offsets; usePositions = storePositions && fieldOptions.positions; - fieldNL = new NamedList(); + fieldNL = new NamedList(); docNL.add(field, fieldNL); } @@ -394,4 +394,4 @@ public class TermVectorComponent extends SearchComponent implements SolrCoreAwar class FieldOptions { String fieldName; boolean termFreq, positions, offsets, docFreq, tfIdf; -} \ No newline at end of file +} diff --git a/solr/src/java/org/apache/solr/request/UnInvertedField.java b/solr/src/java/org/apache/solr/request/UnInvertedField.java index 01fe7ae017d..3845ec9ba31 100755 --- a/solr/src/java/org/apache/solr/request/UnInvertedField.java +++ b/solr/src/java/org/apache/solr/request/UnInvertedField.java @@ -900,15 +900,15 @@ public class UnInvertedField { //////////////////////////// caching ///////////////////////////// ////////////////////////////////////////////////////////////////// public static UnInvertedField getUnInvertedField(String field, SolrIndexSearcher searcher) throws IOException { - SolrCache cache = searcher.getFieldValueCache(); + SolrCache cache = searcher.getFieldValueCache(); if (cache == null) { return new UnInvertedField(field, searcher); } - UnInvertedField uif = (UnInvertedField)cache.get(field); + UnInvertedField uif = cache.get(field); if (uif == null) { synchronized (cache) { - uif = (UnInvertedField)cache.get(field); + uif = cache.get(field); if (uif == null) { uif = new UnInvertedField(field, searcher); cache.put(field, uif); @@ -918,7 +918,6 @@ public class UnInvertedField { return uif; } - } diff --git a/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java b/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java index a011acf4f01..d175a712835 100644 --- a/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java +++ b/solr/src/java/org/apache/solr/search/SolrIndexSearcher.java @@ -79,7 +79,7 @@ public class SolrIndexSearcher extends IndexSearcher implements SolrInfoMBean { private final SolrCache filterCache; private final SolrCache queryResultCache; private final SolrCache documentCache; - private final SolrCache fieldValueCache; + private final SolrCache fieldValueCache; private final LuceneQueryOptimizer optimizer; @@ -470,7 +470,7 @@ public class SolrIndexSearcher extends IndexSearcher implements SolrInfoMBean { //////////////////////////////////////////////////////////////////////////////// /** expert: internal API, subject to change */ - public SolrCache getFieldValueCache() { + public SolrCache getFieldValueCache() { return fieldValueCache; }