Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
rhbz882770 - add multi field search support to FilterConstraintToQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Huang committed Apr 10, 2014
1 parent 907ce45 commit a72e138
Show file tree
Hide file tree
Showing 19 changed files with 1,173 additions and 210 deletions.
13 changes: 13 additions & 0 deletions zanata-war/pom.xml
Expand Up @@ -1392,6 +1392,19 @@
</exclusions>
</dependency>

<dependency>
<groupId>com.github.huangp</groupId>
<artifactId>entityunit</artifactId>
<version>0.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.googlecode.log4jdbc</groupId>
<artifactId>log4jdbc</artifactId>
<version>1.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
Expand Down
8 changes: 4 additions & 4 deletions zanata-war/src/main/java/org/zanata/dao/TextFlowDAO.java
Expand Up @@ -318,8 +318,8 @@ public List<HTextFlow> getTextFlowByDocumentIdWithConstraints(

@SuppressWarnings("unchecked")
List<HTextFlow> result = textFlowQuery.list();
log.debug("{} textFlow for locale {} filter by {}", new Object[] {
result.size(), hLocale.getLocaleId(), constraints });
log.debug("{} textFlow for locale {} filter by {}", result.size(),
hLocale.getLocaleId(), constraints);
return result;
}

Expand All @@ -339,8 +339,8 @@ public List<HTextFlow> getAllTextFlowByDocumentIdWithConstraints(

@SuppressWarnings("unchecked")
List<HTextFlow> result = textFlowQuery.list();
log.debug("{} textFlow for locale {} filter by {}", new Object[] {
result.size(), hLocale.getLocaleId(), constraints });
log.debug("{} textFlow for locale {} filter by {}", result.size(),
hLocale.getLocaleId(), constraints);
return result;
}
}
40 changes: 40 additions & 0 deletions zanata-war/src/main/java/org/zanata/search/ContentCriterion.java
@@ -0,0 +1,40 @@
package org.zanata.search;

import java.util.List;

import org.zanata.common.HasContents;
import org.zanata.util.HqlCriterion;
import org.zanata.util.QueryBuilder;
import com.google.common.base.Strings;
import com.google.common.collect.Lists;

/**
* @author Patrick Huang <a
* href="mailto:pahuang@redhat.com">pahuang@redhat.com</a>
*/
public class ContentCriterion {
// so that in test we can override and have less verbose string
private final int numOfContentFields;

public ContentCriterion() {
this(HasContents.MAX_PLURALS);
}

// test override-able
ContentCriterion(int numOfContentFields) {
this.numOfContentFields = numOfContentFields;
}

public String contentsCriterionAsString(String alias,
boolean caseSensitive, String namedParam) {
String propertyAlias =
Strings.isNullOrEmpty(alias) ? "content" : alias + ".content";
List<String> conditions = Lists.newArrayList();
for (int i = 0; i < numOfContentFields; i++) {
String contentFieldName = propertyAlias + i;
conditions.add(HqlCriterion.like(contentFieldName, caseSensitive,
namedParam));
}
return QueryBuilder.or(conditions);
}
}

0 comments on commit a72e138

Please sign in to comment.