Created
July 24, 2012 12:18
-
-
Save nshaw/3169628 to your computer and use it in GitHub Desktop.
Adding boost factors at runtime
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
for (String assetType : assetTypes) { | |
BooleanQuery assetTypeQuery = BooleanQueryFactoryUtil.create(context); | |
assetTypesQuery.add(assetTypeQuery, BooleanClauseOccur.SHOULD); | |
if( (assetBoostFactors != null) | |
&& (index <= assetBoostFactors.length)) { | |
int boost = assetBoostFactors[index]; | |
Class clazz = assetTypesQuery.getClass(); | |
//Note: can't do instanceOf since BQI is in portal-impl | |
if ("com.liferay.portal.search.lucene.BooleanQueryImpl".equals(clazz.getName())) { | |
try { | |
java.lang.reflect.Field field = clazz.getDeclaredField("_booleanQuery"); | |
field.setAccessible(true); | |
Object bq = field.get(assetTypeQuery); | |
java.lang.reflect.Field field2 = bq.getClass().getSuperclass().getDeclaredField("boost"); | |
field2.setAccessible(true); | |
field2.setFloat(bq, boost); | |
} | |
catch (Exception e) { | |
_log.debug("Unable to set boost: ", e); | |
} | |
} | |
else { | |
_log.debug("Wrong implementation, cannot set boost: " + clazz.getName()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment