Author: bpoussin Date: 2012-02-03 19:08:40 +0100 (Fri, 03 Feb 2012) New Revision: 1412 Url: http://nuiton.org/repositories/revision/wikitty/1412 Log: Evolution #1944: Enhance in memory implementation Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyUtil.java trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query/FacetTopicCountComparator.java trunk/wikitty-api/src/main/java/org/nuiton/wikitty/storage/WikittySearchEngineInMemory.java Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyUtil.java =================================================================== --- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyUtil.java 2012-02-03 18:00:37 UTC (rev 1411) +++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/WikittyUtil.java 2012-02-03 18:08:40 UTC (rev 1412) @@ -1009,8 +1009,12 @@ * TODO poussin 20101208 redondant code with {@link WikittyExtension#extractFieldName(java.lang.String)} */ public static String getFieldNameFromFQFieldName(String fqFieldName) { - String[] fqFieldElements = fqFieldName.split(FQ_FIELD_NAME_SEPARATOR_REGEX); - return fqFieldElements[1]; + try { + String[] fqFieldElements = fqFieldName.split(FQ_FIELD_NAME_SEPARATOR_REGEX); + return fqFieldElements[1]; + } catch(ArrayIndexOutOfBoundsException eee) { + throw new WikittyException("Field is not fully qualified field:" + fqFieldName, eee); + } } /** given names of extension and field, return a fully qualified field name */ Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query/FacetTopicCountComparator.java =================================================================== --- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query/FacetTopicCountComparator.java 2012-02-03 18:00:37 UTC (rev 1411) +++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/query/FacetTopicCountComparator.java 2012-02-03 18:08:40 UTC (rev 1412) @@ -55,7 +55,7 @@ public int compare(FacetTopic o1, FacetTopic o2) { int thisVal = o1.getCount(); int anotherVal = o2.getCount(); - // code recupere de Integer.compareTo - return (thisVal<anotherVal ? -1 : (thisVal==anotherVal ? 0 : 1)); + // code recupere de Integer.compareTo (mais inverse pour les 1/-1) + return (thisVal<anotherVal ? 1 : (thisVal==anotherVal ? 0 : -1)); } } Modified: trunk/wikitty-api/src/main/java/org/nuiton/wikitty/storage/WikittySearchEngineInMemory.java =================================================================== --- trunk/wikitty-api/src/main/java/org/nuiton/wikitty/storage/WikittySearchEngineInMemory.java 2012-02-03 18:00:37 UTC (rev 1411) +++ trunk/wikitty-api/src/main/java/org/nuiton/wikitty/storage/WikittySearchEngineInMemory.java 2012-02-03 18:08:40 UTC (rev 1412) @@ -191,8 +191,10 @@ for (org.nuiton.wikitty.entities.Element e : query.getFacetField()) { String fqf = e.getValue(); Object value = w.getFqField(fqf); - topic.get(fqf).add(value); - result = true; + if (value != null) { + topic.get(fqf).add(value); + result = true; + } } // create facet query @@ -203,6 +205,7 @@ facetName = q.getCondition().toString(); } topic.get(facetName).add(facetName); + result = true; } } @@ -380,35 +383,6 @@ } }; - static private Predicate NotEqualsPredicate = new Predicate() { - public boolean check(FieldType type, Collection values, Collection expected) { - boolean result = true; - if (values != null && expected.size() > 0) { - // gestion des type STRING differement car il peut y avoir des '*' - if (type != null && type.getType() == WikittyTypes.STRING) { - Iterator i = expected.iterator(); - String exp = String.valueOf(i.next()); - for (Object fieldValue : values) { - String val = String.valueOf(fieldValue); - result = !matchString(val, exp, false); - if (!result) { - // si une des valeurs correspond, on retourne true - break; - } - } - } else { - expected = CollectionUtils.subtract(expected, values); - // si lorsqu'on retire tous les elements en commun avec la valeur - // du champs il ne reste plus rien, c'est que le equals est - // vrai et donc le not equals est faux - result = !expected.isEmpty(); - } - } - return result; - - } - }; - static private Predicate EqualsIgnoreCaseAndAccentPredicate = new Predicate() { public boolean check(FieldType type, Collection values, Collection expected) { boolean result = false; @@ -438,35 +412,6 @@ } }; - static private Predicate NotEqualsIgnoreCaseAndAccentPredicate = new Predicate() { - public boolean check(FieldType type, Collection values, Collection expected) { - boolean result = true; - if (values != null && expected.size() > 0) { - // gestion des type STRING differement car il peut y avoir des '*' - if (type != null && type.getType() == WikittyTypes.STRING) { - Iterator i = expected.iterator(); - String exp = String.valueOf(i.next()); - for (Object fieldValue : values) { - String val = String.valueOf(fieldValue); - result = !matchString(val, exp, true); - if (!result) { - // si une des valeurs correspond, on retourne true - break; - } - } - } else { - expected = CollectionUtils.subtract(expected, values); - // si lorsqu'on retire tous les elements en commun avec la valeur - // du champs il ne reste plus rien, c'est que le equals est - // vrai et donc le not equals est faux - result = !expected.isEmpty(); - } - } - return result; - - } - }; - static private Predicate GreaterPredicate = new Predicate() { public boolean check(FieldType type, Collection values, Collection expected) { boolean result = false; @@ -607,27 +552,6 @@ } }; - static private Predicate UnlikePredicate = new Predicate() { - public boolean check(FieldType type, Collection values, Collection expected) { - boolean result = false; - - if (values != null && expected.size() > 0) { - // si on a pas une valeur, c'est pas bon :( - Iterator i = expected.iterator(); - String exp = String.valueOf(i.next()); - for (Object fieldValue : values) { - String val = String.valueOf(fieldValue); - result = !matchString(val, exp, true); - if (result) { - // si une des valeurs correspond, on retourne true - break; - } - } - } - return result; - } - }; - static private Predicate NullPredicate = new Predicate() { public boolean check(FieldType type, Collection values, Collection expected) { boolean result = values == null || values.contains(null); @@ -654,7 +578,7 @@ * @return true if sub match s */ static private boolean matchString(String s, String sub, boolean ignoreCaseAndAccent) { - boolean result = false; + boolean result; if (sub.startsWith("*") && sub.endsWith("*")) { sub = StringUtils.substring(sub, 1, -1); if (ignoreCaseAndAccent) { @@ -757,17 +681,17 @@ * * @return une nouvelle collection avec les elements dans le bon type */ - protected Collection convert(FieldType type, Object o) { - Collection result; + protected Collection<Object> convert(FieldType type, Object o) { + Collection<Object> result; try { if (o instanceof Collection) { // order of collection must be maintained, for that use LinkedHashSet if (type == null) { // if type is null don't change type (in case of id or extension // or when we know object is already in right type) - result = new LinkedHashSet((Collection)o); + result = new LinkedHashSet<Object>((Collection<Object>)o); } else { - result = new LinkedHashSet(); + result = new LinkedHashSet<Object>(); for (Object v : (Collection)o) { result.add(type.getContainedValidObject(v)); } @@ -812,7 +736,7 @@ if (contained != null) { // si on a reussi a convertir dans le bon type on fait la verif Collection values; - values = (Collection)fieldValues.get(fqf); + values = fieldValues.get(fqf); result = predicate.check(type, values, contained); if (result) { @@ -1094,10 +1018,10 @@ boolean result = false; if (o.isIgnoreCaseAndAccent()) { - result = check(NotEqualsIgnoreCaseAndAccentPredicate, o.getElement(), + result = !check(EqualsIgnoreCaseAndAccentPredicate, o.getElement(), evalConditionValue(o.getValue())); } else { - result = check(NotEqualsPredicate, o.getElement(), + result = !check(EqualsPredicate, o.getElement(), evalConditionValue(o.getValue())); } @@ -1225,7 +1149,7 @@ public boolean visitEnter(Unlike o) { boolean result = false; - result = check(UnlikePredicate, o.getElement(), + result = !check(LikePredicate, o.getElement(), evalConditionValue(o.getValue())); evalStack.push(result);