List of usage examples for org.springframework.data.solr.core.query SimpleQuery SimpleQuery
public SimpleQuery(String queryString)
From source file:example.springdata.solr.product.ProductRepositoryImpl.java
@Override public Cursor<Product> findAllUsingCursor() { // NOTE: Using Cursor requires to sort by an unique field return solrTemplate.queryForCursor(new SimpleQuery("*:*").addSort(new Sort("id")), Product.class); }
From source file:com.nixmash.springdata.solr.repository.custom.CustomProductRepositoryImpl.java
@Override public Page<Product> findTestCategoryRecords() { return solrTemplate.queryForPage( new SimpleQuery(new SimpleStringCriteria("cat:test")).setPageRequest(new PageRequest(0, 100)), Product.class); }
From source file:com.nixmash.springdata.solr.repository.custom.CustomProductRepositoryImpl.java
@Override public List<Product> findProductsBySimpleQuery(String userQuery) { Query query = new SimpleQuery(userQuery); query.addFilterQuery(new SimpleQuery(new Criteria(IProduct.DOCTYPE_FIELD).is(SolrDocType.PRODUCT))); query.setRows(1000);//from w ww . j a v a 2 s. c om Page<Product> results = solrTemplate.queryForPage(query, Product.class); return results.getContent(); }
From source file:com.nixmash.springdata.solr.repository.custom.CustomProductRepositoryImpl.java
@Override public List<Product> searchWithCriteria(String searchTerm) { logger.debug("Building a criteria query with search term: {}", searchTerm); String[] words = searchTerm.split(" "); Criteria conditions = createSearchConditions(words); SimpleQuery search = new SimpleQuery(conditions); search.addSort(sortByIdDesc());/*from ww w. j ava 2s .co m*/ Page<Product> results = solrTemplate.queryForPage(search, Product.class); return results.getContent(); }
From source file:example.springdata.solr.AdvancedSolrRepositoryTests.java
/** * Using {@link Function} in queries has no influence on restricting results as all documents will match the function. * Though it does influence document score. In this sample documents not having popularity assigned will be sorted to * the end of the list.//from w ww . ja v a 2 s . c om */ @Test public void influcenceScoreWithFunctions() { Query query = new SimpleQuery(where(exists("popularity"))).addProjectionOnFields("*", "score"); operations.queryForPage(query, Product.class).forEach(System.out::println); }
From source file:example.springdata.solr.AdvancedSolrRepositoryTests.java
/** * Using {@link SolrOperations#getById(java.io.Serializable, Class)} allows reading uncommitted documents from the * update log./* ww w . j a va 2 s . c o m*/ */ @Test public void useRealtimeGetToReadUncommitedDocuments() throws InterruptedException { Product xbox = Product.builder().id("id-5").name("XBox").description("Microsift XBox").popularity(2) .build(); Query query = new SimpleQuery(where("id").is(xbox.getId())); // add document but delay commit for 3 seconds operations.saveBean(xbox, 3000); // document will not be returned hence not yet committed to the index assertThat(operations.queryForObject(query, Product.class), nullValue()); // realtime-get fetches uncommitted document assertThat(operations.getById(xbox.getId(), Product.class), notNullValue()); // wait a little so that changes get committed to the index - normal query will now be able to find the document. Thread.sleep(3010); assertThat(operations.queryForObject(query, Product.class), notNullValue()); }
From source file:org.opengeoportal.harvester.api.client.solr.SolrSearchParams.java
/** * Transform the record in {@link SolrQuery} executable by an * {@link org.apache.solr.client.solrj.impl.HttpSolrServer}. * /*from w w w .j a v a2s . co m*/ * @return the {@link SolrQuery} built with the data page this. */ public SolrQuery toSolrQuery() { SolrQuery solrQuery = new SolrQuery(); if (StringUtils.isNotBlank(customSolrQuery)) { solrQuery.setQuery(customSolrQuery); } else { solrQuery.setQuery("*:*"); // data repositories if (dataRepositories != null && dataRepositories.size() > 0) { Criteria institutionCriteria = null; for (String institution : dataRepositories) { if (institutionCriteria == null) { institutionCriteria = new Criteria(SolrRecord.INSTITUTION).is(institution); } else { institutionCriteria = institutionCriteria .or(new Criteria(SolrRecord.INSTITUTION).is(institution)); } } SimpleQuery query = new SimpleQuery(institutionCriteria); DefaultQueryParser parser = new DefaultQueryParser(); String queryString = parser.getQueryString(query); solrQuery.addFilterQuery(queryString); } else { solrQuery.addFilterQuery(SolrRecord.INSTITUTION + ":*"); } // theme keywords if (StringUtils.isNotBlank(themeKeyword)) { solrQuery.addFilterQuery(SolrRecord.THEME_KEYWORDS + ":" + themeKeyword); solrQuery.add(PF, SolrRecord.THEME_KEYWORDS + ":'" + themeKeyword + "'^9.0"); solrQuery.add(PF, SolrRecord.LAYER_DISPLAY_NAME + ":'" + themeKeyword + "'^9.0"); } if (StringUtils.isNotBlank(placeKeyword)) { solrQuery.addFilterQuery(SolrRecord.PLACE_KEYWORDS + ":" + placeKeyword); solrQuery.add(PF, SolrRecord.PLACE_KEYWORDS + ":'" + placeKeyword + "'^9.0"); } if (StringUtils.isNotBlank(topicCategory)) { solrQuery.addFilterQuery(SolrRecord.ISO_TOPIC_CATEGORY + ":" + this.topicCategory); } if (dateFrom != null || dateTo != null) { Criteria contentDateCriteria = Criteria.where(SolrRecord.CONTENT_DATE).between(dateFrom, dateTo); SimpleQuery query = new SimpleQuery(contentDateCriteria); DefaultQueryParser parser = new DefaultQueryParser(); String queryString = parser.getQueryString(query); solrQuery.addFilterQuery(queryString); } if (StringUtils.isNotBlank(originator)) { String originatorCriteria = splitAndConcatenateUsingOperator(Operator.AND, SolrRecord.ORIGINATOR, originator); solrQuery.addFilterQuery(originatorCriteria); solrQuery.add(PF, SolrRecord.ORIGINATOR + ":" + originator); } if (dataTypes != null && dataTypes.size() > 0) { StringBuilder concatenatedType = new StringBuilder(); for (DataType dType : dataTypes) { concatenatedType.append(dType.toString().replace(" ", "+")).append(" "); } String dataTypeCriteria = splitAndConcatenateUsingOperator(Operator.OR, SolrRecord.DATA_TYPE, concatenatedType.toString()); solrQuery.add("fq", dataTypeCriteria); } if (excludeRestrictedData) { solrQuery.addFilterQuery(SolrRecord.ACCESS + ":" + AccessLevel.Public); } if (fromSolrTimestamp != null || toSolrTimestamp != null) { Criteria solrTimestampCriteria = Criteria.where(SolrRecord.TIMESTAMP).between(fromSolrTimestamp, toSolrTimestamp); SimpleQuery query = new SimpleQuery(solrTimestampCriteria); DefaultQueryParser parser = new DefaultQueryParser(); String queryString = parser.getQueryString(query); solrQuery.addFilterQuery(queryString); } // Add bbox filter only if user has not specified a custom solr // query. buildBoundigBoxQuery(solrQuery); String synonymsFilter = generateSynonymsQuery(); if (StringUtils.isNotBlank(synonymsFilter)) { solrQuery.addFilterQuery(synonymsFilter); } } solrQuery.setRows(pageSize); solrQuery.setStart(page * pageSize); solrQuery.addSort(SortClause.desc("score")); return solrQuery; }
From source file:org.opengeoportal.harvester.api.client.solr.SolrSearchParams.java
/** * Split wordlist by blank space and create an OR criteria with each * resulting word. Words are added using wildcards. * //from w w w .j a va 2 s .c om * @param wordList * a string with a list of words * @param fieldName * the name of the field where criteria is applied. * @return an OR criteria with each word contained in wordlist. */ private Criteria splitAndOrCriteria(String wordList, String fieldName) { Criteria orCriteria = null; String[] words = StringUtils.split(wordList); for (String word : words) { if (orCriteria == null) { orCriteria = new Criteria(fieldName).contains(word); } else { orCriteria = orCriteria.or(new Criteria(fieldName).contains(word)); } } if (orCriteria != null) { SimpleQuery query = new SimpleQuery(orCriteria); DefaultQueryParser parser = new DefaultQueryParser(); String queryString = parser.getQueryString(query); return new SimpleStringCriteria("(" + queryString + ")"); } else { return null; } }