Skip to content

Commit

Permalink
update Cache ID
Browse files Browse the repository at this point in the history
  • Loading branch information
blueSwordfish committed Jun 26, 2024
1 parent c32bacd commit 26ad2dd
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ public FacetMeta searchImportFacetFieldDrilldownV1(@RequestParam("q") Optional<S

List<String> userLists = new ArrayList<>();
String userName = "";
if(GsrsSecurityUtils.getCurrentUsername().isPresent()) {
if(field.isPresent() && field.get().equalsIgnoreCase("User List") && GsrsSecurityUtils.getCurrentUsername().isPresent()) {
userName = GsrsSecurityUtils.getCurrentUsername().get();
userLists= userSavedListService.getUserSearchResultLists(userName, getEntityService().getEntityClass().getName());
}
Expand All @@ -1098,10 +1098,7 @@ public FacetMeta searchImportFacetFieldDrilldownV1(@RequestParam("q") Optional<S
TextIndexer.TermVectors tv = (TextIndexer.TermVectors)gsrscache.getRaw(cacheID);
if(tv == null) {
tv = getlegacyGsrsSearchService().getTermVectorsFromQueryNew(query.orElse(null), so, field.orElse(null));
gsrscache.setRaw(cacheID, tv);
log.info("staging: getting facets from indexes");
}else {
log.info("staging: getting facets from cache");
gsrscache.setRaw(cacheID, tv);
}

String sortByProp = sortBy.isPresent()?sortBy.get():"";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -387,6 +387,8 @@ public FacetMeta searchFacetFieldDrilldownV1(@RequestParam("q") Optional<String>
@RequestParam("sortBy") Optional<String> sortBy,
@RequestParam("sortDesc") Optional<Boolean> sortOrder,
HttpServletRequest request) throws ParseException, IOException {


SearchOptions so = new SearchOptions.Builder()
.kind(getEntityService().getEntityClass())
.top(Integer.MAX_VALUE) // match Play GSRS
Expand All @@ -399,20 +401,17 @@ public FacetMeta searchFacetFieldDrilldownV1(@RequestParam("q") Optional<String>

List<String> userLists = new ArrayList<>();
String userName = "";
if(GsrsSecurityUtils.getCurrentUsername().isPresent()) {
if(field.isPresent() && field.get().equalsIgnoreCase("User List") && GsrsSecurityUtils.getCurrentUsername().isPresent()) {
userName = GsrsSecurityUtils.getCurrentUsername().get();
userLists= userSavedListService.getUserSearchResultLists(userName, getEntityService().getEntityClass().getName());
}

String cacheID = getFacetCacheID("", query.orElse(""), so, field.orElse(""));
log.info("cache ID: " + cacheID);
TextIndexer.TermVectors tv = (TextIndexer.TermVectors)gsrscache.getRaw(cacheID);
if(tv == null) {
tv = getlegacyGsrsSearchService().getTermVectorsFromQuery(query.orElse(null), so, field.orElse(null));
gsrscache.setRaw(cacheID, tv);
log.info("/search/@facet: getting facets from indexes");
}else {
log.info("/search/@facet: getting facets from cache");
if(tv == null) {
tv = getlegacyGsrsSearchService().getTermVectorsFromQuery(query.orElse(null), so, field.orElse(null));
gsrscache.setRaw(cacheID, tv);
}

String sortByProp = sortBy.isPresent()?sortBy.get():"";
Expand Down Expand Up @@ -445,20 +444,17 @@ public FacetMeta searchFacetFieldV1(@RequestParam("field") Optional<String> fiel

List<String> userLists = new ArrayList<>();
String userName = "";
if(GsrsSecurityUtils.getCurrentUsername().isPresent()) {
if(field.isPresent() && field.get().equalsIgnoreCase("User List") && GsrsSecurityUtils.getCurrentUsername().isPresent()) {
userName = GsrsSecurityUtils.getCurrentUsername().get();
userLists= userSavedListService.getUserSearchResultLists(userName, getEntityService().getEntityClass().getName());
}

String cacheID = getFacetCacheID("", "", so, field.orElse(""));
log.info("cache ID: " + cacheID);
// log.info("cache ID: " + cacheID);
TextIndexer.TermVectors tv = (TextIndexer.TermVectors)gsrscache.getRaw(cacheID);
if(tv == null) {
tv = getlegacyGsrsSearchService().getTermVectors(field);
gsrscache.setRaw(cacheID, tv);
log.info("/@facet: getting facets from indexes");
}else {
log.info("/@facet: getting facets from cache");
gsrscache.setRaw(cacheID, tv);
}

String sortByProp = sortBy.isPresent()?sortBy.get():"";
Expand Down Expand Up @@ -1470,7 +1466,8 @@ private String generateResultIDJson(String id) {
}

protected String getFacetCacheID(String namespace, String query, SearchOptions so, String field) {
return namespace + "FacetSearch/" + query + field + ",ffilter=" + so.getFfilter()
+",fskip=" + so.getFskip() + "," + so.toString();
SearchRequest.Builder builder = new SearchRequest.Builder();
String SRHash = builder.options(so).query(query).build().getDefiningSetSha1();
return namespace + "FacetSearch/" + field + SRHash;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -458,37 +458,53 @@ else if(sortBy.equalsIgnoreCase(FacetImpl.COUNT)){
}
}
}

if(userName.isEmpty() || userLists.size() == 0) {

terms.entrySet()
.stream()
.parallel()
.map(es->Tuple.of(es.getKey(), es.getValue().getNDocs()))
.filter(filt)
.map(t->new FV(fac,t.k(),t.v()))
.collect(StreamUtil.maxElements(top+skip, facetComparator))
.skip(skip)
.limit(top)
.forEach(fv->{
fac.add(fv);
});
}else {

terms.entrySet()
.stream()
.parallel()
.map(es->Tuple.of(es.getKey(), es.getValue().getNDocs()))
.filter(filt)
.map(t->new FV(fac,t.k(),t.v()))
.filter(fv->{
if(field.equalsIgnoreCase("User List")) {
// check the current user, filter facet by user name
UserListIndexedValue dataItem = UserSavedListService.getUserNameAndListNameFromIndexedValue(fv.getLabel());
String nameInLabel = dataItem.getUserName();
String listName = dataItem.getListName();
if(userName.equalsIgnoreCase(nameInLabel) && userLists.contains(listName)) {
return true;
}else {
return false;
}
}else {
return true;
}
})
.collect(StreamUtil.maxElements(top+skip, facetComparator))
.skip(skip)
.limit(top)
.forEach(fv->{
fac.add(fv);
});

}

terms.entrySet()
.stream()
.parallel()
.map(es->Tuple.of(es.getKey(), es.getValue().getNDocs()))
.filter(filt)
.map(t->new FV(fac,t.k(),t.v()))
.filter(fv->{
if(field.equalsIgnoreCase("User List")) {
// check the current user, filter facet by user name
UserListIndexedValue dataItem = UserSavedListService.getUserNameAndListNameFromIndexedValue(fv.getLabel());
String nameInLabel = dataItem.getUserName();
String listName = dataItem.getListName();
if(userName.isEmpty() || userLists.size() == 0) {
return false;
}else if(userName.equalsIgnoreCase(nameInLabel) && userLists.contains(listName)) {
return true;
}else {
return false;
}
}else {
return true;
}
})
.collect(StreamUtil.maxElements(top+skip, facetComparator))
.skip(skip)
.limit(top)
.forEach(fv->{
fac.add(fv);
});

return new FacetMeta.Builder()
.facets(fac)
.ffilter(filter)
Expand Down Expand Up @@ -558,6 +574,7 @@ static class TermVectorsCollector<T>

private TermVectorsCollector (Class<T> kind, String originalField, IndexSearcher searcher, Query extrafilter, Query q)
throws IOException {

String adaptedField = TERM_VEC_PREFIX + originalField;

tvec = new TermVectors (kind, adaptedField);
Expand All @@ -571,11 +588,10 @@ private TermVectorsCollector (Class<T> kind, String originalField, IndexSearcher
.collect(Collectors.toSet());
fieldSet.add(FIELD_KIND);


this.reader = searcher.getIndexReader();

Query filter = filterForKinds(kind);

if(q==null){
q = new MatchAllDocsQuery();
}
Expand All @@ -592,18 +608,19 @@ private TermVectorsCollector (Class<T> kind, String originalField, IndexSearcher
.add(filter, BooleanClause.Occur.FILTER)
.build();
}

searcher.search(q, this);

Collections.sort(tvec.docs);

tvec.terms= counts.entrySet()
.stream()
.map(Tuple::of)
.map(Tuple.vmap(DocumentSet::of))
.collect(Tuple.toMap());
counts = null;



}

//
Expand Down

0 comments on commit 26ad2dd

Please sign in to comment.