From kmorin@users.nuiton.org Tue Jan  5 10:32:26 2010
From: kmorin@users.nuiton.org
To: sandbox-commits@list.nuiton.org
Subject: [Sandbox-commits] r343 - in wikengo_core-wikitty:
	wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty
	wikengo_core-wikitty-api/src/main/java/org/sharengo/wikitty/search
	wikengo_core-wikitty-jdbc-impl/src/main/java/org/sharengo/wikitty/jdbc
	wikengo_core-wikitty-solr-impl/src/main/java/org/sharengo/wikitty/solr
Date: Tue, 05 Jan 2010 10:32:25 +0100
Message-ID: <20100105093225.D271D15DAD@nuiton.codelutin.com>
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="===============3889691786016338333=="

--===============3889691786016338333==
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable

Author: kmorin
Date: 2010-01-05 10:32:25 +0100 (Tue, 05 Jan 2010)
New Revision: 343

Modified:
   wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/w=
ikitty/AbstractWikittyService.java
   wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/w=
ikitty/WikittyExtensionStorage.java
   wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/w=
ikitty/WikittyServiceInMemory.java
   wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/w=
ikitty/search/Element.java
   wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/w=
ikitty/search/Search.java
   wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/shar=
engo/wikitty/jdbc/WikittyExtensionStorageJDBC.java
   wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/shar=
engo/wikitty/jdbc/WikittyStorageJDBC.java
   wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/src/main/java/org/shar=
engo/wikitty/solr/Restriction2Solr.java
   wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/src/main/java/org/shar=
engo/wikitty/solr/WikittySearchEngineSolr.java
Log:
- don't remember what I did before holydays... should have commit before leav=
ing but forgot...

Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sha=
rengo/wikitty/AbstractWikittyService.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/=
wikitty/AbstractWikittyService.java	2009-12-24 13:33:17 UTC (rev 342)
+++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/=
wikitty/AbstractWikittyService.java	2010-01-05 09:32:25 UTC (rev 343)
@@ -180,7 +180,7 @@
      * @return
      */
     public WikittyExtension restoreExtension(String id) {
-        WikittyExtension result =3D getExtensionStorage().restore(id);
+        WikittyExtension result =3D getExtensionStorage().restore(WikittyExt=
ension.computeName(id), WikittyExtension.computeVersion(id));
         return result;
     }
=20

Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sha=
rengo/wikitty/WikittyExtensionStorage.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/=
wikitty/WikittyExtensionStorage.java	2009-12-24 13:33:17 UTC (rev 342)
+++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/=
wikitty/WikittyExtensionStorage.java	2010-01-05 09:32:25 UTC (rev 343)
@@ -77,10 +77,12 @@
=20
     /**
      * Restore one extension from storage, if not found an exception is throw
-     * @param id extension id to restore
+     * @param name extension name to restore
+     * @param version extension version to restore
      * @return
      */
-    public WikittyExtension restore(String id) throws WikittyException;
+    WikittyExtension restore(String name, String version)
+            throws WikittyException;
=20
     /**
      * Command update

Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sha=
rengo/wikitty/WikittyServiceInMemory.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/=
wikitty/WikittyServiceInMemory.java	2009-12-24 13:33:17 UTC (rev 342)
+++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/=
wikitty/WikittyServiceInMemory.java	2010-01-05 09:32:25 UTC (rev 343)
@@ -209,7 +209,8 @@
             return null;  //To change body of implemented methods use File |=
 Settings | File Templates.
         }
=20
-        public WikittyExtension restore(String id) throws WikittyException {
+        public WikittyExtension restore(String name, String version) throws =
WikittyException {
+            String id =3D WikittyExtension.computeId(name, version);
             WikittyExtension result =3D extensions.get(id);
             if (result =3D=3D null) {
                 throw new WikittyException(String.format("No extension with =
id '%s'", id));
@@ -356,10 +357,14 @@
             throw new UnsupportedOperationException("Not supported yet.");
         }
=20
-        public Map<String, Integer> findAllChildren(Wikitty w) {
+        public Integer findNodeCount(Wikitty w) {
             throw new UnsupportedOperationException("Not supported yet.");
         }
=20
+        public Map<String, Integer> findAllChildrenCount(Wikitty w) {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
     }
=20
     /**

Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sha=
rengo/wikitty/search/Element.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/=
wikitty/search/Element.java	2009-12-24 13:33:17 UTC (rev 342)
+++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/=
wikitty/search/Element.java	2010-01-05 09:32:25 UTC (rev 343)
@@ -16,8 +16,6 @@
  *##%*/
 package org.sharengo.wikitty.search;
=20
-import org.sharengo.wikitty.FieldType;
-
 import java.io.Serializable;
=20
 /**
@@ -32,25 +30,28 @@
     /** Represent a element on id */
     public static String ELT_ID =3D "elt_id";
=20
-	// serialVersionUID is used for serialization.
-	private static final long serialVersionUID =3D 1L;
+    /** Represent type to search an element */
+    public static enum ElementType {NUMERIC, STRING, WIKITTY, BOOLEAN, TEXT,=
 DATE};
=20
-	protected String name;
+    // serialVersionUID is used for serialization.
+    private static final long serialVersionUID =3D 1L;
=20
-	public Element() {
-		super();
-	}
+    protected String name;
=20
+    public Element() {
+        super();
+    }
+
     public Element(String name) {
-        this.name =3D name.replace(" ", FieldType.WORD_SEPARATOR);
+        this.name =3D name;
     }
=20
-	public String getName() {
-		return name;
-	}
+    public String getName() {
+        return name;
+    }
=20
-	public void setName(String name) {
-		this.name =3D name.replace(" ", FieldType.WORD_SEPARATOR);
-	}
+    public void setName(String name) {
+        this.name =3D name;
+    }
=20
 }

Modified: wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sha=
rengo/wikitty/search/Search.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/=
wikitty/search/Search.java	2009-12-24 13:33:17 UTC (rev 342)
+++ wikengo_core-wikitty/wikengo_core-wikitty-api/src/main/java/org/sharengo/=
wikitty/search/Search.java	2010-01-05 09:32:25 UTC (rev 343)
@@ -13,23 +13,29 @@
=20
 /**
  * Helper to create a criteria with a restriction
+ *
+ * Element :
+ * <extensionName>.<fieldName>[.<fieldType>] : search on an extension and fi=
eld with specific type (optionnal)
+ * Criteria.ALL_EXTENSIONS.<fieldName>.<fieldType> : search on all extension=
 and field name with specific type
+ *
+ * <fieldType> specify seach on field as NUMERIC, STRING, WIKITTY, BOOLEAN, =
TEXT
  */
 public class Search {
=20
     static private Log log =3D LogFactory.getLog(Search.class);
=20
-	public enum KIND {
-		AND, OR
-	}
-=09
-	KIND kind =3D KIND.AND;
-	List<Restriction> restrictions;
+    public enum KIND {
+        AND, OR, NOT
+    }
+
+    KIND kind =3D KIND.AND;
+    List<Restriction> restrictions;
     List<Search> subSearchs;
-=09
-	public Search() {
-		restrictions =3D new ArrayList<Restriction>();
+
+    public Search() {
+        restrictions =3D new ArrayList<Restriction>();
         subSearchs =3D new ArrayList<Search>();
-	}
+    }
=20
     /**
      * Create Search query with field in wikitty argument
@@ -42,7 +48,7 @@
         result.kind =3D KIND.AND;
         // result object must have same extension that wikitty example
         for (String extName : wikitty.getExtensionNames()) {
-			result.eq(Element.ELT_EXTENSION, extName);
+            result.eq(Element.ELT_EXTENSION, extName);
         }
=20
         for (String fqfieldName : wikitty.fieldNames()) {
@@ -65,133 +71,150 @@
         return result;
     }
=20
-	public static Search query() {
-		Search search =3D new Search();
-		search.kind =3D KIND.AND;
-		return search;
-	}
+    public static Search query() {
+        Search search =3D new Search();
+        search.kind =3D KIND.AND;
+        return search;
+    }
=20
     public static Search query(KIND kind) {
-		Search search =3D new Search();
-		search.kind =3D kind;
-		return search;
-	}
-=09
+        Search search =3D new Search();
+        search.kind =3D kind;
+        return search;
+    }
+
     /**
      * Create new query on existant criteria to add new constraint to exista=
nt
      * criteria
      * @param criteria
      * @return
      */
-	public static Search query(Criteria criteria) {
-		Search search =3D query();
+    public static Search query(Criteria criteria) {
+        Search search =3D query();
         search.restrictions.add(criteria.getRestriction());
-		return search;
-	}
-=09
-	private static Element elt(String element) {
-		Element elm =3D new Element();
-		elm.setName(element);
-		return elm;
-	}
-=09
-	protected Search handle( Restriction dto ) {
-		restrictions.add( dto );
-		return this;
-	}
+        return search;
+    }
=20
-	public Search contains(String element, Collection<String> values) {
-		return handle( RestrictionHelper.contains(elt(element),
+    private static Element elt(String element) {
+        Element elm =3D new Element();
+        elm.setName(element);
+        return elm;
+    }
+
+    protected Search handle( Restriction dto ) {
+        restrictions.add( dto );
+        return this;
+    }
+
+    public Search contains(String element, Collection<String> values) {
+        return handle( RestrictionHelper.contains(elt(element),
                 new ArrayList<String>(values)) );
-	}
+    }
=20
-	public Search eq(String element, String value) {
-		return handle( RestrictionHelper.eq(elt(element), value) );
-	}
-=09
-	public Search neq(String element, String value) {
-		return handle( RestrictionHelper.neq(elt(element), value) );
-	}
+    public Search eq(String element, String value) {
+        return handle( RestrictionHelper.eq(elt(element), value) );
+    }
=20
-	public Search gt(String element, String value) {
-		return handle( RestrictionHelper.great(elt(element), value) );
-	}
-=09
-	public Search ge(String element, String value) {
-		return handle( RestrictionHelper.greatEq(elt(element), value) );
-	}
-=09
-	public Search lt(String element, String value) {
-		return handle( RestrictionHelper.less(elt(element), value) );
-	}
-=09
-	public Search le(String element, String value) {
-		return handle( RestrictionHelper.lessEq(elt(element), value) );
-	}
-=09
-	public Search bw(String element, String lowerValue, String upperValue) {
-		return handle( RestrictionHelper.between(elt(element), lowerValue, upperVa=
lue) );
-	}
-=09
-        public Search sw(String element, String value) {
-		return handle( RestrictionHelper.start(elt(element), value) );
-	}
+    public Search neq(String element, String value) {
+        return handle( RestrictionHelper.neq(elt(element), value) );
+    }
=20
-	public Search nsw(String element, String value) {
-		return handle( RestrictionHelper.not(
+    public Search gt(String element, String value) {
+        return handle( RestrictionHelper.great(elt(element), value) );
+    }
+
+    public Search ge(String element, String value) {
+        return handle( RestrictionHelper.greatEq(elt(element), value) );
+    }
+
+    public Search lt(String element, String value) {
+        return handle( RestrictionHelper.less(elt(element), value) );
+    }
+
+    public Search le(String element, String value) {
+        return handle( RestrictionHelper.lessEq(elt(element), value) );
+    }
+
+    public Search bw(String element, String lowerValue, String upperValue) {
+        return handle( RestrictionHelper.between(elt(element), lowerValue, u=
pperValue) );
+    }
+
+    public Search sw(String element, String value) {
+        return handle( RestrictionHelper.start(elt(element), value) );
+    }
+
+    public Search nsw(String element, String value) {
+        return handle( RestrictionHelper.not(
                         RestrictionHelper.start(elt(element), value)) );
-	}
-=09
-	public Search ew(String element, String value) {
-		return handle( RestrictionHelper.end(elt(element), value) );
-	}
+    }
=20
+    public Search ew(String element, String value) {
+        return handle( RestrictionHelper.end(elt(element), value) );
+    }
+
     public Search notew(String element, String value) {
-		return handle( RestrictionHelper.not(
+        return handle( RestrictionHelper.not(
                         RestrictionHelper.end(elt(element), value)) );
-	}
+    }
=20
     public Search keyword(String value) {
         return handle(RestrictionHelper.keyword(value));
     }
=20
-	public Search or() {
-		Search search =3D Search.query(KIND.OR);
+    public Search not() {
+        Search not =3D Search.query(KIND.NOT);
+        subSearchs.add(not);
+
+        Search search =3D Search.query(kind);
+        not.subSearchs.add(search);
+
+        return search;
+    }
+
+    public Search or() {
+        Search search =3D Search.query(KIND.OR);
         subSearchs.add(search);
-		return search;
-	}
-=09
-	public Search and() {
-		Search search =3D Search.query(KIND.AND);
+        return search;
+    }
+
+    public Search and() {
+        Search search =3D Search.query(KIND.AND);
         subSearchs.add(search);
-		return search;
-	}
+        return search;
+    }
=20
-	public Search associated(String foreignFieldName) {
-		Search search =3D new SubSearch( foreignFieldName, this );
-		return search;
-	}
-=09
+    public Search associated(String foreignFieldName) {
+        Search search =3D new SubSearch( foreignFieldName, this );
+        return search;
+    }
+
     /**
      * return unnamed criteria
      * @return new criteria
      */
-	public Criteria criteria(String name) {
-		Criteria criteria =3D new Criteria(name);
-		Restriction result =3D getRestrictions();
+    public Criteria criteria(String name) {
+        Criteria criteria =3D new Criteria(name);
+        Restriction result =3D getRestrictions();
         criteria.setRestriction(result);
-		return criteria;
-	}
-=09
+        return criteria;
+    }
+
     protected Restriction getRestrictions() throws UnsupportedOperationExcep=
tion {
         Restriction result;
         if (restrictions.isEmpty() && subSearchs.isEmpty()) {
             result =3D RestrictionHelper.rFalse();
+
         } else if (restrictions.size() =3D=3D 1 && subSearchs.isEmpty()) {
             result =3D restrictions.remove(0);
+
         } else if (subSearchs.size() =3D=3D 1 && restrictions.isEmpty()) {
             Search subSearch =3D subSearchs.get(0);
             result =3D subSearch.getRestrictions();
+
+            if(kind =3D=3D KIND.NOT) {
+                result =3D RestrictionHelper.not(result);
+            }
+
         } else {
             List<Restriction> allRestrictions =3D new ArrayList<Restriction>=
(restrictions);
             for (Search subSearch : subSearchs) {
@@ -214,10 +237,9 @@
=20
     /**
      * return criteria with name
-     * @param name name of criteria
      * @return new criteria
      */
-	public Criteria criteria() {
-		return criteria(null);
-	}
-}
+    public Criteria criteria() {
+        return criteria(null);
+    }
+}
\ No newline at end of file

Modified: wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/o=
rg/sharengo/wikitty/jdbc/WikittyExtensionStorageJDBC.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sha=
rengo/wikitty/jdbc/WikittyExtensionStorageJDBC.java	2009-12-24 13:33:17 UTC (=
rev 342)
+++ wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sha=
rengo/wikitty/jdbc/WikittyExtensionStorageJDBC.java	2010-01-05 09:32:25 UTC (=
rev 343)
@@ -278,7 +278,7 @@
                     String extName =3D adminResultSet.getString(COL_NAME);
                     String extVersion =3D getLastVersion(extName);
                     String extId =3D WikittyExtension.computeId(extName, ext=
Version);
-                    result.add(restore(extId));
+                    result.add(restore(WikittyExtension.computeName(extId), =
WikittyExtension.computeVersion(extId)));
                 }
             } else {
                 adminResultSet =3D statement.executeQuery(
@@ -287,7 +287,7 @@
                 adminResultSet.beforeFirst();
                 while (adminResultSet.next()) {
                     String extId =3D adminResultSet.getString(COL_ID);
-                    result.add(restore(extId));
+                    result.add(restore(WikittyExtension.computeName(extId), =
WikittyExtension.computeVersion(extId)));
                 }
             }
             closeConnection(con);
@@ -340,7 +340,8 @@
     }
=20
     @Override
-    public WikittyExtension restore(String id) throws WikittyException {
+    public WikittyExtension restore(String name, String version) throws Wiki=
ttyException {
+        String id =3D WikittyExtension.computeId(name, version);
         WikittyExtension result =3D extensionCache.get(id);
         if (result =3D=3D null) {
             Connection con =3D null;

Modified: wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/o=
rg/sharengo/wikitty/jdbc/WikittyStorageJDBC.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sha=
rengo/wikitty/jdbc/WikittyStorageJDBC.java	2009-12-24 13:33:17 UTC (rev 342)
+++ wikengo_core-wikitty/wikengo_core-wikitty-jdbc-impl/src/main/java/org/sha=
rengo/wikitty/jdbc/WikittyStorageJDBC.java	2010-01-05 09:32:25 UTC (rev 343)
@@ -593,7 +593,7 @@
         result.setVersion(version);
         if (extensionList !=3D null && !"".equals(extensionList)) {
             for (String ext : extensionList.split(",")) {
-                WikittyExtension extension =3D extensionStorage.restore(ext);
+                WikittyExtension extension =3D extensionStorage.restore(Wiki=
ttyExtension.computeName(ext), WikittyExtension.computeVersion(ext));
                 result.addExtension(extension);
             }
         }

Modified: wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/src/main/java/o=
rg/sharengo/wikitty/solr/Restriction2Solr.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/src/main/java/org/sha=
rengo/wikitty/solr/Restriction2Solr.java	2009-12-24 13:33:17 UTC (rev 342)
+++ wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/src/main/java/org/sha=
rengo/wikitty/solr/Restriction2Solr.java	2010-01-05 09:32:25 UTC (rev 343)
@@ -8,6 +8,7 @@
 import org.apache.solr.client.solrj.SolrServer;
 import org.apache.solr.client.solrj.SolrServerException;
 import org.apache.solr.client.solrj.response.QueryResponse;
+import org.apache.solr.client.solrj.util.ClientUtils;
 import org.apache.solr.common.SolrDocument;
 import org.apache.solr.common.SolrDocumentList;
 import org.sharengo.wikitty.WikittyException;
@@ -34,21 +35,16 @@
 /**
  * @author "Nicolas Chapurlat" <nicolas.chapurlat@logica.com>
  * @author "Guillaume Dufr=C3=AAne" <dufrene@argia.fr>
- *=20
+ *
  * This class is used to parse Restriction to create lucene request on
  * content. Every operators describe in RestrictionName is handle. Parsing m=
ay
  * throw exception when restriction parameters are incorrect.
  */
 public class Restriction2Solr {
-=09
-	private static final int MAX_SUBQUERY_RESULT =3D 100;
=20
-    /** use to permit client to modify fieldname during query generation */
-    static public interface FieldModifier {
-        public String convertToSolr(String fieldname);
-        public String convertToField(String solrName);
-    }
-    final static protected FieldModifier dummyFieldModifier =3D new FieldMod=
ifier() {
+    private static final int MAX_SUBQUERY_RESULT =3D 100;
+
+    final static protected WikittySearchEngineSolr.FieldModifier dummyFieldM=
odifier =3D new WikittySearchEngineSolr.FieldModifier() {
         public String convertToSolr(String fieldname) {
             return fieldname;
         }
@@ -57,331 +53,323 @@
         }
     };
=20
-    protected FieldModifier fieldModifer;
+    protected WikittySearchEngineSolr.FieldModifier fieldModifer;
=20
     public Restriction2Solr() {
         this(dummyFieldModifier);
     }
=20
-    public Restriction2Solr(FieldModifier fieldModifer) {
+    public Restriction2Solr(WikittySearchEngineSolr.FieldModifier fieldModif=
er) {
         this.fieldModifer =3D fieldModifer;
     }
=20
     public String toSolr(Restriction restriction) {
-    	return toSolr(restriction, null);
+        return toSolr(restriction, null);
     }
-   =20
-	public String toSolr(Restriction restriction, SolrServer solr)
-			throws WikittyException {
-		// ParameterValidator.checkNullParameter(restriction, "restriction");
-		switch (restriction.getName()) {
-		case TRUE:
-			return true2solr();
-		case FALSE:
-			return false2solr();
-		case NOT:
-			Not not =3D (Not) restriction;
-			return not2solr(not);
-		case AND:
-			And and =3D (And) restriction;
-			return and2solr(and);
-		case OR:
-			Or or =3D (Or) restriction;
-			return or2solr(or);
-		case EQUALS:
-			Equals eq =3D (Equals) restriction;
-			return eq2solr(eq);
-		case NOT_EQUALS:
-			NotEquals neq =3D (NotEquals) restriction;
-			return neq2solr(neq);
-		case LESS:
-			Less less =3D (Less) restriction;
-			return less2solr(less);
-		case LESS_OR_EQUAL:
-			LessOrEqual lessEq =3D (LessOrEqual) restriction;
-			return lessEq2solr(lessEq);
-		case GREATER:
-			Greater great =3D (Greater) restriction;
-			return great2solr(great);
-		case GREATER_OR_EQUAL:
-			GreaterOrEqual greatEq =3D (GreaterOrEqual) restriction;
-			return greatEq2solr(greatEq);
-		case BETWEEN:
-			Between between =3D (Between) restriction;
-			return between2solr(between);
-		case CONTAINS:
-			Contains contains =3D (Contains) restriction;
-			return contains2solr(contains);
-		case IN:
-			In in =3D (In) restriction;
-			return in2solr(in);
-		case STARTS_WITH:
-			StartsWith start =3D (StartsWith) restriction;
-			return start2solr(start);
-		case ENDS_WITH:
-			EndsWith end =3D (EndsWith) restriction;
-			return end2solr(end);
-		case ASSOCIATED:
-			AssociatedRestriction associated =3D (AssociatedRestriction) restriction;
-			return associated2solr(associated, solr);
+
+    public String toSolr(Restriction restriction, SolrServer solr)
+            throws WikittyException {
+        // ParameterValidator.checkNullParameter(restriction, "restriction");
+        switch (restriction.getName()) {
+        case TRUE:
+            return true2solr();
+        case FALSE:
+            return false2solr();
+        case NOT:
+            Not not =3D (Not) restriction;
+            return not2solr(not);
+        case AND:
+            And and =3D (And) restriction;
+            return and2solr(and);
+        case OR:
+            Or or =3D (Or) restriction;
+            return or2solr(or);
+        case EQUALS:
+            Equals eq =3D (Equals) restriction;
+            return eq2solr(eq);
+        case NOT_EQUALS:
+            NotEquals neq =3D (NotEquals) restriction;
+            return neq2solr(neq);
+        case LESS:
+            Less less =3D (Less) restriction;
+            return less2solr(less);
+        case LESS_OR_EQUAL:
+            LessOrEqual lessEq =3D (LessOrEqual) restriction;
+            return lessEq2solr(lessEq);
+        case GREATER:
+            Greater great =3D (Greater) restriction;
+            return great2solr(great);
+        case GREATER_OR_EQUAL:
+            GreaterOrEqual greatEq =3D (GreaterOrEqual) restriction;
+            return greatEq2solr(greatEq);
+        case BETWEEN:
+            Between between =3D (Between) restriction;
+            return between2solr(between);
+        case CONTAINS:
+            Contains contains =3D (Contains) restriction;
+            return contains2solr(contains);
+        case IN:
+            In in =3D (In) restriction;
+            return in2solr(in);
+        case STARTS_WITH:
+            StartsWith start =3D (StartsWith) restriction;
+            return start2solr(start);
+        case ENDS_WITH:
+            EndsWith end =3D (EndsWith) restriction;
+            return end2solr(end);
+        case ASSOCIATED:
+            AssociatedRestriction associated =3D (AssociatedRestriction) res=
triction;
+            return associated2solr(associated, solr);
         case KEYWORD:
             Keyword keyword =3D (Keyword) restriction;
             return keyword2solr(keyword);
-		default:
-			throw new WikittyException("this kind of restriction is not supported : "
-							+ restriction.getName().toString());
-		}
-	}
+        default:
+            throw new WikittyException("this kind of restriction is not supp=
orted : "
+                            + restriction.getName().toString());
+        }
+    }
=20
-	private String in2solr(In in) {
-		boolean first =3D true;
-		String result =3D in.getElement().getName() + ":[";
-		for( String value : in.getValue() ) {
-			if ( !first ) { result +=3D ", "; first =3D false; }
-			result +=3D value;
-		}
-		result +=3D"]";
-		return result;
-	}
+    private String in2solr(In in) {
+        boolean first =3D true;
+        String result =3D in.getElement().getName() + ":[";
+        for( String value : in.getValue() ) {
+            if ( !first ) { result +=3D ", "; first =3D false; }
+            result +=3D value;
+        }
+        result +=3D"]";
+        return result;
+    }
=20
-	private String associated2solr(AssociatedRestriction associated, SolrServer=
 solr) throws WikittyException {
-		String subQuery =3D toSolr( associated.getRestriction() );
-		SolrQuery query =3D new SolrQuery(WikittySearchEngineSolr.SOLR_QUERY_PARSE=
R + subQuery);
+    private String associated2solr(AssociatedRestriction associated, SolrSer=
ver solr) throws WikittyException {
+        String subQuery =3D toSolr( associated.getRestriction() );
+        SolrQuery query =3D new SolrQuery(WikittySearchEngineSolr.SOLR_QUERY=
_PARSER + subQuery);
         query.setRows(MAX_SUBQUERY_RESULT);
         QueryResponse resp =3D null;
         try {
-			resp =3D solr.query(query);
-		} catch (SolrServerException e) {
-			throw new WikittyException("Unable to execute associative query on " + as=
sociated.getElement().getName(), e);
-		}
+            resp =3D solr.query(query);
+        } catch (SolrServerException e) {
+            throw new WikittyException("Unable to execute associative query =
on " + associated.getElement().getName(), e);
+        }
         SolrDocumentList solrResults =3D resp.getResults();
-       =20
+
         Restriction generatedRestriction =3D null;
         long size =3D solrResults.size();
         if ( size =3D=3D 0 ) {
-        	throw new WikittyException("Associated " + associated.getElement().=
getName() + " do not retrieved any result");
+            throw new WikittyException("Associated " + associated.getElement=
().getName() + " do not retrieved any result");
         }
         if ( size =3D=3D 1 ) {
-        	generatedRestriction =3D RestrictionHelper.eq( associated.getElemen=
t(), (String) solrResults.get(0).getFieldValue(WikittySearchEngineSolr.SOLR_I=
D) );
+            generatedRestriction =3D RestrictionHelper.eq( associated.getEle=
ment(), (String) solrResults.get(0).getFieldValue(WikittySearchEngineSolr.SOL=
R_ID) );
         } else {
-	        List<String> ids =3D new ArrayList<String>(solrResults.size());
-	        for (SolrDocument doc : solrResults) {
-	            String id =3D (String) doc.getFieldValue(WikittySearchEngineSol=
r.SOLR_ID);
-	            ids.add(id);
-	        }
-			generatedRestriction =3D new In(associated.getElement(), ids);
+            List<String> ids =3D new ArrayList<String>(solrResults.size());
+            for (SolrDocument doc : solrResults) {
+                String id =3D (String) doc.getFieldValue(WikittySearchEngine=
Solr.SOLR_ID);
+                ids.add(id);
+            }
+            generatedRestriction =3D new In(associated.getElement(), ids);
         }
         Restriction parent =3D associated.getParentRestrictionDto();
         And and;
         if ( parent instanceof And ) {
-        	and =3D (And) parent;
-        	and.getRestrictions().add( generatedRestriction );
+            and =3D (And) parent;
+            and.getRestrictions().add( generatedRestriction );
         } else {
-        	and =3D RestrictionHelper.and( Arrays.asList(new Restriction[]{ ass=
ociated.getParentRestrictionDto(), generatedRestriction }) );
+            and =3D RestrictionHelper.and( Arrays.asList(new Restriction[]{ =
associated.getParentRestrictionDto(), generatedRestriction }) );
         }
-		return toSolr(and);
-	}
+        return toSolr(and);
+    }
=20
-	private String not2solr(Not not) throws WikittyException {
-		if (not.getRestriction() =3D=3D null) {
-			throw new WikittyException( "not.restriction" );
-		}
-		return "( *:* - " + toSolr(not.getRestriction()) + " )";
-	}
+    private String not2solr(Not not) throws WikittyException {
+        if (not.getRestriction() =3D=3D null) {
+            throw new WikittyException( "not.restriction" );
+        }
+        return "( *:* - " + toSolr(not.getRestriction()) + " )";
+    }
=20
-	private String and2solr(And and) throws WikittyException {
-		if (and.getRestrictions() =3D=3D null) {
-			throw new WikittyException( "and.restrictions is null" );
-		}
-		if (and.getRestrictions().size() < 2) {
-			throw new WikittyException(	"AND is an operator that handle 2 operand at =
least");
-		}
-		boolean first =3D true;
-		StringBuffer result =3D new StringBuffer();
-		for (Restriction restriction : and.getRestrictions()) {
-			if (first) {
-				result.append("( ").append(toSolr(restriction));
-				first =3D false;
-			} else {
-				result.append(" AND ").append(toSolr(restriction));
-			}
-		}
-		return result.append(" )").toString();
-	}
+    private String and2solr(And and) throws WikittyException {
+        if (and.getRestrictions() =3D=3D null) {
+            throw new WikittyException( "and.restrictions is null" );
+        }
+        if (and.getRestrictions().size() < 2) {
+            throw new WikittyException(    "AND is an operator that handle 2=
 operand at least");
+        }
+        boolean first =3D true;
+        StringBuffer result =3D new StringBuffer();
+        for (Restriction restriction : and.getRestrictions()) {
+            if (first) {
+                result.append("( ").append(toSolr(restriction));
+                first =3D false;
+            } else {
+                result.append(" AND ").append(toSolr(restriction));
+            }
+        }
+        return result.append(" )").toString();
+    }
=20
-	private String or2solr(Or or) throws WikittyException {
-		if (or.getRestrictions() =3D=3D null) {
-			throw new WikittyException("or.restrictions is null");
-		}
-		if (or.getRestrictions().size() < 2) {
-			throw new WikittyException("OR is an operator that handle 2 operand at le=
ast");
-		}
-		boolean first =3D true;
-		StringBuffer result =3D new StringBuffer();
-		for (Restriction restriction : or.getRestrictions()) {
-			if (first) {
-				result.append("( ");
-				first =3D false;
-			} else {
-				result.append(" OR ");
-			}
-			result.append(toSolr(restriction));
-		}
-		return result.append(" )").toString();
-	}
+    private String or2solr(Or or) throws WikittyException {
+        if (or.getRestrictions() =3D=3D null) {
+            throw new WikittyException("or.restrictions is null");
+        }
+        if (or.getRestrictions().size() < 2) {
+            throw new WikittyException("OR is an operator that handle 2 oper=
and at least");
+        }
+        boolean first =3D true;
+        StringBuffer result =3D new StringBuffer();
+        for (Restriction restriction : or.getRestrictions()) {
+            if (first) {
+                result.append("( ");
+                first =3D false;
+            } else {
+                result.append(" OR ");
+            }
+            result.append(toSolr(restriction));
+        }
+        return result.append(" )").toString();
+    }
=20
-	private String eq2solr(Equals eq) throws WikittyException {
-		return element2solr(eq.getElement()) + ":" + value2solr(eq.getValue());
-	}
+    private String eq2solr(Equals eq) throws WikittyException {
+        return element2solr(eq.getElement()) + ":" + value2solr(eq.getValue(=
));
+    }
=20
-	private String neq2solr(NotEquals neq)
-			throws WikittyException {
-		return "-" + element2solr(neq.getElement()) + ":"
-				+ value2solr(neq.getValue());
-	}
+    private String neq2solr(NotEquals neq)
+            throws WikittyException {
+        return "-" + element2solr(neq.getElement()) + ":"
+                + value2solr(neq.getValue());
+    }
=20
-	private String less2solr(Less less) throws WikittyException {
-		return element2solr(less.getElement()) + ":{* TO "
-				+ value2solr(less.getValue()) + "}";
-	}
+    private String less2solr(Less less) throws WikittyException {
+        return element2solr(less.getElement()) + ":{* TO "
+                + value2solr(less.getValue()) + "}";
+    }
=20
-	private String lessEq2solr(LessOrEqual lessEq)
-			throws WikittyException {
-		return element2solr(lessEq.getElement()) + ":[* TO "
-				+ value2solr(lessEq.getValue()) + "]";
-	}
+    private String lessEq2solr(LessOrEqual lessEq)
+            throws WikittyException {
+        return element2solr(lessEq.getElement()) + ":[* TO "
+                + value2solr(lessEq.getValue()) + "]";
+    }
=20
-	private String great2solr(Greater great)
-			throws WikittyException {
-		return element2solr(great.getElement()) + ":{"
-				+ value2solr(great.getValue()) + " TO *}";
-	}
+    private String great2solr(Greater great)
+            throws WikittyException {
+        return element2solr(great.getElement()) + ":{"
+                + value2solr(great.getValue()) + " TO *}";
+    }
=20
-	private String greatEq2solr(GreaterOrEqual greatEq)
-			throws WikittyException {
-		return element2solr(greatEq.getElement()) + ":["
-				+ value2solr(greatEq.getValue()) + " TO *]";
-	}
+    private String greatEq2solr(GreaterOrEqual greatEq)
+            throws WikittyException {
+        return element2solr(greatEq.getElement()) + ":["
+                + value2solr(greatEq.getValue()) + " TO *]";
+    }
=20
-	private String between2solr(Between between)
-			throws WikittyException {
-		if (between.getElement() =3D=3D null) {
-			throw new WikittyException("contains.element");
-		}
-		if (between.getMin() =3D=3D null) {
-			throw new WikittyException("contains.min");
-		}
-		if (between.getMax() =3D=3D null) {
-			throw new WikittyException("contains.max");
-		}
-		return element2solr(between.getElement()) + ":["
-				+ value2solr(between.getMin()) + " TO "
-				+ value2solr(between.getMax()) + "]";
-	}
+    private String between2solr(Between between)
+            throws WikittyException {
+        if (between.getElement() =3D=3D null) {
+            throw new WikittyException("contains.element");
+        }
+        if (between.getMin() =3D=3D null) {
+            throw new WikittyException("contains.min");
+        }
+        if (between.getMax() =3D=3D null) {
+            throw new WikittyException("contains.max");
+        }
+        return element2solr(between.getElement()) + ":["
+                + value2solr(between.getMin()) + " TO "
+                + value2solr(between.getMax()) + "]";
+    }
=20
-	private String contains2solr(Contains contains)
-			throws WikittyException {
-		if (contains.getElement() =3D=3D null) {
-			throw new WikittyException("contains.element");
-		}
-		if (contains.getValue() =3D=3D null) {
-			throw new WikittyException("contains.values");
-		}
-		if (contains.getValue().size() < 1) {
-			throw new WikittyException("CONTAINS is an operator that handle 1 operand=
 at least");
-		}
+    private String contains2solr(Contains contains)
+            throws WikittyException {
+        if (contains.getElement() =3D=3D null) {
+            throw new WikittyException("contains.element");
+        }
+        if (contains.getValue() =3D=3D null) {
+            throw new WikittyException("contains.values");
+        }
+        if (contains.getValue().size() < 1) {
+            throw new WikittyException("CONTAINS is an operator that handle =
1 operand at least");
+        }
=20
         String operand =3D "";
-		StringBuffer result =3D new StringBuffer();
+        StringBuffer result =3D new StringBuffer();
         result.append("(");
-		for (String value : contains.getValue()) {
+        for (String value : contains.getValue()) {
             result.append(operand);
-			result.append(element2solr(contains.getElement()))
-					.append(":").append(value2solr(value));
+            result.append(element2solr(contains.getElement()))
+                    .append(":").append(value2solr(value));
             operand =3D " OR ";
-		}
+        }
         result.append(")");
-		return result.toString();
-	}
+        return result.toString();
+    }
=20
-	private String start2solr(StartsWith start)
-			throws WikittyException {
-		return element2solr(start.getElement()) + ":"
-				+ value2solr(start.getValue(), true, false);
-	}
+    private String start2solr(StartsWith start)
+            throws WikittyException {
+        return element2solr(start.getElement()) + ":"
+                + value2solr(start.getValue(), true, false);
+    }
=20
-	private String end2solr(EndsWith end) {
-		return element2solr(end.getElement()) + ":"	+ value2solr(end.getValue());
-	}
+    private String end2solr(EndsWith end) {
+        return element2solr(end.getElement()) + ":"    + value2solr(end.getV=
alue());
+    }
=20
-	private String true2solr() {
-		return "( *:* )";
-	}
+    private String true2solr() {
+        return "( *:* )";
+    }
=20
-	private String false2solr() {
-		return "( *:* - *:* )";
-	}
+    private String false2solr() {
+        return "( *:* - *:* )";
+    }
=20
     private String keyword2solr(Keyword keyword) {
         return value2solr(keyword.getValue());
     }
=20
-	private String value2solr(String value) {
-		return value2solr(value, false, false);
-	}
+    private String value2solr(String value) {
+        return value2solr(value, false, false);
+    }
=20
-	private String value2solr(String value, boolean starOnEnd,
-			boolean revert) {
-		String result;
-		if (value !=3D null) {
-			if (value.equals("*")) {
-				return "*";
-			}
+    private String value2solr(String value, boolean starOnEnd,
+            boolean revert) {
+        String result;
+        if (value !=3D null) {
+            if (value.equals("*")) {
+                return "*";
+            }
=20
-			if (revert) {
-				result =3D Restriction2Solr.escapeValue(reverse(value));
-			} else {
-				result =3D Restriction2Solr.escapeValue(value);
-			}
-		} else {
-			result =3D "";
-		}
-		if (starOnEnd) {
-			result +=3D "*";
-		}
-		if (result.contains(" ")) {
-			result =3D "\"" + result + "\"";
-		}
-		return result;
-	}
-
-	private String element2solr(Element element) throws WikittyException {
-        String result =3D element.getName();
-        if(Element.ELT_EXTENSION.equals(result)) {
-            result =3D WikittySearchEngineSolr.SOLR_EXTENSIONS;
-        } else if(Element.ELT_ID.equals(result)) {
-            result =3D WikittySearchEngineSolr.SOLR_ID;
+            if (revert) {
+                result =3D Restriction2Solr.escapeValue(reverse(value));
+            } else {
+                result =3D Restriction2Solr.escapeValue(value);
+            }
         } else {
-            result =3D element.getName();
+            result =3D "";
         }
+        if (starOnEnd) {
+            result +=3D "*";
+        }
+        if (result.contains(" ")) {
+            result =3D "\"" + result + "\"";
+        }
+        return result;
+    }
+
+    private String element2solr(Element element) throws WikittyException {
+        String result =3D element.getName();
         result =3D fieldModifer.convertToSolr(result);
         return result;
-	}
+    }
=20
-	private static String escapeValue(String value) {
-		final String LUCENE_REPLACE_PATTERN =3D "\\+" + "|-" + "|&&" + "|\\|"
-				+ "|!" + "|\\(|\\)" + "|\\[|\\]" + "|\\{|\\}" + "|\"" + "|:";
-		return value.replaceAll(LUCENE_REPLACE_PATTERN, "\\\\$0");
-	}
+    private static String escapeValue(String value) {
+        final String LUCENE_REPLACE_PATTERN =3D "\\+" + "|-" + "|&&" + "|\\|"
+                + "|!" + "|\\(|\\)" + "|\\[|\\]" + "|\\{|\\}" + "|\"" + "|:";
+        return value.replaceAll(LUCENE_REPLACE_PATTERN, "\\\\$0");
+    }
=20
-	private String reverse(String source) {
-		int i, len =3D source.length();
-		StringBuffer dest =3D new StringBuffer(len);
+    private String reverse(String source) {
+        int i, len =3D source.length();
+        StringBuffer dest =3D new StringBuffer(len);
=20
-		for (i =3D (len - 1); i >=3D 0; i--) {
-			dest.append(source.charAt(i));
+        for (i =3D (len - 1); i >=3D 0; i--) {
+            dest.append(source.charAt(i));
         }
-		return dest.toString();
-	}
+        return dest.toString();
+    }
 }
-

Modified: wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/src/main/java/o=
rg/sharengo/wikitty/solr/WikittySearchEngineSolr.java
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/src/main/java/org/sha=
rengo/wikitty/solr/WikittySearchEngineSolr.java	2009-12-24 13:33:17 UTC (rev =
342)
+++ wikengo_core-wikitty/wikengo_core-wikitty-solr-impl/src/main/java/org/sha=
rengo/wikitty/solr/WikittySearchEngineSolr.java	2010-01-05 09:32:25 UTC (rev =
343)
@@ -1,16 +1,16 @@
 /* *##%
  * Copyright (c) 2009 poussin. All rights reserved.
- *=20
+ *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation, either version 3 of the License, or
  * (at your option) any later version.
- *=20
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- *=20
+ *
  * You should have received a copy of the GNU General Public License
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *##%*/
@@ -58,6 +58,7 @@
 import org.sharengo.wikitty.WikittyExtensionStorage;
 import org.sharengo.wikitty.WikittySearchEngine;
 import org.sharengo.wikitty.WikittyTransaction;
+import org.sharengo.wikitty.search.Element;
 import org.sharengo.wikitty.search.Search;
=20
 /**
@@ -70,6 +71,7 @@
  */
 public class WikittySearchEngineSolr implements WikittySearchEngine {
=20
+
     /** to use log facility, just put in your code: log.info(\"...\"); */
     static private Log log =3D LogFactory.getLog(WikittySearchEngineSolr.cla=
ss);
=20
@@ -111,7 +113,13 @@
         }
     }
=20
-    static protected class TypeFieldModifer implements Restriction2Solr.Fiel=
dModifier {
+    /** use to permit client to modify fieldname during query generation */
+    static public interface FieldModifier {
+        public String convertToSolr(String fieldname);
+        public String convertToField(String solrName);
+    }
+
+    static protected class TypeFieldModifer implements FieldModifier {
         protected WikittyExtensionStorage extensionStorage;
         public TypeFieldModifer(WikittyExtensionStorage extensionStorage) {
             this.extensionStorage =3D extensionStorage;
@@ -121,39 +129,42 @@
             String result =3D fqfieldname;
             String[] searchField =3D fqfieldname.split("\\.");
=20
-            if (searchField.length =3D=3D 2) {
+            if (Element.ELT_EXTENSION.equals(fqfieldname)) {
+                result =3D SOLR_EXTENSIONS;
+
+            } else if (Element.ELT_ID.equals(fqfieldname)) {
+                result =3D SOLR_ID;
+
+            } else if (searchField.length >=3D 2) {
                 String extName =3D searchField[0];
                 String fieldName =3D searchField[1];
=20
-                String version =3D extensionStorage.getLastVersion(extName);
-                if (version !=3D null) { // not valid extension is version =
=3D=3D null
-                    WikittyExtension ext =3D extensionStorage.restore(
-                            WikittyExtension.computeId(extName, version));
-                    FieldType type =3D ext.getFieldType(fieldName.replace(" =
", "_"));
-                    if (type !=3D null) { // type can be null if extension v=
ersion differ
-                        result =3D WikittySearchEngineSolr.getSolrFieldName(
-                                fqfieldname, type);
+                if (Criteria.ALL_EXTENSIONS.equals(extName)) {
+                    fqfieldname =3D SOLR_ALL_EXTENSIONS + "." + fieldName;
+                }
+
+                if (searchField.length >=3D 3) {
+                    String fieldNameType =3D searchField[2];
+
+                    if (Element.ElementType.TEXT.name().equals(fieldNameType=
)) {
+                        result =3D extName + "." + fieldName + "_s_t";
                     } else {
-                        log.debug(String.format(
-                                "Field '%s' could not be found in '%s'",
-                                fqfieldname, extName));
+                        TYPE  type =3D FieldType.TYPE.valueOf(fieldNameType);
+                        result =3D WikittySearchEngineSolr.getSolrFieldName(=
fqfieldname, type);
                     }
-                } else {
-                    log.warn("No version for extension " + extName);
+                    return result;
                 }
-            }
=20
-            if (searchField.length =3D=3D 3) {
-                String extName =3D searchField[0];
-                String fieldName =3D searchField[1];
-                String fieldType =3D searchField[2];
-
-                if(Criteria.ALL_EXTENSIONS.equals(extName)) {
-                    TYPE type =3D FieldType.TYPE.valueOf(fieldType);
-                    String solrFieldName =3D SOLR_ALL_EXTENSIONS + "." + fie=
ldName;
-                    result =3D WikittySearchEngineSolr.getSolrFieldName(solr=
FieldName, type);
-                } else {
-                    log.warn("All extension not found " + extName);
+                // Search type of field in extension
+                String version =3D extensionStorage.getLastVersion(extName);
+                if (version !=3D null) { // not valid extension is version =
=3D=3D null
+                    WikittyExtension ext =3D extensionStorage.restore(extNam=
e, version);
+                    FieldType fieldType =3D ext.getFieldType(fieldName);
+                    if (fieldType !=3D null) { // type can be null if extens=
ion version differ
+                        TYPE type =3D fieldType.getType();
+                        result =3D WikittySearchEngineSolr.getSolrFieldName(=
fqfieldname, type);
+                        return result;
+                    }
                 }
             }
=20
@@ -161,10 +172,12 @@
         }
=20
         public String convertToField(String solrName) {
-            String fieldname =3D solrName.replaceAll("(_b$)|(_dt$)|(_t$)|(_l=
$)", "");
-            return fieldname;
+            String fieldName =3D solrName.replaceAll("(_b$)|(_dt$)|(_s$)|(_s=
_t$)|(_d$)", "");
+            if(SOLR_EXTENSIONS.equals(fieldName)) {
+                fieldName =3D Element.ELT_EXTENSION;
+            }
+            return fieldName;
         }
-
     }
=20
     protected static class ReindexChildTreeNode extends HashSet<String> {
@@ -230,7 +243,7 @@
     protected TypeFieldModifer fieldModifier;
=20
     public WikittySearchEngineSolr(WikittyExtensionStorage extensionStorage)=
 {
-        this(extensionStorage, null);   =20
+        this(extensionStorage, null);
     }
=20
     public WikittySearchEngineSolr(WikittyExtensionStorage extensionStorage,=
 String dataDir) {
@@ -280,7 +293,7 @@
             Collection<Wikitty> wikitties) {
         List<Command> result =3D new ArrayList<Command>(wikitties.size());
         ReindexChildTreeNode reindexChildTreeNode =3D ReindexChildTreeNode.g=
etReindexChildTreeNode(transaction);
-       =20
+
         for (Wikitty w : wikitties) {
=20
             if(w.hasExtension(TreeNode.EXT_TREENODE)) {
@@ -294,12 +307,12 @@
                 SolrDocument treeNodeDoc =3D findById(treeNodeId);
                 if(treeNodeDoc !=3D null) {
                     Collection oldChildren =3D treeNodeDoc.
-                            getFieldValues(TreeNode.FQ_FIELD_CHILDREN + "_t"=
);
+                            getFieldValues(TreeNode.FQ_FIELD_CHILDREN + "_s"=
);
                     if(oldChildren !=3D null) {
                         reindexChildTreeNode.addAll(oldChildren);
                     }
                 }
-               =20
+
             }
=20
             result.add(new CommandSolr(w));
@@ -330,7 +343,7 @@
         } catch (Exception eee) {
             throw new WikittyException(eee);
         }
-       =20
+
         return result;
     }
=20
@@ -360,7 +373,7 @@
                 solrServer.add(doc);
             }
             solrServer.commit();
-           =20
+
             // no specific result needed
             UpdateResponse result =3D new UpdateResponse();
             return result;
@@ -380,15 +393,15 @@
             int firstIndex =3D criteria.getFirstIndex();
             int endIndex =3D criteria.getEndIndex();
=20
-	        query.setStart(firstIndex);
-	        int nbRows;
-	        if (endIndex =3D=3D -1) {
-	            // WARNING It is necessary to substract 'start' otherwise, ther=
e is a capacity overlow in solR
-	            nbRows =3D Integer.MAX_VALUE - firstIndex;
-	        } else {
-	            nbRows =3D endIndex - firstIndex + 1;
-	        }
-	        query.setRows(nbRows);
+            query.setStart(firstIndex);
+            int nbRows;
+            if (endIndex =3D=3D -1) {
+                // WARNING It is necessary to substract 'start' otherwise, t=
here is a capacity overlow in solR
+                nbRows =3D Integer.MAX_VALUE - firstIndex;
+            } else {
+                nbRows =3D endIndex - firstIndex + 1;
+            }
+            query.setRows(nbRows);
=20
             // Add sorting
             List<String> sortAscending =3D criteria.getSortAscending();
@@ -398,7 +411,7 @@
                     query.setSortField(tranform, SolrQuery.ORDER.asc);
                 }
             }
-           =20
+
             List<String> sortDescending =3D criteria.getSortDescending();
             if(sortDescending !=3D null) {
                 for (String sort : sortDescending) {
@@ -415,11 +428,11 @@
             // use to map query string to criteria facet name
             Map<String, String> facetQueryToName =3D new HashMap<String, Str=
ing>();
=20
-	        if ((facetField !=3D null && !facetField.isEmpty())
+            if ((facetField !=3D null && !facetField.isEmpty())
                     || (facetCriteria !=3D null && !facetCriteria.isEmpty())=
) {
-	            query.setFacet(true);
-	            query.setFacetMinCount(1);
-	            // query.setFacetLimit(8); // no limit actualy
+                query.setFacet(true);
+                query.setFacetMinCount(1);
+                // query.setFacetLimit(8); // no limit actualy
=20
                 // field facetisation
                 if (facetField !=3D null) {
@@ -438,12 +451,12 @@
                         query.addFacetQuery(queryFacet);
                     }
                 }
-	        }
+            }
=20
-	        QueryResponse resp =3D solrServer.query(query);
-	        SolrDocumentList solrResults =3D resp.getResults();
+            QueryResponse resp =3D solrServer.query(query);
+            SolrDocumentList solrResults =3D resp.getResults();
=20
-	        Map<String, List<FacetTopic>> facets =3D new HashMap<String, List<F=
acetTopic>>();
+            Map<String, List<FacetTopic>> facets =3D new HashMap<String, Lis=
t<FacetTopic>>();
             if (facetField !=3D null && !facetField.isEmpty()) {
                 for (FacetField facet : resp.getFacetFields()) {
                     String facetName =3D fieldModifier.convertToField(facet.=
getName());
@@ -476,20 +489,20 @@
                 }
             }
=20
-	        List<String> ids =3D new ArrayList<String>(solrResults.size());
-	        for (SolrDocument doc : solrResults) {
-	            String id =3D (String) doc.getFieldValue(SOLR_ID);
-	            ids.add(id);
-	        }
+            List<String> ids =3D new ArrayList<String>(solrResults.size());
+            for (SolrDocument doc : solrResults) {
+                String id =3D (String) doc.getFieldValue(SOLR_ID);
+                ids.add(id);
+            }
=20
             int numFound =3D (int)resp.getResults().getNumFound();
             PagedResult<String> result =3D new PagedResult<String>(
                     firstIndex, numFound, queryString, facets, ids);
=20
-	        return result;
-		} catch (SolrServerException e) {
-			throw new WikittyException(e);
-		}
+            return result;
+        } catch (SolrServerException e) {
+            throw new WikittyException(e);
+        }
     }
=20
     public Integer findNodeCount(Wikitty w) {
@@ -510,16 +523,17 @@
         return numFound;
     }
=20
+
     public Map<String, Integer> findAllChildrenCount(Wikitty w) {
         String wikittyId =3D w.getId();
-       =20
+
         String parent =3D w.getFieldAsWikitty(TreeNode.EXT_TREENODE, TreeNod=
e.FIELD_PARENT);
         if(parent =3D=3D null) {
             parent =3D TREENODE_ROOT;
         } else {
             parent =3D TREENODE_PREFIX + parent;
         }
-       =20
+
         // Find count with facet, if the node not contain recurcively conten=
t,
         // the node not found with facet
         Criteria criteria =3D Search.query().eq(parent, wikittyId).criteria()
@@ -565,42 +579,44 @@
=20
         SolrInputDocument doc =3D new SolrInputDocument();
         String id =3D w.getId();
-        doc.addField(SOLR_ID,id);
+        doc.addField(SOLR_ID, id);
=20
         for (String name : w.getExtensionNames()) {
             doc.addField(SOLR_EXTENSIONS, name);
         }
=20
         for (String fqfieldName : w.fieldNames()) {
-            FieldType type =3D w.getFieldType(fqfieldName);
-            //	do not index wikitty field reference
-//            if (type.getType() =3D=3D FieldType.TYPE.WIKITTY) {
-//                continue;
-//            }
-            String solrFqFieldName =3D getSolrFieldName(fqfieldName, type );
-            String[] extAndName =3D solrFqFieldName.split("\\.");
-            String solrFieldName =3D SOLR_ALL_EXTENSIONS + "." + extAndName[=
1];
-            if (type.isCollection()) {
-                Collection collection =3D (Collection) w.getFqField(fqfieldN=
ame);
-                if (collection !=3D null) {
-	                for (Object objectValue : collection) {
-	                    if (objectValue !=3D null) {
-	                        // String value =3D WikittyUtil.toString(type, obje=
ctValue);
-	                    	Object value =3D objectValue;
-	                        doc.addField(solrFqFieldName, value);
-	                        doc.addField(solrFieldName, value);
-	                    }
-	                }
+            FieldType fieldType =3D w.getFieldType(fqfieldName);
+            TYPE type =3D fieldType.getType();
+            String solrFqFieldName =3D getSolrFieldName(fqfieldName, type);
+
+            String[] solrFieldName =3D solrFqFieldName.split("\\.");
+            String solrAllFieldName =3D SOLR_ALL_EXTENSIONS + "." + solrFiel=
dName[1];
+
+            Object objectValue =3D w.getFqField(fqfieldName);
+            if(objectValue !=3D null) {
+                if (fieldType.isCollection()) {
+                    Collection collectionValue =3D (Collection) objectValue;
+                    for (Object itemValue : collectionValue) {
+                        if (itemValue !=3D null) {
+                            doc.addField(solrFqFieldName, itemValue);
+                            doc.addField(solrAllFieldName, itemValue);
+
+                            log.debug("index field " + solrFqFieldName + " w=
ith value '" + itemValue + "'");
+                        }
+                    }
+                } else {
+                    doc.addField(solrFqFieldName, objectValue);
+                    doc.addField(solrAllFieldName, objectValue);
+
+                    // Store as text field
+                    if(type =3D=3D TYPE.STRING) {
+                        doc.addField(solrFqFieldName + "_t", objectValue);
+                        doc.addField(solrAllFieldName + "_t", objectValue);
+                    }
+
+                    log.debug("index field " + solrFqFieldName + " with valu=
e '" + objectValue + "'");
                 }
-            } else {
-                Object objectValue =3D w.getFqField(fqfieldName);
-                if (objectValue !=3D null) {
-                    // String value =3D WikittyUtil.toString(type, objectVal=
ue);
-                	Object value =3D objectValue;
-                    log.debug("index field " + solrFqFieldName + " with valu=
e '" + value + "'");
-                    doc.addField(solrFqFieldName, value);
-                    doc.addField(solrFieldName, value);
-                }
             }
         }
         return doc;
@@ -615,11 +631,11 @@
         doc.setField(TREENODE_CHILD, childId);
=20
         // Find all node contain child
-        SolrQuery query =3D new SolrQuery(SOLR_QUERY_PARSER + TreeNode.FQ_FI=
ELD_CHILDREN + "_t:" + childId);
+        SolrQuery query =3D new SolrQuery(SOLR_QUERY_PARSER + TreeNode.FQ_FI=
ELD_CHILDREN + "_s:" + childId);
         QueryResponse response =3D solrServer.query(query);
         SolrDocumentList updateDocs =3D response.getResults();
=20
-        List<String> paths =3D new ArrayList<String>();
+        Map<String, String> paths =3D new HashMap<String, String>();
         for (Iterator<SolrDocument> iterator =3D updateDocs.iterator();
                 iterator.hasNext();) {
             SolrDocument solrDocument =3D iterator.next();
@@ -631,70 +647,23 @@
             String childParent =3D treeNodeId;
             String parent =3D parentMap.get(childParent);
             while (parent !=3D null) {
-                if(!paths.contains(parent)) {
+                String parentPath =3D paths.get(childParent);
+                if(parentPath =3D=3D null) {
                     doc.addField(TREENODE_PREFIX + parent, childParent);
-                    paths.add(parent);
+                    paths.put(childParent, parent);
                 }
=20
                 childParent =3D parent;
                 parent =3D parentMap.get(childParent);
             }
-            doc.addField(TREENODE_ROOT, childParent);
-        }
-       =20
-        return doc;
-    }
=20
-    /**
-     * Update all document depend a deleted node in tree
-     */
-    public void updateTreeNodeDocument(Map<String, SolrInputDocument> docume=
nts, String nodeId) throws SolrServerException {
-        SolrQuery query =3D new SolrQuery(SOLR_QUERY_PARSER + TREENODE_PREFI=
X + nodeId + ":*");
-        QueryResponse response =3D solrServer.query(query);
-        SolrDocumentList updateDocs =3D response.getResults();
-
-        for (Iterator<SolrDocument> iterator =3D updateDocs.iterator(); iter=
ator.hasNext();) {
-            SolrDocument solrDocument =3D iterator.next();
-           =20
-            String documentId =3D (String) solrDocument.getFieldValue(SOLR_I=
D);
-            SolrInputDocument alreadyDone =3D documents.get(documentId);
-
-            if (alreadyDone =3D=3D null) {
-                SolrInputDocument doc =3D updateTreeNodeDocument(solrDocumen=
t, nodeId);
-                documents.put(documentId, doc);
-            } else {
-                // Copy other field after node
-                String parent =3D (String) alreadyDone.getFieldValue(TREENOD=
E_PREFIX + nodeId);
-                if (parent !=3D null) {
-                    // Recreate doc a sub node is deleted
-                    SolrInputDocument doc =3D updateTreeNodeDocument(solrDoc=
ument, nodeId);
-                    documents.put(documentId, doc);
-                }
+            String parentPath =3D paths.get(childParent);
+            if(parentPath =3D=3D null) {
+                doc.addField(TREENODE_ROOT, childParent);
+                paths.put(childParent, TREENODE_ROOT);
             }
         }
-    }
=20
-    /**
-     * Re-create a new document without node deleted, from age document
-     */
-    public SolrInputDocument updateTreeNodeDocument(SolrDocument solrDocumen=
t, String nodeId) {
-        String documentId =3D (String) solrDocument.getFieldValue(SOLR_ID);
-
-        SolrInputDocument doc =3D new SolrInputDocument();
-        doc.setField(SOLR_ID, documentId);
-        doc.setField(TREENODE_CHILD, solrDocument.getFieldValue(TREENODE_CHI=
LD));
-       =20
-        // Copy other field after node
-        String parent =3D (String) solrDocument.getFieldValue(TREENODE_PREFI=
X + nodeId);
-        if (parent !=3D null) {
-            String childParent =3D (String) solrDocument.getFieldValue(paren=
t);
-            while (childParent !=3D null) {
-                doc.setField(parent, childParent);
-                parent =3D TREENODE_PREFIX + childParent;
-                childParent =3D (String) solrDocument.getFieldValue(parent);
-            }
-        }
-
         return doc;
     }
=20
@@ -719,12 +688,6 @@
         return null;
     }
=20
-    static public String getSolrFieldName(String fqfieldName, FieldType fiel=
dType) {
-        TYPE type =3D fieldType.getType();
-        String result =3D getSolrFieldName(fqfieldName, type);
-        return result;
-	}
-
     public static String getSolrFieldName(String fqfieldName, TYPE type) {
         switch (type) {
             case BOOLEAN:
@@ -732,11 +695,11 @@
             case DATE:
                 return fqfieldName + "_dt";
             case STRING:
-                return fqfieldName + "_t";
+                return fqfieldName + "_s";
             case NUMERIC:
                 return fqfieldName + "_d";
             default:
                 return fqfieldName;
         }
     }
-}
+}
\ No newline at end of file


--===============3889691786016338333==--


