r92 - in trunk/simexplorer-si-storage: . src/java/fr/cemagref/simexplorer/is/storage/database src/java/fr/cemagref/simexplorer/is/storage/database/lucene src/java/fr/cemagref/simexplorer/is/storage/engine src/java/fr/cemagref/simexplorer/is/storage/service src/test/fr/cemagref/simexplorer/is/storage/test
Author: glandais Date: 2008-01-03 11:10:57 +0000 (Thu, 03 Jan 2008) New Revision: 92 Modified: trunk/simexplorer-si-storage/.classpath trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/DatabaseConstants.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/service/StorageService.java trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/service/StorageServiceImpl.java trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/LuceneDatabaseLoadTestCase.java Log: Date sort Modified: trunk/simexplorer-si-storage/.classpath =================================================================== --- trunk/simexplorer-si-storage/.classpath 2007-12-28 16:00:25 UTC (rev 91) +++ trunk/simexplorer-si-storage/.classpath 2008-01-03 11:10:57 UTC (rev 92) @@ -2,7 +2,6 @@ <classpath> <classpathentry kind="src" path="src/java"/> <classpathentry kind="src" path="src/test"/> - <classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.jboss.ide.eclipse.as.core.server.runtime.runtimeTarget/JBoss v4.2"/> <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/> <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/> <classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.generic.runtimeTarget/JBoss v4.2"/> Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java 2007-12-28 16:00:25 UTC (rev 91) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/Database.java 2008-01-03 11:10:57 UTC (rev 92) @@ -109,7 +109,7 @@ */ public Set<MetaDataEntity> findElementsByProperties( Map<String, String> properties) throws Exception { - return findElementsByProperties(properties, 0, -1); + return findElementsByProperties(properties, 0, -1, 0); } /** @@ -126,7 +126,7 @@ * @throws Exception */ public abstract Set<MetaDataEntity> findElementsByProperties( - Map<String, String> properties, int start, int count) + Map<String, String> properties, int start, int count, int dateOrder) throws Exception; /** @@ -151,9 +151,9 @@ } public Set<MetaDataEntity> findElementsByType(String type, - boolean onlyLatest, int start, int count) throws Exception { + boolean onlyLatest, int start, int count, int dateOrder) throws Exception { return findElementsByProperties(getPropertiesByType(type, onlyLatest), - start, count); + start, count, dateOrder); } public int findElementsByTypeCount(String type, boolean onlyLatest) @@ -176,7 +176,7 @@ * @throws Exception */ public abstract Set<MetaDataEntity> findElementsByContentSearch( - String queryText, boolean onlyLatest, int start, int count) + String queryText, boolean onlyLatest, int start, int count, int dateOrder) throws Exception; /** Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/DatabaseConstants.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/DatabaseConstants.java 2007-12-28 16:00:25 UTC (rev 91) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/DatabaseConstants.java 2008-01-03 11:10:57 UTC (rev 92) @@ -69,5 +69,20 @@ * Field name for searchable content */ public static final String KEY_SEARCHABLE_CONTENT = "simexplorer.searchablecontent"; - + /** + * + */ + public static final String SORT_DATE_FIELD = KEY_CREATIONDATE; + /** + * + */ + public static final int SORT_DATE_NONE = 0; + /** + * + */ + public static final int SORT_DATE_ASCENDING = 1; + /** + * + */ + public static final int SORT_DATE_DESCENDING = -1; } Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java 2007-12-28 16:00:25 UTC (rev 91) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java 2008-01-03 11:10:57 UTC (rev 92) @@ -29,6 +29,7 @@ import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; import org.apache.lucene.search.Searcher; +import org.apache.lucene.search.Sort; import org.apache.lucene.search.TermQuery; import org.apache.lucene.store.Directory; import org.apache.lucene.store.FSDirectory; @@ -129,8 +130,8 @@ Analyzer analyzer = new SimpleAnalyzer(); // FIXME index location - File indexDir = new File("./index/"); - //File indexDir = new File("/home/landais/lucene/index.big"); + //File indexDir = new File("./index/"); + File indexDir = new File("/home/glandais/lucene/index.big"); // Base directory index directory = FSDirectory.getDirectory(indexDir, lockFactory); @@ -231,7 +232,7 @@ properties.put(KEY_VERSION, version.toString()); // Search elements - Hits hits = findHits(properties, searcher); + Hits hits = findHits(properties, searcher, SORT_DATE_NONE); return hits; } @@ -245,7 +246,7 @@ // Get current searcher instance Searcher searcher = getSearcher(); try { - Hits hits = findHits(properties, searcher); + Hits hits = findHits(properties, searcher, SORT_DATE_NONE); // Add all versions to a list versions = new ArrayList<Version>(); @@ -278,7 +279,7 @@ // Get current searcher instance Searcher searcher = getSearcher(); try { - Hits hits = findHits(properties, searcher); + Hits hits = findHits(properties, searcher, SORT_DATE_NONE); result = convertHitsToElements(hits, 0, -1); } finally { // Release searcher instance @@ -297,7 +298,7 @@ // Get current searcher instance Searcher searcher = getSearcher(); try { - Hits hits = findHits(properties, searcher); + Hits hits = findHits(properties, searcher, SORT_DATE_NONE); result = hits.length(); } finally { // Release searcher instance @@ -310,14 +311,14 @@ @Override public Set<MetaDataEntity> findElementsByProperties( - Map<String, String> properties, int start, int count) + Map<String, String> properties, int start, int count, int dateOrder) throws Exception { Set<MetaDataEntity> result = null; // Get current searcher instance Searcher searcher = getSearcher(); try { - Hits hits = findHits(properties, searcher); + Hits hits = findHits(properties, searcher, dateOrder); result = convertHitsToElements(hits, start, count); } finally { // Release searcher instance @@ -350,9 +351,20 @@ return result; } + private Sort getSortDate(int dateOrder) { + Sort sort = null; + if (dateOrder == SORT_DATE_DESCENDING) { + sort = new Sort(SORT_DATE_FIELD, true); + } + if (dateOrder == SORT_DATE_ASCENDING) { + sort = new Sort(SORT_DATE_FIELD); + } + return sort; + } + @Override public Set<MetaDataEntity> findElementsByContentSearch(String queryText, - boolean onlyLatest, int start, int count) throws Exception { + boolean onlyLatest, int start, int count, int dateOrder) throws Exception { Query query = getQueryByContentSearch(queryText, onlyLatest); Set<MetaDataEntity> result = null; @@ -361,7 +373,7 @@ // Get current searcher instance Searcher searcher = getSearcher(); try { - hits = searcher.search(query); + hits = searcher.search(query, getSortDate(dateOrder)); // Convert hits to elements result = convertHitsToElements(hits, start, count); } finally { @@ -409,7 +421,7 @@ * @throws IOException * @throws Exception */ - private Hits findHits(Map<String, String> properties, Searcher searcher) + private Hits findHits(Map<String, String> properties, Searcher searcher, int dateOrder) throws IOException { // Create a query with all parameters BooleanQuery query = new BooleanQuery(); @@ -418,7 +430,7 @@ BooleanClause.Occur.MUST); } - Hits hits = searcher.search(query); + Hits hits = searcher.search(query, getSortDate(dateOrder)); return hits; } Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java 2007-12-28 16:00:25 UTC (rev 91) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/engine/StorageEngine.java 2008-01-03 11:10:57 UTC (rev 92) @@ -179,16 +179,16 @@ } public MetaDataEntity[] findFullText(String query, boolean onlyLatest, - int indexStart, int count) throws Exception { + int indexStart, int count, int dateOrder) throws Exception { MetaDataEntity[] result = database.findElementsByContentSearch(query, - onlyLatest, indexStart, count).toArray(new MetaDataEntity[0]); + onlyLatest, indexStart, count, dateOrder).toArray(new MetaDataEntity[0]); return result; } public MetaDataEntity[] findElementsByType(String type, boolean onlyLatest, - int start, int count) throws Exception { + int start, int count, int dateOrder) throws Exception { MetaDataEntity[] result = database.findElementsByType(type, onlyLatest, - start, count).toArray(new MetaDataEntity[0]); + start, count, dateOrder).toArray(new MetaDataEntity[0]); return result; } Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/service/StorageService.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/service/StorageService.java 2007-12-28 16:00:25 UTC (rev 91) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/service/StorageService.java 2008-01-03 11:10:57 UTC (rev 92) @@ -31,11 +31,11 @@ int findFullTextCount(String query, boolean onlyLatest) throws Exception; MetaDataEntity[] findFullText(String query, boolean onlyLatest, - int indexStart, int count) throws Exception; + int indexStart, int count, int dateOrder) throws Exception; int findApplicationsCount(boolean onlyLatest) throws Exception; - MetaDataEntity[] findApplications(boolean onlyLatest, int start, int count) + MetaDataEntity[] findApplications(boolean onlyLatest, int start, int count, int dateOrder) throws Exception; } Modified: trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/service/StorageServiceImpl.java =================================================================== --- trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/service/StorageServiceImpl.java 2007-12-28 16:00:25 UTC (rev 91) +++ trunk/simexplorer-si-storage/src/java/fr/cemagref/simexplorer/is/storage/service/StorageServiceImpl.java 2008-01-03 11:10:57 UTC (rev 92) @@ -85,8 +85,8 @@ } public MetaDataEntity[] findFullText(String query, boolean onlyLatest, - int indexStart, int count) throws Exception { - return storageEngine.findFullText(query, onlyLatest, indexStart, count); + int indexStart, int count, int dateOrder) throws Exception { + return storageEngine.findFullText(query, onlyLatest, indexStart, count, dateOrder); } public int findFullTextCount(String query, boolean onlyLatest) @@ -100,9 +100,9 @@ } public MetaDataEntity[] findApplications(boolean onlyLatest, int start, - int count) throws Exception { + int count, int dateOrder) throws Exception { return storageEngine.findElementsByType(KEY_METADATA_TYPE_VALUE_EA, - onlyLatest, start, count); + onlyLatest, start, count, dateOrder); } private MetaDataEntity saveElement(InputStream zipStream) throws Exception { Modified: trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/LuceneDatabaseLoadTestCase.java =================================================================== --- trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/LuceneDatabaseLoadTestCase.java 2007-12-28 16:00:25 UTC (rev 91) +++ trunk/simexplorer-si-storage/src/test/fr/cemagref/simexplorer/is/storage/test/LuceneDatabaseLoadTestCase.java 2008-01-03 11:10:57 UTC (rev 92) @@ -146,7 +146,7 @@ int length = Math.min(200, Math.min(count, Math.max(1, count / 4))); Set<MetaDataEntity> metaDatas = database - .findElementsByContentSearch(key, false, start, length); + .findElementsByContentSearch(key, false, start, length, 1); System.out.println(key + " (" + start + " " + length + ") : " + metaDatas.size());
participants (1)
-
glandais@users.labs.libre-entreprise.org