Permalink
Browse files

Fix search on dates through web service

There were 2 issues. First, if no restriction other than date is applied then
no result is return due to bug in the query generated. Now a dummy
query is added in front of so nullify the bug. Second shorter comparator
first checking caused number format exception so the order of checking
for comparator is fixed.

Signed-off-by: Imran M Yousuf <imyousuf@smartitengineering.com>
  • Loading branch information...
1 parent 4fa4877 commit 50d99cc3a30acb580027b0f9fe263432dfc5d67e @imyousuf imyousuf committed Apr 29, 2012
@@ -137,22 +137,6 @@
if (contentTypeIds != null && !contentTypeIds.isEmpty()) {
query.append(")");
}
- if (filter.getCreationDateFilter() != null) {
- if (query.length() > 0) {
- query.append(seperator);
- }
- QueryParameter<Date> creationDateFilter = filter.getCreationDateFilter();
- String queryStr = generateDateQuery(SolrFieldNames.CREATIONDATE, creationDateFilter);
- query.append(queryStr);
- }
- if (filter.getLastModifiedDateFilter() != null) {
- if (query.length() > 0) {
- query.append(seperator);
- }
- QueryParameter<Date> lastModifiedDateFilter = filter.getLastModifiedDateFilter();
- String queryStr = generateDateQuery(SolrFieldNames.LASTMODIFIEDDATE, lastModifiedDateFilter);
- query.append(queryStr);
- }
if (StringUtils.isNotBlank(filter.getSearchTerms())) {
if (query.length() > 0) {
query.append(seperator);
@@ -171,6 +155,28 @@
Collection<QueryParameter> fieldQuery = new ArrayList<QueryParameter>(filter.getFieldFilters());
final QueryParameter orderParam = findAndRemoveOrderByParam(fieldQuery);
processParams(fieldQuery, query, seperator, filter.isFieldParamsEscaped());
+ if (filter.getCreationDateFilter() != null) {
+ if (query.length() > 0) {
+ query.append(seperator);
+ }
+ else {
+ query.append("contentTypeId: [* TO *]").append(seperator);
+ }
+ QueryParameter<Date> creationDateFilter = filter.getCreationDateFilter();
+ String queryStr = generateDateQuery(SolrFieldNames.CREATIONDATE, creationDateFilter);
+ query.append(queryStr);
+ }
+ if (filter.getLastModifiedDateFilter() != null) {
+ if (query.length() > 0) {
+ query.append(seperator);
+ }
+ else {
+ query.append("contentTypeId: [* TO *]").append(seperator);
+ }
+ QueryParameter<Date> lastModifiedDateFilter = filter.getLastModifiedDateFilter();
+ String queryStr = generateDateQuery(SolrFieldNames.LASTMODIFIEDDATE, lastModifiedDateFilter);
+ query.append(queryStr);
+ }
if (query.length() > 0) {
finalQuery.append(conjunctionSeperator).append('(').append(query.toString()).append(')');
}
@@ -200,10 +200,19 @@ public void run() {
query.append(")");
}
+ if (StringUtils.isNotBlank(filter.getSearchTerms())) {
+ if (query.length() > 0) {
+ query.append(seperator);
+ }
+ query.append(SolrFieldNames.ALL_TEXT).append(": ").append(ClientUtils.escapeQueryChars(filter.getSearchTerms()));
+ }
if (filter.getCreationDateFilter() != null) {
if (query.length() > 0) {
query.append(seperator);
}
+ else {
+ query.append("workspaceId: [* TO *]").append(seperator);
+ }
QueryParameter<Date> creationDateFilter = filter.getCreationDateFilter();
String queryStr = ContentSearcherImpl.generateDateQuery(SolrFieldNames.CREATIONDATE, creationDateFilter);
query.append(queryStr);
@@ -213,18 +222,14 @@ public void run() {
if (query.length() > 0) {
query.append(seperator);
}
+ else {
+ query.append("workspaceId: [* TO *]").append(seperator);
+ }
QueryParameter<Date> lastModifiedDateFilter = filter.getLastModifiedDateFilter();
String queryStr = ContentSearcherImpl.generateDateQuery(SolrFieldNames.LASTMODIFIEDDATE, lastModifiedDateFilter);
query.append(queryStr);
}
- if (StringUtils.isNotBlank(filter.getSearchTerms())) {
- if (query.length() > 0) {
- query.append(seperator);
- }
- query.append(SolrFieldNames.ALL_TEXT).append(": ").append(ClientUtils.escapeQueryChars(filter.getSearchTerms()));
- }
-
if (query.length() > 0) {
finalQuery.append(conjunctionSeperator).append('(').append(query.toString()).append(')');
}
@@ -465,25 +465,24 @@ public static ContentTypeId parseContentTypeId(String strContentTypeId) {
return null;
}
QueryParameter<Date> queryParameter = null;
- if (strDate.startsWith(">")) {
- String date = strDate.replace(">", "");
- queryParameter = QueryParameterFactory.getGreaterThanPropertyParam("greaterThan", new Date(Long.parseLong(date)));
- }
- else if (strDate.startsWith("<")) {
- String date = strDate.replace("<", "");
- queryParameter = QueryParameterFactory.getLesserThanPropertyParam("lessThan", new Date(Long.parseLong(date)));
- }
- else if (strDate.startsWith(">=")) {
+ if (strDate.startsWith(">=")) {
String date = strDate.replaceAll(">=", "");
queryParameter = QueryParameterFactory.getGreaterThanEqualToPropertyParam("greaterOrEqual", new Date(Long.
- parseLong(
- date)));
+ parseLong(date)));
}
else if (strDate.startsWith("<=")) {
String date = strDate.replaceAll("<=", "");
queryParameter = QueryParameterFactory.getLesserThanEqualToPropertyParam("lessOrEqual", new Date(Long.parseLong(
date)));
}
+ else if (strDate.startsWith("<")) {
+ String date = strDate.replace("<", "");
+ queryParameter = QueryParameterFactory.getLesserThanPropertyParam("lessThan", new Date(Long.parseLong(date)));
+ }
+ else if (strDate.startsWith(">")) {
+ String date = strDate.replace(">", "");
+ queryParameter = QueryParameterFactory.getGreaterThanPropertyParam("greaterThan", new Date(Long.parseLong(date)));
+ }
else if (strDate.contains(",")) {
String[] date = strDate.split(",");
queryParameter = QueryParameterFactory.getBetweenPropertyParam("between", new Date(Long.parseLong(date[0])),

0 comments on commit 50d99cc

Please sign in to comment.