當前位置: 首頁>>代碼示例>>Java>>正文


Java SolrClient類代碼示例

本文整理匯總了Java中org.apache.solr.client.solrj.SolrClient的典型用法代碼示例。如果您正苦於以下問題:Java SolrClient類的具體用法?Java SolrClient怎麽用?Java SolrClient使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SolrClient類屬於org.apache.solr.client.solrj包,在下文中一共展示了SolrClient類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testRuntimeLib

import org.apache.solr.client.solrj.SolrClient; //導入依賴的package包/類
@Test
public void testRuntimeLib() throws SolrServerException, IOException {
    SearchServer server = testSearchServer.getSearchServer();

    SolrClient client = (SolrClient) server.getBackend();

    SolrInputDocument document = new SolrInputDocument();
    document.setField("_id_", "1");
    document.setField("_type_", "doc");
    document.setField("dynamic_multi_facet_string_f1", "test");
    document.setField("dynamic_multi_facet_string_f2", "hello");

    client.add(document);
    client.commit();

    SolrQuery query = new SolrQuery("t");
    query.setRequestHandler("/suggester");
    query.set("suggestion.df", "facets");
    query.set("suggestion.field", "dynamic_multi_facet_string_f1");

    QueryResponse response = client.query(query);

    assertEquals(1, ((HashMap) response.getResponse().get("suggestions")).get("suggestion_count"));
}
 
開發者ID:RBMHTechnology,項目名稱:vind,代碼行數:25,代碼來源:TestServerTest.java

示例2: SolrSearchServer

import org.apache.solr.client.solrj.SolrClient; //導入依賴的package包/類
/**
 * Creates an instance of SolrSearch server allowing to avoid the schema validity check.
 * @param client SolrClient to connect to.
 * @param check true to perform local schema validity check against remote schema, false otherwise.
 */
protected SolrSearchServer(SolrClient client, boolean check) {
    solrClient = client;

    //In order to perform unit tests with mocked solrClient, we do not need to do the schema check.
    if(check && client != null) {
        try {
            final SolrPingResponse ping = solrClient.ping();
            if (ping.getStatus() == 0) {
                log.debug("Pinged Solr in {}", ping.getQTime());
            }
        } catch (SolrServerException | IOException e) {
            log.error("Cannot connect to solr server", e);
            throw new RuntimeException();
        }
        log.info("Connection to solr server successful");

        checkVersionAndSchema();
    } else {
        log.warn("Solr ping and schema validity check has been deactivated.");
    }
}
 
開發者ID:RBMHTechnology,項目名稱:vind,代碼行數:27,代碼來源:SolrSearchServer.java

示例3: main

import org.apache.solr.client.solrj.SolrClient; //導入依賴的package包/類
/**
 * Main entry point. 
 * 
 * @param args the command line arguments.
 * @throws IOException in case of I/O failure.
 */
public static void main(String[] args) throws IOException, SolrServerException {
	
	// This is the list of documents we will send to Solr
	List<SolrInputDocument> books = new ArrayList<SolrInputDocument>();
	
	// Populate the list
	books.add(newBook("1", "Apache Solr Essentials", "Andrea Gazzarini"));
	books.add(newBook("2", "Apache Solr FullText Search Server", "John White"));
	books.add(newBook("3", "Enterprise Search with Apache Solr", "Martin Green"));	
	
	// Creates the Solr remote proxy
	try (SolrClient client = new HttpSolrClient.Builder("http://127.0.0.1:8983/solr/ex1").build()) {
		
		// Indexes data
		client.add(books);
		
		// Commits
		client.commit();
	} 
}
 
開發者ID:agazzarini,項目名稱:as-full-text-search-server,代碼行數:27,代碼來源:SampleIndexer.java

示例4: createNewSolrClient

import org.apache.solr.client.solrj.SolrClient; //導入依賴的package包/類
public SolrClient createNewSolrClient(final String index) {
	if (jetty != null) {
		try {
			// setup the client...
			String url = jetty.getBaseUrl().toString() + "/" + index;
			HttpSolrClient client = getHttpSolrClient(url);
			client.setConnectionTimeout(DEFAULT_CONNECTION_TIMEOUT);
			client.setDefaultMaxConnectionsPerHost(100);
			client.setMaxTotalConnections(100);
			return client;
		} catch (Exception ex) {
			throw new RuntimeException(ex);
		}
	} else {
		return new EmbeddedSolrServer(h.getCoreContainer(), index);
	}
}
 
開發者ID:agazzarini,項目名稱:as-full-text-search-server,代碼行數:18,代碼來源:BaseIntegrationTest.java

示例5: indexConversation

import org.apache.solr.client.solrj.SolrClient; //導入依賴的package包/類
public void indexConversation(Conversation conversation, boolean commit) {
    try (SolrClient solr = solrServer.getSolrClient(conversationCore)){
        SolrInputDocument doc = toSolrInputDocument(conversation);
        if(doc != null){
            solr.add(doc, commitWithin);
        } else { //remove from index
            solr.deleteByQuery(getDeleteQuery(conversation),commitWithin);
        }
        if(commit){
            solr.commit();
        }
    } catch (IOException | SolrServerException e) {
        log.warn("Unable to index Conversation {} ({}: {})",conversation.getId(), e.getClass().getSimpleName(), e.getMessage());
        log.debug("STACKTRACE",e);
    }        
}
 
開發者ID:redlink-gmbh,項目名稱:smarti,代碼行數:17,代碼來源:ConversationIndexer.java

示例6: solrQuery

import org.apache.solr.client.solrj.SolrClient; //導入依賴的package包/類
protected MCROAISolrResult solrQuery(Optional<String> cursor) throws SolrServerException, IOException {
    SolrQuery query = getBaseQuery(CommonParams.Q);

    // set support
    if (this.set != null) {
        String setId = this.set.getSetId();
        MCROAISetConfiguration<SolrQuery, SolrDocument, String> setConfig = getSetManager().getConfig(setId);
        setConfig.getHandler().apply(this.set, query);
    }
    // from & until
    if (this.from != null || this.until != null) {
        String fromUntilCondition = buildFromUntilCondition(this.from, this.until);
        query.add(CommonParams.FQ, fromUntilCondition);
    }

    // cursor
    query.set(CursorMarkParams.CURSOR_MARK_PARAM, cursor.orElse(CursorMarkParams.CURSOR_MARK_START));
    query.set(CommonParams.ROWS, String.valueOf(getPartitionSize()));
    query.set(CommonParams.SORT, "id asc");

    // do the query
    SolrClient solrClient = MCRSolrClientFactory.getSolrClient();
    QueryResponse response = solrClient.query(query);
    Collection<MCROAISetResolver<String, SolrDocument>> setResolver = getSetResolver(response.getResults());
    return new MCROAISolrResult(response, d -> toHeader(d, setResolver));
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:27,代碼來源:MCROAISolrSearcher.java

示例7: filter

import org.apache.solr.client.solrj.SolrClient; //導入依賴的package包/類
@Override
public boolean filter(MCRSet set) {
    if (!filterEmptySets()) {
        return false;
    }
    SolrClient solrClient = MCRSolrClientFactory.getSolrClient();
    ModifiableSolrParams p = new ModifiableSolrParams();
    String value = set.getSpec();
    p.set(CommonParams.Q, MCROAIUtils.getDefaultSetQuery(value, getConfigPrefix()));
    String restriction = MCROAIUtils.getDefaultRestriction(getConfigPrefix());
    if (restriction != null) {
        p.set(CommonParams.FQ, restriction);
    }
    p.set(CommonParams.ROWS, 1);
    p.set(CommonParams.FL, "id");
    try {
        QueryResponse response = solrClient.query(p);
        return response.getResults().isEmpty();
    } catch (Exception exc) {
        LOGGER.error("Unable to get results of solr server", exc);
        return true;
    }
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:24,代碼來源:MCROAIClassificationToSetHandler.java

示例8: init

import org.apache.solr.client.solrj.SolrClient; //導入依賴的package包/類
@Override
public void init(String configPrefix, String setId, Map<String, MCRSet> setMap, Collection<SolrDocument> result,
    Function<SolrDocument, String> identifier) {
    super.init(configPrefix, setId, setMap, result, identifier);
    if (result.isEmpty()) {
        idsInSet = Collections.emptySet();
        return;
    }
    SolrClient solrClient = MCRSolrClientFactory.getSolrClient();
    QueryResponse response;
    try {
        response = solrClient.query(getQuery());
    } catch (SolrServerException | IOException e) {
        throw new MCRException("Error while getting set membership.", e);
    }
    idsInSet = response.getResults().stream().map(getIdentifier()).collect(Collectors.toSet());
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:18,代碼來源:MCROAIQuerySetResolver.java

示例9: filterNonEmpty

import org.apache.solr.client.solrj.SolrClient; //導入依賴的package包/類
private void filterNonEmpty(String classId, Element e) {
    SolrClient solrClient = MCRSolrClientFactory.getSolrClient();
    for (int i = 0; i < e.getChildren("category").size(); i++) {
        Element cat = e.getChildren("category").get(i);

        SolrQuery solrQquery = new SolrQuery();
        solrQquery.setQuery(
            "category:\"" + MCRSolrUtils.escapeSearchValue(classId + ":" + cat.getAttributeValue("ID")) + "\"");
        solrQquery.setRows(0);
        try {
            QueryResponse response = solrClient.query(solrQquery);
            SolrDocumentList solrResults = response.getResults();
            if (solrResults.getNumFound() == 0) {
                e.removeContent(cat);
                i--;
            }
        } catch (SolrServerException | IOException exc) {
            LOGGER.error(exc);
        }
    }
    for (int i = 0; i < e.getChildren("category").size(); i++) {
        filterNonEmpty(classId, e.getChildren("category").get(i));
    }
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:25,代碼來源:MCRRestAPIClassifications.java

示例10: filter

import org.apache.solr.client.solrj.SolrClient; //導入依賴的package包/類
@GET
@Path("filter/{text}")
@Produces(MediaType.APPLICATION_JSON)
public Response filter(@PathParam("text") String text) {
    SolrClient solrClient = MCRSolrClassificationUtil.getCore().getClient();
    ModifiableSolrParams p = new ModifiableSolrParams();
    p.set("q", "*" + text + "*");
    p.set("fl", "id,ancestors");

    JsonArray docList = new JsonArray();
    MCRSolrSearchUtils.stream(solrClient, p).flatMap(document -> {
        List<String> ids = new ArrayList<>();
        ids.add(document.getFirstValue("id").toString());
        Collection<Object> fieldValues = document.getFieldValues("ancestors");
        if (fieldValues != null) {
            for (Object anc : fieldValues) {
                ids.add(anc.toString());
            }
        }
        return ids.stream();
    }).distinct().map(JsonPrimitive::new).forEach(docList::add);
    return Response.ok().entity(docList.toString()).build();
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:24,代碼來源:MCRClassificationEditorResource.java

示例11: rebuildContentIndex

import org.apache.solr.client.solrj.SolrClient; //導入依賴的package包/類
/**
 * Rebuilds solr's content index.
 *
 * @param solrClient
 *            solr client connection
 * @param list
 *            list of mycore object id's
 * @param priority
 *            higher priority means earlier execution
 */
public static void rebuildContentIndex(SolrClient solrClient, List<String> list, int priority) {
    LOGGER.info("Re-building Content Index");

    if (list.isEmpty()) {
        LOGGER.info("No objects to index");
        return;
    }
    long tStart = System.currentTimeMillis();
    int totalCount = list.size();
    LOGGER.info("Sending content of {} derivates to solr for reindexing", totalCount);

    for (String id : list) {
        MCRSolrFilesIndexHandler indexHandler = new MCRSolrFilesIndexHandler(id, solrClient);
        indexHandler.setCommitWithin(BATCH_AUTO_COMMIT_WITHIN_MS);
        submitIndexHandler(indexHandler, priority);
    }
    long tStop = System.currentTimeMillis();
    MCRSolrIndexStatisticCollector.FILE_TRANSFER.addTime(tStop - tStart);
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:30,代碼來源:MCRSolrIndexer.java

示例12: executeStreamingExpression

import org.apache.solr.client.solrj.SolrClient; //導入依賴的package包/類
public static RStreamingExpressionIterator executeStreamingExpression(SolrClient sc, String collection,
    String expression, String[] columnNames) throws IOException, SolrServerException {
    if (!checkResponseWriter(sc)) {
        log.error("The SolrClient's Response Writer should be: " + InputStreamResponseParser.class.getName());
    }
    SolrParams sp = new MapSolrParams(Collections.singletonMap("expr", expression));
    SolrRequest<?> sr = new GenericSolrRequest(METHOD.POST, "/stream", sp);
    NamedList<Object> nl = sc.request(sr, collection);
    InputStream stream = (InputStream) nl.get("stream");
    InputStreamReader reader = new InputStreamReader(stream, "UTF-8");
    if (columnNames == null || columnNames.length == 0) {
        return new RStreamingExpressionIterator(reader);
    }
    return new RStreamingExpressionIterator(reader, columnNames);
}
 
開發者ID:jdyer1,項目名稱:R-solr-stream,代碼行數:16,代碼來源:RStreamingExpressions.java

示例13: checkResponseWriter

import org.apache.solr.client.solrj.SolrClient; //導入依賴的package包/類
private static boolean checkResponseWriter(SolrClient sc) {
    if (sc instanceof HttpSolrClient && !(((HttpSolrClient) sc).getParser() instanceof InputStreamResponseParser)) {
        return false;
    } else if (sc instanceof LBHttpSolrClient
        && !(((LBHttpSolrClient) sc).getParser() instanceof InputStreamResponseParser)) {
        return false;
    } else if (sc instanceof CloudSolrClient
        && !(((CloudSolrClient) sc).getParser() instanceof InputStreamResponseParser)) {
        return false;
    }
    return true;
}
 
開發者ID:jdyer1,項目名稱:R-solr-stream,代碼行數:13,代碼來源:RStreamingExpressions.java

示例14: fromZookeeperHosts

import org.apache.solr.client.solrj.SolrClient; //導入依賴的package包/類
public static SolrClient fromZookeeperHosts(String zkHostsCommaSeparated, String zkChroot) {
    CloudSolrClient.Builder b =
        new CloudSolrClient.Builder().withZkHost(Arrays.asList(zkHostsCommaSeparated.split(",")));
    if (zkChroot != null && zkChroot.length() > 0) {
        b.withZkChroot(zkChroot);
    }
    CloudSolrClient csc = b.build();
    csc.setParser(new InputStreamResponseParser("json"));
    return csc;
}
 
開發者ID:jdyer1,項目名稱:R-solr-stream,代碼行數:11,代碼來源:SolrClientFactory.java

示例15: fromSolrHosts

import org.apache.solr.client.solrj.SolrClient; //導入依賴的package包/類
public static SolrClient fromSolrHosts(String solrHostsCommaSeparated) {
    String[] hostArr = solrHostsCommaSeparated.split(",");
    if (hostArr.length == 1) {
        return new HttpSolrClient.Builder(hostArr[0]).withResponseParser(new InputStreamResponseParser("json"))
            .build();
    }
    return new LBHttpSolrClient.Builder().withBaseSolrUrls(hostArr)
        .withResponseParser(new InputStreamResponseParser("json")).build();
}
 
開發者ID:jdyer1,項目名稱:R-solr-stream,代碼行數:10,代碼來源:SolrClientFactory.java


注:本文中的org.apache.solr.client.solrj.SolrClient類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。