当前位置: 首页>>代码示例>>Java>>正文


Java CommonsHttpSolrServer类代码示例

本文整理汇总了Java中org.apache.solr.client.solrj.impl.CommonsHttpSolrServer的典型用法代码示例。如果您正苦于以下问题:Java CommonsHttpSolrServer类的具体用法?Java CommonsHttpSolrServer怎么用?Java CommonsHttpSolrServer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


CommonsHttpSolrServer类属于org.apache.solr.client.solrj.impl包,在下文中一共展示了CommonsHttpSolrServer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: SolrClient

import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; //导入依赖的package包/类
/**
    * @param solrUrl
    *                The solr URL of the server to connect
    */
   @Autowired
   public SolrClient(@Qualifier("fulltextSearchUrl")
   String solrUrl, @Qualifier("multiThreadedHttpConnectionManager")
   MultiThreadedHttpConnectionManager multiThreadedHttpConnectionManager) {
try {
    Assert.notNull(solrUrl, "solrClient does not accept null solrUrl");
    Assert
	    .notNull(multiThreadedHttpConnectionManager,
		    "solrClient does not accept null multiThreadedHttpConnectionManager");
    this.multiThreadedHttpConnectionManager = multiThreadedHttpConnectionManager;
    this.server = new CommonsHttpSolrServer(new URL(solrUrl),
	    new HttpClient(multiThreadedHttpConnectionManager));
    this.URL = !solrUrl.endsWith("/") ? solrUrl + "/" : solrUrl ;
    logger.info("connecting to solr on " + this.URL + "...");
} catch (MalformedURLException e) {
    throw new RuntimeException("Error connecting to Solr! : "
	    + e.getMessage());
}
   }
 
开发者ID:gisgraphy,项目名称:gisgraphy,代码行数:24,代码来源:SolrClient.java

示例2: purgeSolr

import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; //导入依赖的package包/类
/**
 * Manually purge the index to try again.
 * Since this cascade is currently ordered, can be used to purge before we load.
 * 
 * @param opts
 * @throws Exception
 */
@SuppressWarnings("deprecation")
@CLIMethod("--solr-purge")
public void purgeSolr(Opts opts) throws Exception  {

	// Check to see if the global url has been set.
	String url = sortOutSolrURL(globalSolrURL);				

	// Wipe out the solr index at url.
	SolrServer server = new CommonsHttpSolrServer(url);
	server.deleteByQuery("*:*");
	server.commit();

	// Probably worked, so let's destroy the log if there is one.
	if( globalSolrLogFile != null && globalSolrLogFile.exists() ){
	    boolean yes_p = globalSolrLogFile.delete();
	    if( yes_p ){
	        LOG.info("Deleted GOlr load log file.");
	    }else{
	        // Nothing there, doing nothing.
	    }
	}
	LOG.info("Purged: " + url);
}
 
开发者ID:owlcollab,项目名称:owltools,代码行数:31,代码来源:SolrCommandRunner.java

示例3: init

import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; //导入依赖的package包/类
public void init()
{
   	ParameterCheck.mandatory("solrHost", solrHost);
   	ParameterCheck.mandatory("solrPort", solrPort);
   	ParameterCheck.mandatory("solrUser", solrUser);
   	ParameterCheck.mandatory("solrPassword", solrPassword);
   	ParameterCheck.mandatory("solrPingCronExpression", solrPingCronExpression);
   	ParameterCheck.mandatory("solrConnectTimeout", solrConnectTimeout);

	try
	{
    	StringBuilder sb = new StringBuilder();
    	sb.append(httpClientFactory.isSSL() ? "https://" : "http://");
    	sb.append(solrHost);
    	sb.append(":");
    	sb.append(httpClientFactory.isSSL() ? solrSSLPort: solrPort);
    	sb.append(baseUrl);
		this.solrUrl = sb.toString();
		HttpClient httpClient = httpClientFactory.getHttpClient();

		server = new CommonsHttpSolrServer(solrUrl, httpClient);
		server.setParser(new XMLResponseParser());
		// TODO remove credentials because we're using SSL?
		Credentials defaultcreds = new UsernamePasswordCredentials(solrUser, solrPassword); 
		server.getHttpClient().getState().setCredentials(new AuthScope(solrHost, solrPort, AuthScope.ANY_REALM), 
				defaultcreds);
		server.setConnectionTimeout(solrConnectTimeout);
		server.setSoTimeout(20000);

		this.solrTracker = new SolrTracker(scheduler);
	}
	catch(MalformedURLException e)
	{
		throw new AlfrescoRuntimeException("Cannot initialise Solr admin http client", e);
	}
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:37,代码来源:SOLRAdminClient.java

示例4: executeAndSerialize

import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; //导入依赖的package包/类
public void executeAndSerialize(FulltextQuery query,
    OutputStream outputStream) throws FullTextSearchException {
statsUsageService.increaseUsage(StatsUsageType.FULLTEXT);
Assert.notNull(query, "Can not execute a null query");
Assert.notNull(outputStream,
	"Can not serialize into a null outputStream");
String queryString = ZipcodeNormalizer.normalize(query.getQuery(), query.getCountryCode());
query.withQuery(queryString);
try {
	if (!disableLogging){
		logger.info(query.toString());
	}

    ModifiableSolrParams params = FulltextQuerySolrHelper.parameterize(query);
    CommonsHttpSolrServer server = new CommonsHttpSolrServer(solrClient
	    .getURL(), this.httpClient,
	    new OutputstreamResponseWrapper(outputStream, params
		    .get(Constants.OUTPUT_FORMAT_PARAMETER)));
    server.query(params);
} catch (SolrServerException e) {
    logger.error("Can not execute query " + FulltextQuerySolrHelper.toQueryString(query)
	    + "for URL : " + solrClient.getURL() + " : "
	    + e.getCause().getMessage(),e);
    throw new FullTextSearchException(e.getCause().getMessage());
} catch (MalformedURLException e1) {
    logger.error("The URL " + solrClient.getURL() + " is incorrect",e1);
    throw new FullTextSearchException(e1);
} catch (RuntimeException e2) {
    String message = e2.getCause()!=null?e2.getCause().getMessage():e2.getMessage();
    logger
	    .error("An error has occurred during fulltext search of query "
		    + query + " : " + message,e2);
    throw new FullTextSearchException(message,e2);
}

   }
 
开发者ID:gisgraphy,项目名称:gisgraphy,代码行数:37,代码来源:FullTextSearchEngine.java

示例5: bindToUrl

import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; //导入依赖的package包/类
public void bindToUrl(String solrUrl) {
try {
    this.server = new CommonsHttpSolrServer(new URL(solrUrl));
    this.URL = !solrUrl.endsWith("/") ? solrUrl + "/" : solrUrl ;
    logger
	    .info("fulltextSearchUrl for FullTextSearchEngine is changed to "
		    + solrUrl);
} catch (Exception e) {
    throw new RuntimeException("Error connecting to Solr to "+solrUrl);
}
   }
 
开发者ID:gisgraphy,项目名称:gisgraphy,代码行数:12,代码来源:SolrClient.java

示例6: getSolrServer

import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; //导入依赖的package包/类
/**
 * Gets the instance of the Apache Solr server used for indexing.
 *
 * @return Instance of the Apache Solr server
 * @throws IllegalStateException If the search engine is not properly
 * configured
 */
private SolrServer getSolrServer() {
    try {
        String url = cfgService.getString(ConfigurationKey.SEARCH_ENGINE_URL);
        Integer socketTimeout = cfgService.getInteger(ConfigurationKey.SEARCH_ENGINE_SOCKET_TIMEOUT);
        Integer connectionTimeout = cfgService.getInteger(ConfigurationKey.SEARCH_ENGINE_CONNECTION_TIMEOUT);
        Integer maxTotalConnectionsPerHost = cfgService.getInteger(ConfigurationKey.SEARCH_ENGINE_MAX_TOTAL_CONNECTIONS_PER_HOST);
        Integer maxTotalConnections = cfgService.getInteger(ConfigurationKey.SEARCH_ENGINE_MAX_TOTAL_CONNECTIONS);
        Integer maxRetries = cfgService.getInteger(ConfigurationKey.SEARCH_ENGINE_MAX_RETRIES);
        Boolean followRedirects = cfgService.getBoolean(ConfigurationKey.SEARCH_ENGINE_FOLLOW_REDIRECTS);
        Boolean allowCompression = cfgService.getBoolean(ConfigurationKey.SEARCH_ENGINE_ALLOW_COMPRESSION);

        CommonsHttpSolrServer solrServer = new CommonsHttpSolrServer(url);
        solrServer.setRequestWriter(new BinaryRequestWriter());
        solrServer.setSoTimeout(socketTimeout);
        solrServer.setConnectionTimeout(connectionTimeout);
        solrServer.setDefaultMaxConnectionsPerHost(maxTotalConnectionsPerHost);
        solrServer.setMaxTotalConnections(maxTotalConnections);
        solrServer.setFollowRedirects(followRedirects);
        solrServer.setAllowCompression(allowCompression);
        solrServer.setMaxRetries(maxRetries);

        return solrServer;
    } catch (MalformedURLException ex) {
        LOG.log(Level.SEVERE, "Invalid search engine configuration. {0}", ex.getMessage());
        LOG.log(Level.FINEST, "", ex);
        throw new IllegalStateException("Invalid search engine configuration", ex);
    }
}
 
开发者ID:getconverge,项目名称:converge-1.x,代码行数:36,代码来源:SearchEngineBean.java

示例7: getPosts

import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; //导入依赖的package包/类
public List<ExtendedPost> getPosts(String queryText, String userId, int count) {
    List<ExtendedPost> list = new LinkedList<ExtendedPost>();
    CommonsHttpSolrServer server = getSolrServer();
    server.setParser(new XMLResponseParser());
    SolrQuery query = new SolrQuery();

    if (queryText.isEmpty()) {
        queryText = "*:*";
    } else {
        queryText = "(text:" + queryText + " || " + "from:" + queryText + " || " + "comments:" + queryText + ")";
    }

    queryText += " && owner_id:" + userId;
    System.out.println(queryText);
    query.setQuery(queryText);
    query.addSortField("updatedTime", SolrQuery.ORDER.desc);
    query.setRows(2000);

    try {
        QueryResponse rsp = server.query(query);
        SolrDocumentList docs = rsp.getResults();

        for (SolrDocument d : docs) {
            ExtendedPost p = convertToPost(d);
            if (p != null) {
                list.add(p);
            }
        }
    } catch (SolrServerException ex) {
        Logger.getLogger(DataSearcher.class.getName()).log(Level.SEVERE, null, ex);
    }


    return list;
}
 
开发者ID:milenchechev,项目名称:RecommendedStream,代码行数:36,代码来源:DataSearcher.java

示例8: check

import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; //导入依赖的package包/类
@Override
public void check(CommandLine commandLine) throws Exception {
	
	// get url
	String url = commandLine.getOptionValue(SolrParameter.URL.toString());
	
	// get query
	String query = commandLine.getOptionValue(SolrParameter.QUERY.toString());

	// get connect timeout
	int connectTimeout = (Integer) SolrParameter.CONNECT_TIMEOUT.getDefaultValue();
	String connectTimeoutString = commandLine.getOptionValue(SolrParameter.CONNECT_TIMEOUT.toString());
	if (StringUtils.isNotEmpty(connectTimeoutString)) {
		connectTimeout = Integer.parseInt(connectTimeoutString);
	}
	
	// get response timeout
	int responseTimeout = (Integer) SolrParameter.RESPONSE_TIMEOUT.getDefaultValue();
	String responseTimeoutString = commandLine.getOptionValue(SolrParameter.RESPONSE_TIMEOUT.toString());
	if (StringUtils.isNotEmpty(responseTimeoutString)) {
		responseTimeout = Integer.parseInt(connectTimeoutString);
	}
	
	// get pattern
	Pattern pattern = (Pattern) SolrParameter.PATTERN.getDefaultValue();
	String patternString = commandLine.getOptionValue(SolrParameter.PATTERN.toString());
	if (StringUtils.isNotEmpty(patternString)) {
		pattern = Pattern.compile(patternString);
	}
	
	// create solr server client
	CommonsHttpSolrServer solrServer = new CommonsHttpSolrServer(url);
	solrServer.setConnectionTimeout(connectTimeout);
	solrServer.setSoTimeout(responseTimeout);
	
	// create solr query
	SolrQuery solrQuery = new SolrQuery(query);
	
	// execute solr query
	QueryResponse queryResponse = solrServer.query(solrQuery);
	
	// get query result
	StringBuffer resultBuffer = new StringBuffer(); 
	for (SolrDocument document : queryResponse.getResults()) {
		resultBuffer.append(ClientUtils.toXML(ClientUtils.toSolrInputDocument(document)));
		resultBuffer.append("\n");
	}
	
	// get result as string
	String result = resultBuffer.toString();
	if (StringUtils.isNotEmpty(result)) {

		System.out.println(result);
		
		// check if query result matches the given pattern
		Matcher matcher = pattern.matcher(result);
		if (!matcher.find()) {
			throw new Exception("The pattern does not match the solr result text");
		}
	}
}
 
开发者ID:chrisipa,项目名称:health-checker,代码行数:62,代码来源:SolrHealthChecker.java

示例9: setSolrServer

import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; //导入依赖的package包/类
public void setSolrServer(CommonsHttpSolrServer solrServer) {
	this.solrServer = solrServer;
}
 
开发者ID:ait-ngcms,项目名称:ffma,代码行数:4,代码来源:FFSynchronizerImpl.java

示例10: setSolrServer

import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; //导入依赖的package包/类
@Autowired
@Qualifier("solrUpdateServer")
public abstract void setSolrServer(CommonsHttpSolrServer solrServer);
 
开发者ID:ait-ngcms,项目名称:ffma,代码行数:4,代码来源:FFSynchronizer.java

示例11: getCommonsHttpSolrServer

import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; //导入依赖的package包/类
public static CommonsHttpSolrServer getCommonsHttpSolrServer(JobConf job) throws MalformedURLException {
  HttpClient client=new HttpClient();

  // Check for username/password
  if (job.getBoolean(SolrConstants.USE_AUTH, false)) {
    String username = job.get(SolrConstants.USERNAME);

    LOG.info("Authenticating as: " + username);

    AuthScope scope = new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT, AuthScope.ANY_REALM, AuthScope.ANY_SCHEME);

    client.getState().setCredentials(scope, new UsernamePasswordCredentials(username, job.get(SolrConstants.PASSWORD)));

    HttpClientParams params = client.getParams();
    params.setAuthenticationPreemptive(true);

    client.setParams(params);
  }

  return new CommonsHttpSolrServer(job.get(SolrConstants.SERVER_URL), client);
}
 
开发者ID:yahoo,项目名称:anthelion,代码行数:22,代码来源:SolrUtils.java

示例12: createDefaultServer

import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; //导入依赖的package包/类
public static final SolrServer createDefaultServer(String url) throws MalformedURLException {
	LOG.info("Server at: " + url);
	return new CommonsHttpSolrServer(url);
}
 
开发者ID:owlcollab,项目名称:owltools,代码行数:5,代码来源:AbstractSolrLoader.java

示例13: getSolrServer

import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; //导入依赖的package包/类
/**
 * Gets the instance of the Apache Solr server used for indexing.
 *
 * @return Instance of the Apache Solr server
 * @throws IllegalStateException If the search engine is not properly
 * configured
 */
private SolrServer getSolrServer() {
    try {
        String url = cfgService.getString(
                ConfigurationKey.SEARCH_ENGINE_NEWSWIRE_URL);
        Integer socketTimeout = cfgService.getInteger(
                ConfigurationKey.SEARCH_ENGINE_SOCKET_TIMEOUT);
        Integer connectionTimeout = cfgService.getInteger(
                ConfigurationKey.SEARCH_ENGINE_CONNECTION_TIMEOUT);
        Integer maxTotalConnectionsPerHost =
                cfgService.getInteger(
                ConfigurationKey.SEARCH_ENGINE_MAX_TOTAL_CONNECTIONS_PER_HOST);
        Integer maxTotalConnections =
                cfgService.getInteger(
                ConfigurationKey.SEARCH_ENGINE_MAX_TOTAL_CONNECTIONS);
        Integer maxRetries = cfgService.getInteger(
                ConfigurationKey.SEARCH_ENGINE_MAX_RETRIES);
        Boolean followRedirects = cfgService.getBoolean(
                ConfigurationKey.SEARCH_ENGINE_FOLLOW_REDIRECTS);
        Boolean allowCompression = cfgService.getBoolean(
                ConfigurationKey.SEARCH_ENGINE_ALLOW_COMPRESSION);

        CommonsHttpSolrServer solrServer = new CommonsHttpSolrServer(url);
        solrServer.setRequestWriter(new BinaryRequestWriter());
        solrServer.setSoTimeout(socketTimeout);
        solrServer.setConnectionTimeout(connectionTimeout);
        solrServer.setDefaultMaxConnectionsPerHost(
                maxTotalConnectionsPerHost);
        solrServer.setMaxTotalConnections(maxTotalConnections);
        solrServer.setFollowRedirects(followRedirects);
        solrServer.setAllowCompression(allowCompression);
        solrServer.setMaxRetries(maxRetries);

        return solrServer;
    } catch (MalformedURLException ex) {
        LOG.log(Level.SEVERE, "Invalid search engine configuration. {0}",
                ex.getMessage());
        LOG.log(Level.FINE, "", ex);
        throw new java.lang.IllegalStateException(
                "Invalid search engine configuration", ex);
    }
}
 
开发者ID:getconverge,项目名称:converge-1.x,代码行数:49,代码来源:NewswireServiceBean.java

示例14: getRemoteServer

import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; //导入依赖的package包/类
public static SolrServer getRemoteServer() throws MalformedURLException
{
    CommonsHttpSolrServer solr = new CommonsHttpSolrServer("http://localhost:8080/solr/test");
    solr.setRequestWriter(new BinaryRequestWriter());
    return solr;
}
 
开发者ID:Alfresco,项目名称:community-edition-old,代码行数:7,代码来源:SolrDocumentLoader.java

示例15: getRemoteServer

import org.apache.solr.client.solrj.impl.CommonsHttpSolrServer; //导入依赖的package包/类
public SolrServer getRemoteServer() throws MalformedURLException
{
    CommonsHttpSolrServer solr = new CommonsHttpSolrServer("http://localhost:8080/solr/test");
    solr.setRequestWriter(new BinaryRequestWriter());
    return solr;
}
 
开发者ID:Alfresco,项目名称:community-edition-old,代码行数:7,代码来源:SolrDocumentLoaderTest.java


注:本文中的org.apache.solr.client.solrj.impl.CommonsHttpSolrServer类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。