This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rhbz882770 - add multi field search support to FilterConstraintToQuery
- Loading branch information
Patrick Huang
committed
Apr 10, 2014
1 parent
907ce45
commit a72e138
Showing
19 changed files
with
1,173 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
zanata-war/src/main/java/org/zanata/search/ContentCriterion.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} | ||
} |
Oops, something went wrong.