1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.search.solr.internal

File DefaultSolrConfiguration.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

0
8
7
1
168
69
7
0.88
1.14
7
1

Classes

Class Line # Actions
DefaultSolrConfiguration 40 8 0% 7 0
1.0100%
 

Contributing tests

This file is covered by 3 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.search.solr.internal;
21   
22    import java.io.InputStream;
23   
24    import javax.inject.Inject;
25    import javax.inject.Named;
26    import javax.inject.Singleton;
27   
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.configuration.ConfigurationSource;
30    import org.xwiki.search.solr.internal.api.SolrConfiguration;
31   
32    /**
33    * Default implementation for {@link SolrConfiguration} that uses the xwiki.properties file.
34    *
35    * @version $Id: 3ffdb1c77c87df4f05e4119a43face873cc4af18 $
36    * @since 4.5M1
37    */
38    @Component
39    @Singleton
 
40    public class DefaultSolrConfiguration implements SolrConfiguration
41    {
42    /**
43    * Default component type.
44    */
45    public static final String DEFAULT_SOLR_TYPE = "embedded";
46   
47    /**
48    * The classpath location prefix to use when looking for the default solr configuration files.
49    */
50    public static final String CLASSPATH_LOCATION_PREFIX = "/solr/%s";
51   
52    /**
53    * Name of the classpath folder where the default configuration files are located.
54    */
55    public static final String CONF_DIRECTORY = "conf";
56   
57    /**
58    * Classpath location pattern for the default configuration files.
59    */
60    public static final String CONF_FILE_LOCATION_PATTERN = "/%s/%s/%s";
61   
62    /**
63    * Solr home directory file names.
64    */
65    public static final String[] HOME_DIRECTORY_FILE_NAMES = {"solr.xml"};
66   
67    /**
68    * The package containing the Solr core configuration files.
69    */
70    public static final String HOME_DIRECTORY_CORE_PACKAGE = "solr.xwiki";
71   
72    /**
73    * The prefix of the solr resources.
74    */
75    public static final String HOME_DIRECTORY_PREFIX = "solr/";
76   
77    /**
78    * The name of the configuration property containing the batch size.
79    */
80    public static final String SOLR_INDEXER_BATCH_SIZE_PROPERTY = "solr.indexer.batch.size";
81   
82    /**
83    * The default size of the batch.
84    */
85    public static final int SOLR_INDEXER_BATCH_SIZE_DEFAULT = 50;
86   
87    /**
88    * The name of the configuration property containing the batch maximum length.
89    */
90    public static final String SOLR_INDEXER_BATCH_MAXLENGH_PROPERTY = "solr.indexer.batch.maxLength";
91   
92    /**
93    * The default length of the data above which the batch is sent without waiting.
94    */
95    public static final int SOLR_INDEXER_BATCH_MAXLENGH_DEFAULT = 10000;
96   
97    /**
98    * The name of the configuration property containing the batch size.
99    */
100    public static final String SOLR_INDEXER_QUEUE_CAPACITY_PROPERTY = "solr.indexer.queue.capacity";
101   
102    /**
103    * The default size of the batch.
104    */
105    public static final int SOLR_INDEXER_QUEUE_CAPACITY_DEFAULT = 100000;
106   
107    /**
108    * The name of the configuration property indicating if a synchronization should be run at startup.
109    */
110    public static final String SOLR_SYNCHRONIZE_AT_STARTUP = "solr.synchronizeAtStartup";
111   
112    /**
113    * Indicate if a synchronization should be run at startup by default.
114    */
115    public static final boolean SOLR_SYNCHRONIZE_AT_STARTUP_DEFAULT = true;
116   
117    /**
118    * The Solr configuration source.
119    */
120    @Inject
121    @Named("xwikiproperties")
122    private ConfigurationSource configuration;
123   
 
124  3 toggle @Override
125    public String getServerType()
126    {
127  3 return this.configuration.getProperty("solr.type", DEFAULT_SOLR_TYPE);
128    }
129   
 
130  6 toggle @Override
131    public <T> T getInstanceConfiguration(String instanceType, String propertyName, T defaultValue)
132    {
133  6 String actualPropertyName = String.format("%s.%s.%s", "solr", instanceType, propertyName);
134  6 return this.configuration.getProperty(actualPropertyName, defaultValue);
135    }
136   
 
137  4 toggle @Override
138    public InputStream getHomeDirectoryConfiguration()
139    {
140  4 return getClass().getResourceAsStream("/xwiki-platform-search-solr-server-data.zip");
141    }
142   
 
143  4234 toggle @Override
144    public int getIndexerBatchSize()
145    {
146  4234 return this.configuration.getProperty(SOLR_INDEXER_BATCH_SIZE_PROPERTY, SOLR_INDEXER_BATCH_SIZE_DEFAULT);
147    }
148   
 
149  4469 toggle @Override
150    public int getIndexerBatchMaxLengh()
151    {
152  4469 return this.configuration
153    .getProperty(SOLR_INDEXER_BATCH_MAXLENGH_PROPERTY, SOLR_INDEXER_BATCH_MAXLENGH_DEFAULT);
154    }
155   
 
156  3 toggle @Override
157    public int getIndexerQueueCapacity()
158    {
159  3 return this.configuration
160    .getProperty(SOLR_INDEXER_QUEUE_CAPACITY_PROPERTY, SOLR_INDEXER_QUEUE_CAPACITY_DEFAULT);
161    }
162   
 
163  3 toggle @Override
164    public boolean synchronizeAtStartup()
165    {
166  3 return this.configuration.getProperty(SOLR_SYNCHRONIZE_AT_STARTUP, SOLR_SYNCHRONIZE_AT_STARTUP_DEFAULT);
167    }
168    }