Author: glandais Date: 2008-03-05 09:58:02 +0000 (Wed, 05 Mar 2008) New Revision: 1288 Removed: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/BitSetFilter.java trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/BitSetHitCollector.java Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java Log: Security filtering with Lucene objects Deleted: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/BitSetFilter.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/BitSetFilter.java 2008-03-04 20:05:33 UTC (rev 1287) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/BitSetFilter.java 2008-03-05 09:58:02 UTC (rev 1288) @@ -1,52 +0,0 @@ -/* -* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais -* -* 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 2 -* of the License, or (at your option) any later version. -* -* 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. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.storage.database.lucene; - -import java.io.IOException; -import java.util.BitSet; - -import org.apache.lucene.index.IndexReader; -import org.apache.lucene.search.Filter; - -/** - * The Class BitSetFilter. - */ -public class BitSetFilter extends Filter { - - /** The bit set. */ - private BitSet bitSet; - - /* (non-Javadoc) - * @see org.apache.lucene.search.Filter#bits(org.apache.lucene.index.IndexReader) - */ - @Override - public BitSet bits(IndexReader reader) throws IOException { - return bitSet; - } - - /** - * Instantiates a new bit set filter. - * - * @param bitSet the bit set - */ - public BitSetFilter(BitSet bitSet) { - super(); - this.bitSet = bitSet; - } - -} Deleted: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/BitSetHitCollector.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/BitSetHitCollector.java 2008-03-04 20:05:33 UTC (rev 1287) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/BitSetHitCollector.java 2008-03-05 09:58:02 UTC (rev 1288) @@ -1,49 +0,0 @@ -/* -* ##% Copyright (C) 2008 Code Lutin, Gabriel Landais -* -* 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 2 -* of the License, or (at your option) any later version. -* -* 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. -* -* You should have received a copy of the GNU General Public License -* along with this program; if not, write to the Free Software -* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -* ##% */ -package fr.cemagref.simexplorer.is.storage.database.lucene; - -import java.util.BitSet; - -import org.apache.lucene.search.HitCollector; - -/** - * The Class BitSetHitCollector. - */ -public class BitSetHitCollector extends HitCollector { - - /** The bits. */ - private BitSet bits = new BitSet(); - - /* (non-Javadoc) - * @see org.apache.lucene.search.HitCollector#collect(int, float) - */ - @Override - public void collect(int doc, float score) { - bits.set(doc); - } - - /** - * Gets the bits. - * - * @return the bits - */ - public BitSet getBits() { - return bits; - } - -} Modified: trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java =================================================================== --- trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java 2008-03-04 20:05:33 UTC (rev 1287) +++ trunk/simexplorer-is/simexplorer-is-storage/src/java/fr/cemagref/simexplorer/is/storage/database/lucene/LuceneDatabase.java 2008-03-05 09:58:02 UTC (rev 1288) @@ -22,7 +22,6 @@ import java.io.Reader; import java.io.StringReader; import java.util.ArrayList; -import java.util.BitSet; import java.util.Collection; import java.util.Date; import java.util.HashMap; @@ -37,7 +36,6 @@ import org.apache.lucene.analysis.KeywordAnalyzer; import org.apache.lucene.analysis.PerFieldAnalyzerWrapper; import org.apache.lucene.analysis.SimpleAnalyzer; -import org.apache.lucene.analysis.TokenStream; import org.apache.lucene.document.Document; import org.apache.lucene.document.Field; import org.apache.lucene.index.IndexReader; @@ -47,10 +45,12 @@ import org.apache.lucene.queryParser.QueryParser; import org.apache.lucene.search.BooleanClause; import org.apache.lucene.search.BooleanQuery; +import org.apache.lucene.search.CachingWrapperFilter; import org.apache.lucene.search.Filter; import org.apache.lucene.search.Hits; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; +import org.apache.lucene.search.QueryWrapperFilter; import org.apache.lucene.search.Searcher; import org.apache.lucene.search.Sort; import org.apache.lucene.search.SortField; @@ -255,37 +255,36 @@ } /** - * Creates the bit set. + * Creates the query. * * @param visibleItems the visible items * - * @return the bit set - * - * @throws SimExplorerTechnicalException the sim explorer technical exception + * @return the query */ - private BitSet createBitSet(Collection<String> visibleItems) throws SimExplorerTechnicalException { + private Query createQuery(Collection<String> visibleItems) { + int maxTerms = BooleanQuery.getMaxClauseCount() - 1; + int i = 0; + boolean subQueryIsQuery = true; + BooleanQuery query = new BooleanQuery(); + + BooleanQuery subQuery = new BooleanQuery(); for (String string : visibleItems) { - query.add(new TermQuery(new Term(KEY_UUID, string)), BooleanClause.Occur.SHOULD); - } - - BitSetHitCollector bitSetHitCollector = new BitSetHitCollector(); - try { - // Get current searcher instance - Searcher searcher = getSearcher(); - try { - searcher.search(query, bitSetHitCollector); - } finally { - // Release searcher instance - releaseSearcher(searcher); + subQuery.add(new TermQuery(new Term(KEY_UUID, string)), BooleanClause.Occur.SHOULD); + if (i % maxTerms == 0) { + subQueryIsQuery = false; + query.add(new BooleanClause(subQuery, BooleanClause.Occur.SHOULD)); + subQuery = new BooleanQuery(); } - } catch (Exception e) { - throw new SimExplorerTechnicalException(e); + i++; } - - return bitSetHitCollector.getBits(); + + if (subQueryIsQuery) { + return subQuery; + } + return query; } - + /** * Creates the filter. * @@ -296,34 +295,10 @@ * @throws SimExplorerTechnicalException the sim explorer technical exception */ private Filter createFilter(Collection<String> visibleItems) throws SimExplorerTechnicalException { - List<BitSet> bitSets = new ArrayList<BitSet>(); - - int maxTerms = BooleanQuery.getMaxClauseCount(); - int i = 0; - - Collection<String> currentList = new ArrayList<String>(); - for (String uuid : visibleItems) { - currentList.add(uuid); - if (i == maxTerms) { - bitSets.add(createBitSet(currentList)); - currentList.clear(); - i = 0; - } else { - i++; - } - } - if (visibleItems.size() > 0 && i != 0) { - bitSets.add(createBitSet(currentList)); - } - - BitSet finalBitSet = new BitSet(); - for (BitSet bitSet : bitSets) { - finalBitSet.or(bitSet); - } - Filter result = new BitSetFilter(finalBitSet); - return result; + Filter filter = new CachingWrapperFilter(new QueryWrapperFilter(createQuery(visibleItems))); + return filter; } - + /* (non-Javadoc) * @see fr.cemagref.simexplorer.is.storage.database.Database#open(boolean) */