本文整理匯總了Java中org.apache.solr.client.solrj.SolrQuery.setQuery方法的典型用法代碼示例。如果您正苦於以下問題:Java SolrQuery.setQuery方法的具體用法?Java SolrQuery.setQuery怎麽用?Java SolrQuery.setQuery使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.solr.client.solrj.SolrQuery
的用法示例。
在下文中一共展示了SolrQuery.setQuery方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public static void main(String[] args) throws MalformedURLException, SolrServerException {
String zkHost = "localhost:2181";
String defaultCollection = "collection1";
CloudSolrServer solr = new CloudSolrServer(zkHost);
solr.setDefaultCollection(defaultCollection);
/* ModifiableSolrParams params = new ModifiableSolrParams();
params.set("q", "cat:electronics");
params.set("defType", "edismax");
params.set("start", "0");*/
SolrQuery params = new SolrQuery();
params.setQuery("*:*");
params.setSort("score ",ORDER.desc);
params.setStart(Integer.getInteger("0"));
params.setRows(Integer.getInteger("100"));
QueryResponse response = solr.query(params);
SolrDocumentList results = response.getResults();
for (int i = 0; i < results.size(); ++i) {
System.out.println(results.get(i));
}
}
示例2: main
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public static void main(String[] args) throws MalformedURLException, SolrServerException {
HttpSolrServer solr = new HttpSolrServer("http://localhost:8983/solr");
// ModifiableSolrParams params = new ModifiableSolrParams();
// params.setQuery("name:Samsung ");
// params.setStart(0);
// params.setRows(100);
SolrQuery params = new SolrQuery();
params.setQuery("*:*");
params.setSort("score ",ORDER.desc);
params.setStart(Integer.getInteger("0"));
params.setRows(Integer.getInteger("100"));
QueryResponse response = solr.query(params);
SolrDocumentList results = response.getResults();
for (int i = 0; i < results.size(); ++i) {
System.out.println(results.get(i));
}
}
示例3: getSets
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
* Creates a list with all available values for the given field (minus any blacklisted values).
*
* @return
* @throws SolrServerException
* @should return all values
*/
public List<String> getSets(String field) throws SolrServerException {
List<String> ret = new ArrayList<>();
SolrQuery query = new SolrQuery();
query.setQuery(field + ":* " + DataManager.getInstance().getConfiguration().getCollectionBlacklistFilterSuffix());
query.setStart(0);
query.setRows(0);
query.addFacetField(field);
logger.trace("Set query: {}", query.getQuery());
QueryResponse resp = server.query(query);
FacetField facetField = resp.getFacetField(field);
if (facetField != null) {
for (Count count : facetField.getValues()) {
if (count.getCount() == 0) {
continue;
}
ret.add(count.getName());
}
}
Collections.sort(ret);
logger.trace("{} terms found for {}", ret.size(), field);
return ret;
}
示例4: search
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
* Search.
* <p>
* Set `start` and `rows` values in the SolrQuery parameter to paginate the results.<br>
* <strong>If no `rows` have been set, solr will only return 10 documents, no more.</strong>
* <p>
* To get the total number of document matching the given query, use {@code res.getNumFound()}.
*
* @param query a SolrQuery with at least a 'q' parameter set.
* @return A list of solr document matching the given query.
*/
@PreAuthorize("hasRole('ROLE_SEARCH')")
public SolrDocumentList search(SolrQuery query)
{
Objects.requireNonNull(query);
query.setQuery(solrDao.updateQuery(query.getQuery()));
try
{
return solrDao.search(query).getResults();
}
catch (SolrServerException | IOException ex)
{
LOGGER.error(ex);
throw new DHusSearchException("An exception occured while searching", ex);
}
}
示例5: getDatasetCount
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public long getDatasetCount() throws SearchException{
SolrQuery solrQuery = new SolrQuery();
solrQuery.setQuery("*:*");
solrQuery.setFilterQueries(SearchFields.TYPE+":datasets",
SearchFields.PUBLICATION_STATUS+":Published");
solrQuery.setStart(0);
solrQuery.setRows(0);
QueryResponse queryResponse = null;
try {
queryResponse = solrServer.query(solrQuery);
return queryResponse.getResults().getNumFound();
} catch (HttpSolrServer.RemoteSolrException | SolrServerException ex) {
logger.log(Level.INFO, null, ex);
throw new SearchException("Internal Dataverse Search Engine Error", ex);
}
}
開發者ID:pengchengluo,項目名稱:Peking-University-Open-Research-Data-Platform,代碼行數:17,代碼來源:SolrSearchServiceBean.java
示例6: getDataverseCount
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public long getDataverseCount() throws SearchException{
SolrQuery solrQuery = new SolrQuery();
solrQuery.setQuery("*:*");
solrQuery.setFilterQueries(SearchFields.TYPE+":dataverses",
SearchFields.PUBLICATION_STATUS+":Published");
solrQuery.setStart(0);
solrQuery.setRows(0);
QueryResponse queryResponse = null;
try {
queryResponse = solrServer.query(solrQuery);
return queryResponse.getResults().getNumFound();
} catch (HttpSolrServer.RemoteSolrException | SolrServerException ex) {
logger.log(Level.INFO, null, ex);
throw new SearchException("Internal Dataverse Search Engine Error", ex);
}
}
開發者ID:pengchengluo,項目名稱:Peking-University-Open-Research-Data-Platform,代碼行數:17,代碼來源:SolrSearchServiceBean.java
示例7: getQuery
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
private SolrQuery getQuery() {
SolrQuery solrQuery = new SolrQuery();
MCRConfiguration config = MCRConfiguration.instance();
// query
String idQuery = getResult().stream()
.map(getIdentifier())
.map(MCRSolrUtils::escapeSearchValue)
.collect(Collectors.joining(" OR ", "id:(", ")"));
solrQuery.setQuery(idQuery);
solrQuery.setFilterQueries(query);
solrQuery.setFields("id");
solrQuery.setRows(getResult().size());
// request handler
solrQuery.setRequestHandler(config.getString(getConfigPrefix() + "Search.RequestHandler", "/select"));
return solrQuery;
}
示例8: checkSitemapFile
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
* The method computes the number of sitemap files. If we have less than
* <em>numberOfURLs</em> URLs and only one MyCoRe type the sitemap_google.xml
* contained all URLs. Otherwise it split the sitemap in an sitemap_google.xml
* index file and a lot of sitemap_google_xxxx.xml URL files.
*
* @return the number of files, one for a single sitemap_google.xml file, more than
* one for the index and all parts.
*
*/
protected final int checkSitemapFile() throws IOException {
int number = 0;
QueryResponse response;
SolrQuery query = new SolrQuery();
query.setQuery(SOLR_QUERY);
query.setRows(Integer.MAX_VALUE);
query.setParam("fl", "id,modified");
try {
response = MCRSolrClientFactory.getSolrClient().query(query);
objidlist = response.getResults().stream().map((document) -> {
String id = (String) document.getFieldValue("id");
Date modified = (Date) document.getFieldValue("modified");
return new MCRObjectIDDateImpl(modified, id);
}).collect(Collectors.toList());
} catch (SolrServerException e) {
LOGGER.error(e);
}
number = objidlist.size() / numberOfURLs;
if (objidlist.size() % numberOfURLs != 0)
number++;
return number;
}
示例9: filterNonEmpty
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的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));
}
}
示例10: createDocumentQuery
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Override
public SolrQuery createDocumentQuery(String docId) {
// make a query to look up a specific document by its ID
final SolrQuery query = getDefaultDocumentQuery();
// we can use the 'fast' request handler here, document ranking is of no interest
query.setRequestHandler(FacetConstants.SOLR_REQUEST_HANDLER_FAST);
// consider all documents
query.setQuery(SOLR_SEARCH_ALL);
// filter by ID
// check for ID value in both 'id' and 'self link' fields, both ought to
// be unique and self link use to be ID in old VLO, so this should keep old
// URL's valid with a minimal likelihood of clashes
final ImmutableMap<String, String> idOrQueryMap = ImmutableMap.<String, String>builder()
.put(FacetConstants.FIELD_ID, docId)
.put(FacetConstants.FIELD_SELF_LINK, docId)
.build();
query.addFilterQuery(createFilterOrQuery(idOrQueryMap));
// one result max
query.setRows(1);
return query;
}
示例11: getSolrDocument
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public SolrDocument getSolrDocument(String docId) {
if (docId == null) {
throw new NullPointerException("Cannot get SOLR document for null docId");
}
SolrDocument result = null;
SolrQuery query = new SolrQuery();
query.setQuery("id:" + ClientUtils.escapeQueryChars(docId));
query.setFields("*");
SolrDocumentList docs = fireQuery(query).getResults();
if (docs.getNumFound() > 1) {
logger.error("Error: found multiple documents for id (will return first one): " + docId + " \nDocuments found: " + docs);
result = docs.get(0);
} else if (docs.getNumFound() == 1) {
result = docs.get(0);
}
return result;
}
示例12: getChoices
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
* Returns list of suggestions for incomplete input (used for autocomplete
* function)
*
* @param input user input
* @return iterator over suggestions
*/
@Override
public Iterator<String> getChoices(String input) {
if (input != null) {
final SolrQuery query = new SolrQuery();
query.setQuery(input.toLowerCase());
query.setRequestHandler("/suggest");
final QueryResponse response = fireQuery(sanitise(query));
if (response.getSpellCheckResponse() != null) {
final List<Suggestion> suggestions = response.getSpellCheckResponse().getSuggestions();
if (suggestions.size() > 0) {
return suggestions.get(0).getAlternatives().iterator();
}
}
}
return Collections.emptyIterator();
}
示例13: runQuery
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
* Verwendung des Standard Query Parsers, der nur ein Index durchsucht (standardmäßig soll im Feld fulltext_stemmed
* gesucht werden)
*
* @param queryString Suchanfrage
*/
private void runQuery(String queryString) {
SolrQuery query = new SolrQuery();
query.setQuery(queryString);
// TODO Standardsuchfeld definieren mittels Query-Parameter df
query.set("fl", "*,score"); // Feldliste im Resultat (* bedeutet, dass alle Felder zurückgegeben werden, die als stored="true" markiert sind)
query.setRows(10);
QueryRequest req = new QueryRequest(query);
req.setBasicAuthCredentials(Configuration.USERNAME, Configuration.PASSWORD);
QueryResponse response = null;
try {
response = req.process(solrClient);
} catch (SolrServerException|IOException e) {
// do something reasonable
System.err.println(e);
}
printRanking(response);
}
示例14: inSolr
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
boolean inSolr() throws IOException, SolrServerException {
// Check Solr to see if the file has already been index by getting the md5 checksum
// of the file and doing a Solr query using that checksum. Don't run FITS if the
// file already exists.
try (InputStream inputStream = Files.newInputStream(this.getFile())) {
byte[] buffer = new byte[8192];
DigestInputStream digestInputStream = new DigestInputStream(inputStream, messageDigest);
try {
while (digestInputStream.read(buffer) != -1) ;
} finally {
digestInputStream.close();
}
SolrQuery md5Query = new SolrQuery();
md5Query.setQuery("md5checksum:" + DatatypeConverter.printHexBinary(messageDigest.digest()).toLowerCase());
QueryResponse queryResponse = solrClient.query(md5Query);
if (queryResponse.getResults().getNumFound() == 0) {
this.status = false;
} else{
this.status = true;
}
}
return this.status;
}
示例15: getSolrQuery
import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public SolrQuery getSolrQuery(List<WatchList> watchList) {
if (watchList.isEmpty()) {
return null;
}
String searchString = "id:(";
for (WatchList watchListItem : watchList) {
searchString = searchString + "\"" +watchListItem.getBookId() +"\",";
}
searchString = searchString.substring(0, searchString.length()-1) + ")";
SolrQuery query = new SolrQuery();
query.setRows(20);
query.setStart(0);
query.setQuery(searchString);
query.setSort(SolrQuery.SortClause.asc("author"));
query.setFields(SolrSearchUtil.DEFAULT_FIELDS);
return query;
}