Skip to content

Commit

Permalink
Merge pull request #25 from nimble-platform/staging
Browse files Browse the repository at this point in the history
Pull Request for MVP 19.0.0 / FMP 13.0.0
  • Loading branch information
dogukan10 authored Jul 1, 2020
2 parents 494426a + c3c8791 commit c73411c
Show file tree
Hide file tree
Showing 4 changed files with 143 additions and 105 deletions.
10 changes: 6 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Created by .ignore support plugin (hsz.mobi)
/target/
/.classpath
/.project
# Created by .ignore support plugin (hsz.mobi)
/target/
/.classpath
/.project
.idea/
*.iml
200 changes: 102 additions & 98 deletions src/main/java/eu/nimble/indexing/service/SolrService.java
Original file line number Diff line number Diff line change
@@ -1,98 +1,102 @@
package eu.nimble.indexing.service;

import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import org.springframework.data.domain.Pageable;

import eu.nimble.service.model.solr.FacetResult;
import eu.nimble.service.model.solr.IndexField;
import eu.nimble.service.model.solr.Search;
import eu.nimble.service.model.solr.SearchResult;

public interface SolrService<T> {

/**
* Obtain an item based on it's identifier
* @param uri
* @return
*/
public Optional<T> get(String uri);
/**
* Store an item
* @param item
*/
public void set(T item);
/**
* Store a list of items
* @param items
*/
public boolean set(List<T> items);
/**
* Delete an item from the index
* @param uri
*/
public void remove(String uri);
/**
* Retrieve the {@link IndexField} descriptors for the
* collection. The {@link IndexField} denotes
* <ul>
* <li>fieldName: as used in the collection
* <li>dataType: one of string, int, double, boolean
* <li>docCount: the number of documents containing this field
* <li>dynamicBase: the dynamic field used for deriving the fieldName
* </ul>
* @return
*/
public Collection<IndexField> fields();
/**
* Retrieve the {@link IndexField} descritors for the collection. Perform
* filtering based on the provided list.
* @param fields A list of fieldNames to return, wildcards are allowed as the first/last character.
* @return
*/
public Collection<IndexField> fields(Set<String> fields);
/**
* Perform a search against the collection
* @param search The search definition holding query, filterQuery and faceting parameters
* @return
*/
public SearchResult<T> search(Search search);
/**
* Perform a select query against the collection
* @param query The query term used with the <code>q</code> query parameter
* @param filterQueries The filter terms uses as <code>fq</code> query parameters
* @param facetFields The names used for faceting, e.g. <code>facet.field</code> parameters
* @param facetLimit The number of facet elements to return for each facet
* @param facetMinCount The minimum number of facet occurrences to be included in the result
* @param page The {@link Pageable} pointing to the current page & size
* @return
*/
public SearchResult<T> select(String query, List<String> filterQueries, List<String> facetFields, int facetLimit, int facetMinCount, Pageable page);

/**
* Perform a select query against the collection
* @param query The query term used with the <code>q</code> query parameter
* @param filterQueries The filter terms uses as <code>fq</code> query parameters
* @param facetFields The names used for faceting, e.g. <code>facet.field</code> parameters
* @param sortFields Set of attributes for search pointing to the current page & size
* @param facetLimit The number of facet elements to return for each facet
* @param facetMinCount The minimum number of facet occurrences to be included in the result
* @param page The {@link Pageable} pointing to the current page & size
* @return
*/
public SearchResult<T> select(String query, List<String> filterQueries, List<String> facetFields,List<String> sortFields, int facetLimit, int facetMinCount, Pageable page);

/**
* Perform a auto suggest query
* @param query The query term used with the <code>q</code> query parameter
* @param filterQueries The filter terms uses as <code>fq</code> query parameters
* @param facetFields The names used for faceting, e.g. <code>facet.field</code> parameters
* @param facetLimit The number of facet elements to return for each facet
* @param facetMinCount The minimum number of facet occurrences to be included in the result
* @return A {@link FacetResult} denoting name, facet and facet count
*/
public FacetResult suggest(String query, String facetField, int facetLimit, int facetMinCount);
}
package eu.nimble.indexing.service;

import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;

import org.springframework.data.domain.Pageable;

import eu.nimble.service.model.solr.FacetResult;
import eu.nimble.service.model.solr.IndexField;
import eu.nimble.service.model.solr.Search;
import eu.nimble.service.model.solr.SearchResult;

public interface SolrService<T> {

/**
* Obtain an item based on it's identifier
* @param uri
* @return
*/
public Optional<T> get(String uri);
/**
* Store an item
* @param item
*/
public void set(T item);
/**
* Store a list of items
* @param items
*/
public boolean set(List<T> items);
/**
* Delete an item from the index
* @param uri
*/
public void remove(String uri);
/**
* Clear the index
*/
public void clearIndex();
/**
* Retrieve the {@link IndexField} descriptors for the
* collection. The {@link IndexField} denotes
* <ul>
* <li>fieldName: as used in the collection
* <li>dataType: one of string, int, double, boolean
* <li>docCount: the number of documents containing this field
* <li>dynamicBase: the dynamic field used for deriving the fieldName
* </ul>
* @return
*/
public Collection<IndexField> fields();
/**
* Retrieve the {@link IndexField} descritors for the collection. Perform
* filtering based on the provided list.
* @param fields A list of fieldNames to return, wildcards are allowed as the first/last character.
* @return
*/
public Collection<IndexField> fields(Set<String> fields);
/**
* Perform a search against the collection
* @param search The search definition holding query, filterQuery and faceting parameters
* @return
*/
public SearchResult<T> search(Search search);
/**
* Perform a select query against the collection
* @param query The query term used with the <code>q</code> query parameter
* @param filterQueries The filter terms uses as <code>fq</code> query parameters
* @param facetFields The names used for faceting, e.g. <code>facet.field</code> parameters
* @param facetLimit The number of facet elements to return for each facet
* @param facetMinCount The minimum number of facet occurrences to be included in the result
* @param page The {@link Pageable} pointing to the current page & size
* @return
*/
public SearchResult<T> select(String query, List<String> filterQueries, List<String> facetFields, int facetLimit, int facetMinCount, Pageable page);

/**
* Perform a select query against the collection
* @param query The query term used with the <code>q</code> query parameter
* @param filterQueries The filter terms uses as <code>fq</code> query parameters
* @param facetFields The names used for faceting, e.g. <code>facet.field</code> parameters
* @param sortFields Set of attributes for search pointing to the current page & size
* @param facetLimit The number of facet elements to return for each facet
* @param facetMinCount The minimum number of facet occurrences to be included in the result
* @param page The {@link Pageable} pointing to the current page & size
* @return
*/
public SearchResult<T> select(String query, List<String> filterQueries, List<String> facetFields,List<String> sortFields, int facetLimit, int facetMinCount, Pageable page);

/**
* Perform a auto suggest query
* @param query The query term used with the <code>q</code> query parameter
* @param filterQueries The filter terms uses as <code>fq</code> query parameters
* @param facetFields The names used for faceting, e.g. <code>facet.field</code> parameters
* @param facetLimit The number of facet elements to return for each facet
* @param facetMinCount The minimum number of facet occurrences to be included in the result
* @return A {@link FacetResult} denoting name, facet and facet count
*/
public FacetResult suggest(String query, String facetField, int facetLimit, int facetMinCount);
}
14 changes: 11 additions & 3 deletions src/main/java/eu/nimble/indexing/service/impl/SolrServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public void remove(String uri) {
}
}

@Override
public void clearIndex() {
solr.deleteAll();
}

@Override
public SearchResult<T> search(Search search) {
if(search.getSort() != null) {
Expand Down Expand Up @@ -151,14 +156,17 @@ public SearchResult<T> select(String query, List<String> filterQueries, List<Str

@Override
public SearchResult<T> select(String query, List<String> filterQueries, List<String> facetFields, List<String> sortFields, int facetLimit, int facetMinCount, Pageable page) {
JoinHelper joinHelper = new JoinHelper(getCollection());
// expand main query to a wild card search when it is only a single word
if (query.indexOf(":") == -1 && query.indexOf("*") == -1 && query.indexOf(" ") == -1) {
query = String.format("*%s*", query);
}

else if (query.indexOf("classification.") != -1) {
//parse the query with a join on class index for synonyms
query = joinHelper.parseQuery(query);
}

Criteria qCriteria = new SimpleStringCriteria(query);
//
JoinHelper joinHelper = new JoinHelper(getCollection());

if ( filterQueries != null && !filterQueries.isEmpty()) {
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,18 @@ public ResponseEntity<?> searchParty(
return ResponseEntity.ok(result);
}

@ApiOperation(value = "", notes = "Clear party index", response = Boolean.class)
@DeleteMapping("/party/clear")
public ResponseEntity<?> clearPartyIndex(
@RequestHeader(value = "Authorization") String bearerToken) throws Exception {

if (identityService.hasAnyRole(bearerToken, PLATFORM_MANAGER,LEGAL_REPRESENTATIVE,NIMBLE_USER,
PUBLISHER,COMPANY_ADMIN,EFACTORYUSER) == false)
return new ResponseEntity<>("User Not Allowed To Clear Party Index", HttpStatus.UNAUTHORIZED);
partyService.clearIndex();
return ResponseEntity.ok(Boolean.TRUE);
}

@ApiOperation(value = "", notes = "Retrieve a specific party identified by the given uri", response = PartyType.class)
@GetMapping("/party")
public ResponseEntity<?> getParty(
Expand Down Expand Up @@ -798,6 +810,18 @@ public ResponseEntity<?> getItem(
return ResponseEntity.of(result);
}

@ApiOperation(value = "", notes = "Clear item index", response = Boolean.class)
@DeleteMapping("/item/clear")
public ResponseEntity<?> clearItemIndex(
@RequestHeader(value = "Authorization") String bearerToken) throws Exception {

if (identityService.hasAnyRole(bearerToken, PLATFORM_MANAGER,LEGAL_REPRESENTATIVE,NIMBLE_USER,
PUBLISHER,COMPANY_ADMIN,EFACTORYUSER) == false)
return new ResponseEntity<>("User Not Allowed To Clear Item Index", HttpStatus.UNAUTHORIZED);
itemService.clearIndex();
return ResponseEntity.ok(Boolean.TRUE);
}

@ApiOperation(value = "", notes = "Detele an item", response = Boolean.class)
@DeleteMapping("/item")
public ResponseEntity<?> removeItem(
Expand Down

0 comments on commit c73411c

Please sign in to comment.