⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 indexmanager.java

📁 Abstract The Lucene Server project is an attempt to extend the Jakarta Lucene tool with server ca
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		if (tasktype.compareTo("Build")==0)
		{
			String when = E.getAttribute("when");
			String at = E.getAttribute("at");
			int hh,mm,ss;
			try 
			{
				StringTokenizer tok = new StringTokenizer(at,":");
				hh = Integer.parseInt(tok.nextToken());
				mm = Integer.parseInt(tok.nextToken());
				ss = Integer.parseInt(tok.nextToken());
			} 
			catch (NumberFormatException e) 
			{
				logServer("Invalid time "+at+" for task Build (index "+IndexName+") : task ignored");
				logServer("'at' attribute must be of the form HH:MM:SS");
				return;
			}
			Date now = new Date();
			cal.setTime(now);
			cal.set(Calendar.HOUR_OF_DAY,hh);
			cal.set(Calendar.MINUTE,mm);
			cal.set(Calendar.SECOND,ss);
			if (when.compareTo("EVERYDAY")==0)
			{
				
				if (cal.getTime().before(now))
				{
					// add 24 hours
					cal.setTimeInMillis(cal.getTimeInMillis()+24*3600*1000);
				}

				BuildIndexTimerTask task = new BuildIndexTimerTask(server,IndexName);
				logServer("Index "+IndexName+" will be built "+cal.getTime().toString()+" and everyday.");

				server.addTask(task,cal.getTime(),24*3600*1000);
				
			}
			else
			{
				if (when.compareTo("MONDAY")==0)
				{
					cal.set(Calendar.DAY_OF_WEEK,Calendar.MONDAY);
				}
				if (when.compareTo("TUESDAY")==0)
				{
					cal.set(Calendar.DAY_OF_WEEK,Calendar.TUESDAY);
				}
				if (when.compareTo("WEDNESDAY")==0)
				{
					cal.set(Calendar.DAY_OF_WEEK,Calendar.WEDNESDAY);
				}
				if (when.compareTo("FRIDAY")==0)
				{
					cal.set(Calendar.DAY_OF_WEEK,Calendar.FRIDAY);
				}
				if (when.compareTo("THURSDAY")==0)
				{
					cal.set(Calendar.DAY_OF_WEEK,Calendar.THURSDAY);
				}
				if (when.compareTo("SATURDAY")==0)
				{
					cal.set(Calendar.DAY_OF_WEEK,Calendar.SATURDAY);
				}
				if (when.compareTo("SUNDAY")==0)
				{
					cal.set(Calendar.DAY_OF_WEEK,Calendar.SUNDAY);
				}
				
				if (cal.getTime().before(now))
				{
					// add 7 days
					cal.setTimeInMillis(cal.getTimeInMillis()+24*3600*1000*7);
				}

				BuildIndexTimerTask task = new BuildIndexTimerTask(server,IndexName);
				logServer("Index "+IndexName+" will be built "+cal.getTime().toString()+" and every week.");

				server.addTask(task,cal.getTime(),24*3600*1000*7);
			}

		}
			

	}
	
	/**
	 * Returns the index name represented by the IndexName tag in
	 * the configuration file. 
	 * @return
	 */
	public String getIndexName()
	{
		return IndexName;
	}

	/**
	 * 
	 * @param s
	 */
	private void log(String s)
	{
		java.util.Date d = new java.util.Date();
		logger.log(d.toString()+" : "+this.getClass().getName() +" : "+ s);		
	}
	
	private void log(Exception e)
	{
		logger.log(e);
	}
	
	private void logServer(String s)
	{
		server.log(s);
	}

	private void logServer(Exception e)
	{
		server.log(e);
	}

	/**
	 * 
	 * @author rcocula
	 *
	 * TODO To change the template for this generated type comment go to
	 * Window - Preferences - Java - Code Generation - Code and Comments
	 */
	
	public void BuildIndexFromScratch() throws BuildIndexException
	{
		int nbDocsAdded = 0;
		try
		{
			log ("Building index "+IndexName);
			IndexWriter indexwriter = new IndexWriter(IndexDirectory,AnalyzerClass,true);
			
			
			logger.logHigh(" ******** list of all files. *******");
			Document[] docs = null;
			Source MatchedSource = null;


			for (Enumeration e=SourceVector.elements();e.hasMoreElements();)
			{
				Source S = (Source)e.nextElement();
				for (Iterator I = S.getXFileIterator();I.hasNext();)
				{
					MatchedSource = null;
					XFile next = (XFile)I.next();
					for (Enumeration e1=SourceVector.elements();e1.hasMoreElements();)
					{
						Source S1 = (Source)e1.nextElement();
						if (S1.Match(next))
						{
							MatchedSource = S1;
							break;
						}
					}
					
					if (MatchedSource == null)
					{
						logger.logHigh (next.toString()+" does not match any source.");
						docs=null;
					}
					
					if (MatchedSource == S)
					{
						logger.logHigh(next.toString()+" - Matches "+MatchedSource.getLocation().toString());
						try
						{
							docs = MatchedSource.toDocuments(next);
						}
						catch (Exception E) 
						{
							logger.logHigh (next.toString()+ ": could not be parsed");
						}
					}
					
				
					if (MatchedSource != null && (SourceVector.indexOf(MatchedSource) < SourceVector.indexOf(S)))
					{
						logger.logHigh (next.toString()+" file treated before.");						
					}

					try
					{
						for (int i=0;;i++)
						{
							indexwriter.addDocument(docs[i]);
							nbDocsAdded++;
						}
					}
					catch (ArrayIndexOutOfBoundsException E1)
					{
					}
					catch (NullPointerException E2) 
					{
					}

					
				}
			}
			
				
			indexwriter.close();
			
		}
		catch (Exception E)
		{
			throw new BuildIndexException("Index Building error for Index "+IndexName,E);
		}
		
		log ("index "+IndexName+" successfully built. "+nbDocsAdded+" documents added.");
	}
	

	/**
	 * @deprecated
	 * @return
	 * @throws XFileException
	 */
	private HashSet getAllFiles() throws XFileException
	{
		HashSet allFiles = new HashSet();
		
		// constitutes set of all files from all Sources
		for (Enumeration es = SourceVector.elements();es.hasMoreElements();)
		{
			Source s = (Source)es.nextElement();
			XFile[] listfiles = s.ListFiles();
			try
			{
				for (int i=0;;i++)
				{
					allFiles.add((XFile)Array.get(listfiles,i));	
				}
			}
			catch (ArrayIndexOutOfBoundsException e)
			{
			}
			
		}
		
		return allFiles;
		
	}	
	
	
	/**
	 * 
	 * @author rcocula
	 *
	 * TODO To change the template for this generated type comment go to
	 * Window - Preferences - Java - Code Generation - Code and Comments
	 */
	
	public RemoteSearchable getRemoteSearchable() throws IOException
	{
		return new RemoteSearchable(new IndexSearcher(IndexDirectory));
	}
	
	/**
	 * 
	 * @author rcocula
	 *
	 * TODO To change the template for this generated type comment go to
	 * Window - Preferences - Java - Code Generation - Code and Comments
	 */

	public Class  getAnalyzerClass ()
	{
		return AnalyzerClass.getClass();
	}
}


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -