19 package org.sleuthkit.autopsy.keywordsearch;
 
   21 import java.awt.event.ActionEvent;
 
   22 import java.beans.PropertyChangeListener;
 
   23 import java.io.BufferedReader;
 
   24 import java.io.BufferedWriter;
 
   26 import java.io.FileOutputStream;
 
   27 import java.io.IOException;
 
   28 import java.io.InputStream;
 
   29 import java.io.InputStreamReader;
 
   30 import java.io.OutputStream;
 
   31 import java.io.OutputStreamWriter;
 
   32 import java.net.ConnectException;
 
   33 import java.net.ServerSocket;
 
   34 import java.net.SocketException;
 
   35 import java.nio.charset.Charset;
 
   36 import java.nio.file.Path;
 
   37 import java.nio.file.Paths;
 
   38 import java.util.ArrayList;
 
   39 import java.util.Collection;
 
   40 import java.util.List;
 
   41 import java.util.concurrent.locks.ReentrantReadWriteLock;
 
   42 import java.util.logging.Level;
 
   43 import javax.swing.AbstractAction;
 
   44 import org.apache.solr.client.solrj.SolrQuery;
 
   45 import org.apache.solr.client.solrj.SolrRequest;
 
   46 import org.apache.solr.client.solrj.SolrServerException;
 
   47 import org.apache.solr.client.solrj.impl.HttpSolrServer;
 
   48 import org.apache.solr.client.solrj.impl.XMLResponseParser;
 
   49 import org.apache.solr.client.solrj.request.CoreAdminRequest;
 
   50 import org.apache.solr.client.solrj.response.CoreAdminResponse;
 
   51 import org.apache.solr.client.solrj.response.QueryResponse;
 
   52 import org.apache.solr.client.solrj.response.TermsResponse;
 
   53 import org.apache.solr.common.SolrDocument;
 
   54 import org.apache.solr.common.SolrDocumentList;
 
   55 import org.apache.solr.common.SolrException;
 
   56 import org.apache.solr.common.SolrInputDocument;
 
   57 import org.apache.solr.common.util.NamedList;
 
   58 import org.openide.modules.InstalledFileLocator;
 
   59 import org.openide.modules.Places;
 
   60 import org.openide.util.NbBundle;
 
   83             public String toString() {
 
   89             public String toString() {
 
   96             public String toString() {
 
  102             public String toString() {
 
  108             public String toString() {
 
  114             public String toString() {
 
  121             public String toString() {
 
  128             public String toString() {
 
  135             public String toString() {
 
  142             public String toString() {
 
  148             public String toString() {
 
  167     static final String PROPERTIES_FILE = KeywordSearchSettings.MODULE_NAME;
 
  168     static final String PROPERTIES_CURRENT_SERVER_PORT = 
"IndexingServerPort"; 
 
  169     static final String PROPERTIES_CURRENT_STOP_PORT = 
"IndexingServerStopPort"; 
 
  170     private static final String 
KEY = 
"jjk#09s"; 
 
  171     static final String DEFAULT_SOLR_SERVER_HOST = 
"localhost"; 
 
  172     static final int DEFAULT_SOLR_SERVER_PORT = 23232;
 
  173     static final int DEFAULT_SOLR_STOP_PORT = 34343;
 
  176     private static final boolean DEBUG = 
false;
 
  178     private static final String 
SOLR = 
"solr";
 
  207         this.localSolrServer = 
new HttpSolrServer(
"http://localhost:" + currentSolrServerPort + 
"/solr"); 
 
  208         serverAction = 
new ServerAction();
 
  209         solrFolder = InstalledFileLocator.getDefault().locate(
"solr", 
Server.class.getPackage().getName(), 
false); 
 
  212         currentCoreLock = 
new ReentrantReadWriteLock(
true);
 
  215         logger.log(Level.INFO, 
"Created Server instance"); 
 
  223             } 
catch (NumberFormatException nfe) {
 
  224                 logger.log(Level.WARNING, 
"Could not decode indexing server port, value was not a valid port number, using the default. ", nfe); 
 
  225                 currentSolrServerPort = DEFAULT_SOLR_SERVER_PORT;
 
  228             currentSolrServerPort = DEFAULT_SOLR_SERVER_PORT;
 
  235             } 
catch (NumberFormatException nfe) {
 
  236                 logger.log(Level.WARNING, 
"Could not decode indexing server stop port, value was not a valid port number, using default", nfe); 
 
  237                 currentSolrStopPort = DEFAULT_SOLR_STOP_PORT;
 
  240             currentSolrStopPort = DEFAULT_SOLR_STOP_PORT;
 
  246     public void finalize() throws java.lang.Throwable {
 
  252         serverAction.addPropertyChangeListener(l);
 
  255     int getCurrentSolrServerPort() {
 
  259     int getCurrentSolrStopPort() {
 
  270         volatile boolean doRun = 
true;
 
  273             this.stream = stream;
 
  275                 final String log = Places.getUserDirectory().getAbsolutePath()
 
  276                         + File.separator + 
"var" + File.separator + 
"log"  
  277                         + File.separator + 
"solr.log." + type; 
 
  278                 File outputFile = 
new File(log.concat(
".0"));
 
  279                 File first = 
new File(log.concat(
".1"));
 
  280                 File second = 
new File(log.concat(
".2"));
 
  281                 if (second.exists()) {
 
  284                 if (first.exists()) {
 
  285                     first.renameTo(second);
 
  287                 if (outputFile.exists()) {
 
  288                     outputFile.renameTo(first);
 
  290                     outputFile.createNewFile();
 
  292                 out = 
new FileOutputStream(outputFile);
 
  294             } 
catch (Exception ex) {
 
  295                 logger.log(Level.WARNING, 
"Failed to create solr log file", ex); 
 
  306             try (InputStreamReader isr = 
new InputStreamReader(stream);
 
  307                     BufferedReader br = 
new BufferedReader(isr);
 
  309                     BufferedWriter bw = 
new BufferedWriter(osw);) {
 
  312                 while (doRun && (line = br.readLine()) != null) {
 
  321             } 
catch (IOException ex) {
 
  322                 logger.log(Level.SEVERE, 
"Error redirecting Solr output stream", ex); 
 
  332     List<Long> getSolrPIDs() {
 
  333         List<Long> pids = 
new ArrayList<>();
 
  336         final String pidsQuery = 
"Args.4.eq=-DSTOP.KEY=" + KEY + 
",Args.6.eq=start.jar"; 
 
  339         if (pidsArr != null) {
 
  340             for (
int i = 0; i < pidsArr.length; ++i) {
 
  341                 pids.add(pidsArr[i]);
 
  353         List<Long> solrPids = getSolrPIDs();
 
  354         for (
long pid : solrPids) {
 
  355             logger.log(Level.INFO, 
"Trying to kill old Solr process, PID: {0}", pid); 
 
  356             PlatformUtil.killProcess(pid);
 
  365     void start() throws KeywordSearchModuleException, SolrServerNoPortException {
 
  371         if (!isPortAvailable(currentSolrServerPort)) {
 
  375             final List<Long> pids = this.getSolrPIDs();
 
  379             if (pids.isEmpty()) {
 
  380                 throw new SolrServerNoPortException(currentSolrServerPort);
 
  389             if (!isPortAvailable(currentSolrServerPort)) {
 
  390                 throw new SolrServerNoPortException(currentSolrServerPort);
 
  392             if (!isPortAvailable(currentSolrStopPort)) {
 
  393                 throw new SolrServerNoPortException(currentSolrStopPort);
 
  397         logger.log(Level.INFO, 
"Starting Solr server from: {0}", solrFolder.getAbsolutePath()); 
 
  399         if (isPortAvailable(currentSolrServerPort)) {
 
  400             logger.log(Level.INFO, 
"Port [{0}] available, starting Solr", currentSolrServerPort); 
 
  402                 final String MAX_SOLR_MEM_MB_PAR = 
"-Xmx" + Integer.toString(MAX_SOLR_MEM_MB) + 
"m"; 
 
  403                 List<String> commandLine = 
new ArrayList<>();
 
  404                 commandLine.add(javaPath);
 
  405                 commandLine.add(MAX_SOLR_MEM_MB_PAR);
 
  406                 commandLine.add(
"-DSTOP.PORT=" + currentSolrStopPort); 
 
  407                 commandLine.add(
"-Djetty.port=" + currentSolrServerPort); 
 
  408                 commandLine.add(
"-DSTOP.KEY=" + KEY); 
 
  409                 commandLine.add(
"-jar"); 
 
  410                 commandLine.add(
"start.jar"); 
 
  412                 ProcessBuilder solrProcessBuilder = 
new ProcessBuilder(commandLine);
 
  413                 solrProcessBuilder.directory(solrFolder);
 
  416                 Path solrStdoutPath = Paths.get(Places.getUserDirectory().getAbsolutePath(), 
"var", 
"log", 
"solr.log.stdout"); 
 
  417                 solrProcessBuilder.redirectOutput(solrStdoutPath.toFile());
 
  419                 Path solrStderrPath = Paths.get(Places.getUserDirectory().getAbsolutePath(), 
"var", 
"log", 
"solr.log.stderr"); 
 
  420                 solrProcessBuilder.redirectError(solrStderrPath.toFile());
 
  422                 logger.log(Level.INFO, 
"Starting Solr using: {0}", solrProcessBuilder.command()); 
 
  423                 curSolrProcess = solrProcessBuilder.start();
 
  424                 logger.log(Level.INFO, 
"Finished starting Solr"); 
 
  429                     Thread.sleep(10 * 1000);
 
  430                 } 
catch (InterruptedException ex) {
 
  431                     logger.log(Level.WARNING, 
"Timer interrupted"); 
 
  434                 final List<Long> pids = this.getSolrPIDs();
 
  435                 logger.log(Level.INFO, 
"New Solr process PID: {0}", pids); 
 
  436             } 
catch (SecurityException ex) {
 
  437                 logger.log(Level.SEVERE, 
"Could not start Solr process!", ex); 
 
  438                 throw new KeywordSearchModuleException(
 
  439                         NbBundle.getMessage(
this.getClass(), 
"Server.start.exception.cantStartSolr.msg"), ex);
 
  440             } 
catch (IOException ex) {
 
  441                 logger.log(Level.SEVERE, 
"Could not start Solr server process!", ex); 
 
  442                 throw new KeywordSearchModuleException(
 
  443                         NbBundle.getMessage(
this.getClass(), 
"Server.start.exception.cantStartSolr.msg2"), ex);
 
  453     static boolean isPortAvailable(
int port) {
 
  454         ServerSocket ss = null;
 
  457             ss = 
new ServerSocket(port, 0, java.net.Inet4Address.getByName(
"localhost")); 
 
  459                 ss.setReuseAddress(
true);
 
  464         } 
catch (IOException e) {
 
  469                 } 
catch (IOException e) {
 
  484     void changeSolrServerPort(
int port) {
 
  485         currentSolrServerPort = port;
 
  486         ModuleSettings.setConfigSetting(PROPERTIES_FILE, PROPERTIES_CURRENT_SERVER_PORT, String.valueOf(port));
 
  494     void changeSolrStopPort(
int port) {
 
  495         currentSolrStopPort = port;
 
  496         ModuleSettings.setConfigSetting(PROPERTIES_FILE, PROPERTIES_CURRENT_STOP_PORT, String.valueOf(port));
 
  504     synchronized void stop() {
 
  509         } 
catch (KeywordSearchModuleException e) {
 
  510             logger.log(Level.WARNING, 
"Failed to close core: ", e); 
 
  514             logger.log(Level.INFO, 
"Stopping Solr server from: {0}", solrFolder.getAbsolutePath()); 
 
  517             final String[] SOLR_STOP_CMD = {
 
  525             Process stop = Runtime.getRuntime().exec(SOLR_STOP_CMD, null, solrFolder);
 
  526             logger.log(Level.INFO, 
"Waiting for stopping Solr server"); 
 
  530             if (curSolrProcess != null) {
 
  531                 curSolrProcess.destroy();
 
  532                 curSolrProcess = null;
 
  535         } 
catch (InterruptedException | IOException ex) {
 
  539                 if (errorRedirectThread != null) {
 
  540                     errorRedirectThread.stopRun();
 
  541                     errorRedirectThread = null;
 
  548             logger.log(Level.INFO, 
"Finished stopping Solr server"); 
 
  559     synchronized boolean isRunning() throws KeywordSearchModuleException {
 
  562             if (isPortAvailable(currentSolrServerPort)) {
 
  566             if (curSolrProcess != null && !curSolrProcess.isAlive()) {
 
  573             CoreAdminRequest.getStatus(null, localSolrServer);
 
  575             logger.log(Level.INFO, 
"Solr server is running"); 
 
  576         } 
catch (SolrServerException ex) {
 
  578             Throwable cause = ex.getRootCause();
 
  583             if (cause instanceof ConnectException || cause instanceof SocketException) { 
 
  584                 logger.log(Level.INFO, 
"Solr server is not running, cause: {0}", cause.getMessage()); 
 
  587                 throw new KeywordSearchModuleException(
 
  588                         NbBundle.getMessage(
this.getClass(), 
"Server.isRunning.exception.errCheckSolrRunning.msg"), ex);
 
  590         } 
catch (SolrException ex) {
 
  592             logger.log(Level.INFO, 
"Solr server is not running", ex); 
 
  594         } 
catch (IOException ex) {
 
  595             throw new KeywordSearchModuleException(
 
  596                     NbBundle.getMessage(
this.getClass(), 
"Server.isRunning.exception.errCheckSolrRunning.msg2"), ex);
 
  614     void openCoreForCase(Case theCase) 
throws KeywordSearchModuleException {
 
  615         currentCoreLock.writeLock().lock();
 
  618             serverAction.putValue(CORE_EVT, CORE_EVT_STATES.STARTED);
 
  620             currentCoreLock.writeLock().unlock();
 
  629     boolean coreIsOpen() {
 
  630         currentCoreLock.readLock().lock();
 
  632             return (null != currentCore);
 
  634             currentCoreLock.readLock().unlock();
 
  638     void closeCore() throws KeywordSearchModuleException {
 
  639         currentCoreLock.writeLock().lock();
 
  641             if (null != currentCore) {
 
  644                 serverAction.putValue(CORE_EVT, CORE_EVT_STATES.STOPPED);
 
  647             currentCoreLock.writeLock().unlock();
 
  651     void addDocument(SolrInputDocument doc) 
throws KeywordSearchModuleException {
 
  652         currentCoreLock.readLock().lock();
 
  654             currentCore.addDocument(doc);
 
  656             currentCoreLock.readLock().unlock();
 
  667     String geCoreDataDirPath(Case theCase) {
 
  668         String indexDir = theCase.getModuleDirectory() + File.separator + 
"keywordsearch" + File.separator + 
"data"; 
 
  669         if (uncPathUtilities != null) {
 
  672             if (result == null) {
 
  676             if (result == null) {
 
  697     private Core 
openCore(
Case theCase) 
throws KeywordSearchModuleException {
 
  704                 currentSolrServer = 
new HttpSolrServer(
"http://" + host + 
":" + port + 
"/solr"); 
 
  706             connectToSolrServer(currentSolrServer);
 
  708         } 
catch (SolrServerException | IOException ex) {
 
  709             throw new KeywordSearchModuleException(NbBundle.getMessage(
Server.class, 
"Server.connect.exception.msg"), ex);
 
  712         String dataDir = geCoreDataDirPath(theCase);
 
  713         String coreName = theCase.getTextIndexName();
 
  714         return this.
openCore(coreName.isEmpty() ? DEFAULT_CORE_NAME : coreName, 
new File(dataDir), theCase.getCaseType());
 
  723         currentCoreLock.readLock().lock();
 
  725             if (null == currentCore) {
 
  726                 throw new NoOpenCoreException();
 
  728             currentCore.commit();
 
  730             currentCoreLock.readLock().unlock();
 
  734     NamedList<Object> request(SolrRequest request) 
throws SolrServerException, NoOpenCoreException {
 
  735         currentCoreLock.readLock().lock();
 
  737             if (null == currentCore) {
 
  738                 throw new NoOpenCoreException();
 
  740             return currentCore.request(request);
 
  742             currentCoreLock.readLock().unlock();
 
  757         currentCoreLock.readLock().lock();
 
  759             if (null == currentCore) {
 
  760                 throw new NoOpenCoreException();
 
  763                 return currentCore.queryNumIndexedFiles();
 
  764             } 
catch (SolrServerException ex) {
 
  765                 throw new KeywordSearchModuleException(NbBundle.getMessage(
this.getClass(), 
"Server.queryNumIdxFiles.exception.msg"), ex);
 
  768             currentCoreLock.readLock().unlock();
 
  782         currentCoreLock.readLock().lock();
 
  784             if (null == currentCore) {
 
  785                 throw new NoOpenCoreException();
 
  788                 return currentCore.queryNumIndexedChunks();
 
  789             } 
catch (SolrServerException ex) {
 
  790                 throw new KeywordSearchModuleException(NbBundle.getMessage(
this.getClass(), 
"Server.queryNumIdxChunks.exception.msg"), ex);
 
  793             currentCoreLock.readLock().unlock();
 
  807         currentCoreLock.readLock().lock();
 
  809             if (null == currentCore) {
 
  810                 throw new NoOpenCoreException();
 
  813                 return currentCore.queryNumIndexedDocuments();
 
  814             } 
catch (SolrServerException ex) {
 
  815                 throw new KeywordSearchModuleException(NbBundle.getMessage(
this.getClass(), 
"Server.queryNumIdxDocs.exception.msg"), ex);
 
  818             currentCoreLock.readLock().unlock();
 
  832     public boolean queryIsIndexed(
long contentID) 
throws KeywordSearchModuleException, NoOpenCoreException {
 
  833         currentCoreLock.readLock().lock();
 
  835             if (null == currentCore) {
 
  836                 throw new NoOpenCoreException();
 
  839                 return currentCore.queryIsIndexed(contentID);
 
  840             } 
catch (SolrServerException ex) {
 
  841                 throw new KeywordSearchModuleException(NbBundle.getMessage(
this.getClass(), 
"Server.queryIsIdxd.exception.msg"), ex);
 
  845             currentCoreLock.readLock().unlock();
 
  860     public int queryNumFileChunks(
long fileID) 
throws KeywordSearchModuleException, NoOpenCoreException {
 
  861         currentCoreLock.readLock().lock();
 
  863             if (null == currentCore) {
 
  864                 throw new NoOpenCoreException();
 
  867                 return currentCore.queryNumFileChunks(fileID);
 
  868             } 
catch (SolrServerException ex) {
 
  869                 throw new KeywordSearchModuleException(NbBundle.getMessage(
this.getClass(), 
"Server.queryNumFileChunks.exception.msg"), ex);
 
  872             currentCoreLock.readLock().unlock();
 
  886     public QueryResponse 
query(SolrQuery sq) 
throws KeywordSearchModuleException, NoOpenCoreException {
 
  887         currentCoreLock.readLock().lock();
 
  889             if (null == currentCore) {
 
  890                 throw new NoOpenCoreException();
 
  893                 return currentCore.query(sq);
 
  894             } 
catch (SolrServerException ex) {
 
  895                 throw new KeywordSearchModuleException(NbBundle.getMessage(
this.getClass(), 
"Server.query.exception.msg", sq.getQuery()), ex);
 
  898             currentCoreLock.readLock().unlock();
 
  913     public QueryResponse 
query(SolrQuery sq, SolrRequest.METHOD method) throws KeywordSearchModuleException, NoOpenCoreException {
 
  914         currentCoreLock.readLock().lock();
 
  916             if (null == currentCore) {
 
  917                 throw new NoOpenCoreException();
 
  920                 return currentCore.query(sq, method);
 
  921             } 
catch (SolrServerException ex) {
 
  922                 throw new KeywordSearchModuleException(NbBundle.getMessage(
this.getClass(), 
"Server.query2.exception.msg", sq.getQuery()), ex);
 
  925             currentCoreLock.readLock().unlock();
 
  939     public TermsResponse 
queryTerms(SolrQuery sq) 
throws KeywordSearchModuleException, NoOpenCoreException {
 
  940         currentCoreLock.readLock().lock();
 
  942             if (null == currentCore) {
 
  943                 throw new NoOpenCoreException();
 
  946                 return currentCore.queryTerms(sq);
 
  947             } 
catch (SolrServerException ex) {
 
  948                 throw new KeywordSearchModuleException(NbBundle.getMessage(
this.getClass(), 
"Server.queryTerms.exception.msg", sq.getQuery()), ex);
 
  951             currentCoreLock.readLock().unlock();
 
  965         currentCoreLock.readLock().lock();
 
  967             if (null == currentCore) {
 
  968                 throw new NoOpenCoreException();
 
  970             return currentCore.getSolrContent(content.getId(), 0);
 
  972             currentCoreLock.readLock().unlock();
 
  988     public String 
getSolrContent(
final Content content, 
int chunkID) 
throws NoOpenCoreException {
 
  989         currentCoreLock.readLock().lock();
 
  991             if (null == currentCore) {
 
  992                 throw new NoOpenCoreException();
 
  994             return currentCore.getSolrContent(content.getId(), chunkID);
 
  996             currentCoreLock.readLock().unlock();
 
 1010         currentCoreLock.readLock().lock();
 
 1012             if (null == currentCore) {
 
 1013                 throw new NoOpenCoreException();
 
 1015             return currentCore.getSolrContent(objectID, 0);
 
 1017             currentCoreLock.readLock().unlock();
 
 1031     public String 
getSolrContent(
final long objectID, 
final int chunkID) 
throws NoOpenCoreException {
 
 1032         currentCoreLock.readLock().lock();
 
 1034             if (null == currentCore) {
 
 1035                 throw new NoOpenCoreException();
 
 1037             return currentCore.getSolrContent(objectID, chunkID);
 
 1039             currentCoreLock.readLock().unlock();
 
 1049         return Ingester.getDefault();
 
 1078     private Core 
openCore(String coreName, File dataDir, 
CaseType caseType) 
throws KeywordSearchModuleException {
 
 1081             if (!dataDir.exists()) {
 
 1085             if (!this.isRunning()) {
 
 1086                 logger.log(Level.SEVERE, 
"Core create/open requested, but server not yet running"); 
 
 1087                 throw new KeywordSearchModuleException(NbBundle.getMessage(
this.getClass(), 
"Server.openCore.exception.msg"));
 
 1100                     Path corePropertiesFile = Paths.get(solrFolder.toString(), 
SOLR, coreName, 
CORE_PROPERTIES);
 
 1101                     if (corePropertiesFile.toFile().exists()) {
 
 1103                             corePropertiesFile.toFile().delete();
 
 1104                         } 
catch (Exception ex) {
 
 1105                             logger.log(Level.INFO, 
"Could not delete pre-existing core.properties prior to opening the core."); 
 
 1110                 CoreAdminRequest.Create createCoreRequest = 
new CoreAdminRequest.Create();
 
 1111                 createCoreRequest.setDataDir(dataDir.getAbsolutePath());
 
 1112                 createCoreRequest.setCoreName(coreName);
 
 1113                 createCoreRequest.setConfigSet(
"AutopsyConfig"); 
 
 1114                 createCoreRequest.setIsLoadOnStartup(
false);
 
 1115                 createCoreRequest.setIsTransient(
true);
 
 1116                 currentSolrServer.request(createCoreRequest);
 
 1120                 throw new KeywordSearchModuleException(NbBundle.getMessage(
this.getClass(), 
"Server.openCore.exception.noIndexDir.msg"));
 
 1123             return new Core(coreName, caseType);
 
 1125         } 
catch (SolrServerException | SolrException | IOException ex) {
 
 1126             throw new KeywordSearchModuleException(NbBundle.getMessage(
this.getClass(), 
"Server.openCore.exception.cantOpen.msg"), ex);
 
 1138     void connectToSolrServer(HttpSolrServer solrServer) 
throws SolrServerException, IOException {
 
 1139         CoreAdminRequest.getStatus(null, solrServer);
 
 1155     private boolean coreIsLoaded(String coreName) 
throws SolrServerException, IOException {
 
 1156         CoreAdminResponse response = CoreAdminRequest.getStatus(coreName, currentSolrServer);
 
 1157         return response.getCoreStatus(coreName).get(
"instanceDir") != null; 
 
 1171         CoreAdminResponse response = CoreAdminRequest.getStatus(coreName, currentSolrServer);
 
 1172         Object dataDirPath = response.getCoreStatus(coreName).get(
"dataDir"); 
 
 1173         if (null != dataDirPath) {
 
 1174             File indexDir = Paths.get((String) dataDirPath, 
"index").toFile();  
 
 1175             return indexDir.exists();
 
 1184         private final String name;
 
 1190         private final HttpSolrServer solrCore;
 
 1192         private Core(String name, 
CaseType caseType) {
 
 1194             this.caseType = caseType;
 
 1196             this.solrCore = 
new HttpSolrServer(currentSolrServer.getBaseURL() + 
"/" + name);
 
 1201             solrCore.setDefaultMaxConnectionsPerHost(2);
 
 1202             solrCore.setMaxTotalConnections(5);
 
 1203             solrCore.setFollowRedirects(
false);  
 
 1206             solrCore.setAllowCompression(
true);
 
 1207             solrCore.setMaxRetries(1); 
 
 1208             solrCore.setParser(
new XMLResponseParser()); 
 
 1221         private QueryResponse 
query(SolrQuery sq) 
throws SolrServerException {
 
 1222             return solrCore.query(sq);
 
 1225         private NamedList<Object> request(SolrRequest request) 
throws SolrServerException {
 
 1227                 return solrCore.request(request);
 
 1228             } 
catch (IOException e) {
 
 1229                 logger.log(Level.WARNING, 
"Could not issue Solr request. ", e); 
 
 1230                 throw new SolrServerException(
 
 1231                         NbBundle.getMessage(
this.getClass(), 
"Server.request.exception.exception.msg"), e);
 
 1236         private QueryResponse 
query(SolrQuery sq, SolrRequest.METHOD method) throws SolrServerException {
 
 1237             return solrCore.query(sq, method);
 
 1240         private TermsResponse 
queryTerms(SolrQuery sq) 
throws SolrServerException {
 
 1241             QueryResponse qres = solrCore.query(sq);
 
 1242             return qres.getTermsResponse();
 
 1245         private void commit() throws SolrServerException {
 
 1248                 solrCore.commit(
true, 
true);
 
 1249             } 
catch (IOException e) {
 
 1250                 logger.log(Level.WARNING, 
"Could not commit index. ", e); 
 
 1251                 throw new SolrServerException(NbBundle.getMessage(
this.getClass(), 
"Server.commit.exception.msg"), e);
 
 1255         void addDocument(SolrInputDocument doc) 
throws KeywordSearchModuleException {
 
 1258             } 
catch (SolrServerException ex) {
 
 1259                 logger.log(Level.SEVERE, 
"Could not add document to index via update handler: " + doc.getField(
"id"), ex); 
 
 1260                 throw new KeywordSearchModuleException(
 
 1261                         NbBundle.getMessage(
this.getClass(), 
"Server.addDoc.exception.msg", doc.getField(
"id")), ex); 
 
 1262             } 
catch (IOException ex) {
 
 1263                 logger.log(Level.SEVERE, 
"Could not add document to index via update handler: " + doc.getField(
"id"), ex); 
 
 1264                 throw new KeywordSearchModuleException(
 
 1265                         NbBundle.getMessage(
this.getClass(), 
"Server.addDoc.exception.msg2", doc.getField(
"id")), ex); 
 
 1278             final SolrQuery q = 
new SolrQuery();
 
 1280             String filterQuery = Schema.ID.toString() + 
":" + KeywordSearchUtil.escapeLuceneQuery(Long.toString(contentID));
 
 1282                 filterQuery = filterQuery + Server.CHUNK_ID_SEPARATOR + chunkID;
 
 1284             q.addFilterQuery(filterQuery);
 
 1285             q.setFields(Schema.TEXT.toString());
 
 1288                 SolrDocumentList solrDocuments = solrCore.query(q).getResults();
 
 1290                 if (!solrDocuments.isEmpty()) {
 
 1291                     SolrDocument solrDocument = solrDocuments.get(0);
 
 1292                     if (solrDocument != null) {
 
 1293                         Collection<Object> fieldValues = solrDocument.getFieldValues(Schema.TEXT.toString());
 
 1294                         if (fieldValues.size() == 1) 
 
 1296                             return fieldValues.toArray(
new String[0])[0];
 
 1300                             return fieldValues.toArray(
new String[0])[1];
 
 1304             } 
catch (SolrServerException ex) {
 
 1305                 logger.log(Level.WARNING, 
"Error getting content from Solr", ex); 
 
 1312         synchronized void close() throws KeywordSearchModuleException {
 
 1319                 CoreAdminRequest.unloadCore(this.name, currentSolrServer);
 
 1320             } 
catch (SolrServerException ex) {
 
 1321                 throw new KeywordSearchModuleException(
 
 1322                         NbBundle.getMessage(
this.getClass(), 
"Server.close.exception.msg"), ex);
 
 1323             } 
catch (IOException ex) {
 
 1324                 throw new KeywordSearchModuleException(
 
 1325                         NbBundle.getMessage(
this.getClass(), 
"Server.close.exception.msg2"), ex);
 
 1351             SolrQuery q = 
new SolrQuery(Server.Schema.ID + 
":*" + Server.CHUNK_ID_SEPARATOR + 
"*");
 
 1353             int numChunks = (int) 
query(q).getResults().getNumFound();
 
 1368             SolrQuery q = 
new SolrQuery(
"*:*");
 
 1370             return (
int) 
query(q).getResults().getNumFound();
 
 1382         private boolean queryIsIndexed(
long contentID) 
throws SolrServerException {
 
 1383             String 
id = KeywordSearchUtil.escapeLuceneQuery(Long.toString(contentID));
 
 1384             SolrQuery q = 
new SolrQuery(
"*:*");
 
 1385             q.addFilterQuery(Server.Schema.ID.toString() + 
":" + id);
 
 1388             return (
int) 
query(q).getResults().getNumFound() != 0;
 
 1403             String 
id = KeywordSearchUtil.escapeLuceneQuery(Long.toString(contentID));
 
 1405                     = 
new SolrQuery(Server.Schema.ID + 
":" + 
id + Server.CHUNK_ID_SEPARATOR + 
"*");
 
 1407             return (
int) 
query(q).getResults().getNumFound();
 
 1411     class ServerAction 
extends AbstractAction {
 
 1413         private static final long serialVersionUID = 1L;
 
 1416         public void actionPerformed(ActionEvent e) {
 
 1417             logger.log(Level.INFO, e.paramString().trim());
 
 1424     class SolrServerNoPortException 
extends SocketException {
 
 1426         private static final long serialVersionUID = 1L;
 
 1431         private final int port;
 
 1433         SolrServerNoPortException(
int port) {
 
 1434             super(NbBundle.getMessage(Server.class, 
"Server.solrServerNoPortException.msg", port,
 
 1435                     Server.PROPERTIES_CURRENT_SERVER_PORT));
 
 1439         int getPortNumber() {
 
int queryNumIndexedFiles()
String getSolrContent(final long objectID)
synchronized void rescanDrives()
final ReentrantReadWriteLock currentCoreLock
int queryNumIndexedChunks()
static final char ID_CHUNK_SEP
final ServerAction serverAction
synchronized String mappedDriveToUNC(String inputPath)
UNCPathUtilities uncPathUtilities
static String getIndexingServerPort()
static final String CORE_PROPERTIES
boolean coreIsLoaded(String coreName)
final HttpSolrServer localSolrServer
static final Logger logger
Core openCore(Case theCase)
void addServerActionListener(PropertyChangeListener l)
static final String HL_ANALYZE_CHARS_UNLIMITED
String getSolrContent(final Content content)
static final long MAX_CONTENT_SIZE
boolean coreIndexFolderExists(String coreName)
HttpSolrServer currentSolrServer
int queryNumIndexedDocuments()
static synchronized void setConfigSetting(String moduleName, String settingName, String settingVal)
static final String CHUNK_ID_SEPARATOR
static final String CORE_EVT
static final Charset DEFAULT_INDEXED_TEXT_CHARSET
default Charset to index text as 
InputStreamPrinterThread errorRedirectThread
static final String DEFAULT_CORE_NAME
QueryResponse query(SolrQuery sq)
static String getConfigSetting(String moduleName, String settingName)
int currentSolrServerPort
TermsResponse queryTerms(SolrQuery sq)
boolean queryIsIndexed(long contentID)
String getSolrContent(final Content content, int chunkID)
String getSolrContent(final long objectID, final int chunkID)
synchronized static Logger getLogger(String name)
Core openCore(String coreName, File dataDir, CaseType caseType)
static final int MAX_SOLR_MEM_MB
static Ingester getIngester()
static String getChunkIdString(long parentID, int childID)
static String getIndexingServerHost()
static boolean settingExists(String moduleName, String settingName)
int queryNumFileChunks(long fileID)
static final boolean DEBUG
QueryResponse query(SolrQuery sq, SolrRequest.METHOD method)