Author: epbernard
Date: 2008-10-08 16:03:23 -0400 (Wed, 08 Oct 2008)
New Revision: 15292
Added:
search/trunk/src/java/org/hibernate/search/bridge/LuceneOptions.java
search/trunk/src/java/org/hibernate/search/engine/LuceneOptionsImpl.java
Removed:
search/trunk/src/java/org/hibernate/search/bridge/LuceneOptions.java
Modified:
search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java
Log:
HSEARCH-273 make LcueneOptions an interface and its implementation package visible
Deleted: search/trunk/src/java/org/hibernate/search/bridge/LuceneOptions.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/bridge/LuceneOptions.java 2008-10-08
17:33:27 UTC (rev 15291)
+++ search/trunk/src/java/org/hibernate/search/bridge/LuceneOptions.java 2008-10-08
20:03:23 UTC (rev 15292)
@@ -1,49 +0,0 @@
-// $Id$
-package org.hibernate.search.bridge;
-
-import org.apache.lucene.document.Field.Index;
-import org.apache.lucene.document.Field.Store;
-import org.apache.lucene.document.Field.TermVector;
-
-/**
- * A wrapper class for Lucene parameters needed for indexing.
- *
- * @author Hardy Ferentschik
- */
-public class LuceneOptions {
- private final Store store;
- private final Index index;
- private final TermVector termVector;
- private final Float boost;
-
- public LuceneOptions(Store store, Index index, TermVector termVector, Float boost) {
- this.store = store;
- this.index = index;
- this.termVector = termVector;
- this.boost = boost;
- }
-
- public Store getStore() {
- return store;
- }
-
- public Index getIndex() {
- return index;
- }
-
- public TermVector getTermVector() {
- return termVector;
- }
-
- /**
- * @return the boost value. If <code>boost == null</code>, the default boost
value
- * 1.0 is returned.
- */
- public Float getBoost() {
- if ( boost != null ) {
- return boost;
- } else {
- return 1.0f;
- }
- }
-}
\ No newline at end of file
Added: search/trunk/src/java/org/hibernate/search/bridge/LuceneOptions.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/bridge/LuceneOptions.java
(rev 0)
+++ search/trunk/src/java/org/hibernate/search/bridge/LuceneOptions.java 2008-10-08
20:03:23 UTC (rev 15292)
@@ -0,0 +1,22 @@
+package org.hibernate.search.bridge;
+
+import org.apache.lucene.document.Field;
+
+/**
+ * A wrapper class for Lucene parameters needed for indexing.
+ *
+ * @author Emmanuel Bernard
+ */
+public interface LuceneOptions {
+ Field.Store getStore();
+
+ Field.Index getIndex();
+
+ Field.TermVector getTermVector();
+
+ /**
+ * @return the boost value. If <code>boost == null</code>, the default boost
value
+ * 1.0 is returned.
+ */
+ Float getBoost();
+}
Modified: search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java
===================================================================
--- search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java 2008-10-08
17:33:27 UTC (rev 15291)
+++ search/trunk/src/java/org/hibernate/search/engine/DocumentBuilder.java 2008-10-08
20:03:23 UTC (rev 15292)
@@ -49,6 +49,7 @@
import org.hibernate.search.bridge.LuceneOptions;
import org.hibernate.search.bridge.TwoWayFieldBridge;
import org.hibernate.search.bridge.TwoWayString2FieldBridgeAdaptor;
+import org.hibernate.search.engine.LuceneOptionsImpl;
import org.hibernate.search.impl.InitContext;
import org.hibernate.search.store.DirectoryProvider;
import org.hibernate.search.store.IndexShardingStrategy;
@@ -503,18 +504,39 @@
//TODO could we use T instead of EntityClass?
public void addWorkToQueue(Class entityClass, T entity, Serializable id, WorkType
workType, List<LuceneWork> queue, SearchFactoryImplementor searchFactoryImplementor)
{
//TODO with the caller loop we are in a n^2: optimize it using a HashMap for work
recognition
+ List<LuceneWork> toDelete = new ArrayList<LuceneWork>();
+ boolean duplicateDelete = false;
for (LuceneWork luceneWork : queue) {
- //any work on the same entity should be ignored
+ //avoid unecessary duplicated work
if ( luceneWork.getEntityClass() == entityClass
) {
Serializable currentId = luceneWork.getId();
+ //currentId != null => either ADD or Delete work
if ( currentId != null && currentId.equals( id ) ) { //find a way to use
Type.equals(x,y)
- return;
+ if (workType == WorkType.DELETE) { //TODO add PURGE?
+ //DELETE should have precedence over any update before (HSEARCH-257)
+ //if an Add work is here, remove it
+ //if an other delete is here remember but still search for Add
+ if (luceneWork instanceof AddLuceneWork) {
+ toDelete.add( luceneWork );
+ }
+ else if (luceneWork instanceof DeleteLuceneWork) {
+ duplicateDelete = true;
+ }
+ }
+ else {
+ //we can safely say we are out, the other work is an ADD
+ return;
+ }
}
//TODO do something to avoid multiple PURGE ALL and OPTIMIZE
}
+ }
+ for ( LuceneWork luceneWork : toDelete ) {
+ toDelete.remove( luceneWork );
+ }
+ if (duplicateDelete) return;
- }
boolean searchForContainers = false;
String idInString = idBridge.objectToString( id );
if ( workType == WorkType.ADD ) {
@@ -620,7 +642,7 @@
Field classField =
new Field( CLASS_FIELDNAME, instanceClass.getName(), Field.Store.YES,
Field.Index.UN_TOKENIZED, Field.TermVector.NO );
doc.add( classField );
- LuceneOptions luceneOptions = new LuceneOptions( Field.Store.YES,
+ LuceneOptions luceneOptions = new LuceneOptionsImpl( Field.Store.YES,
Field.Index.UN_TOKENIZED, Field.TermVector.NO, idBoost );
idBridge.set( idKeywordName, id, doc, luceneOptions );
}
@@ -866,13 +888,13 @@
}
private LuceneOptions getClassLuceneOptions(int i) {
- LuceneOptions options = new LuceneOptions( classStores.get( i ),
+ LuceneOptions options = new LuceneOptionsImpl( classStores.get( i ),
classIndexes.get( i ), classTermVectors.get( i ), classBoosts.get( i ) );
return options;
}
private LuceneOptions getFieldLuceneOptions(int i, Float boost) {
- LuceneOptions options = new LuceneOptions( fieldStore.get( i ),
+ LuceneOptions options = new LuceneOptionsImpl( fieldStore.get( i ),
fieldIndex.get( i ), fieldTermVectors.get( i ), boost );
return options;
}
Copied: search/trunk/src/java/org/hibernate/search/engine/LuceneOptionsImpl.java (from rev
15291, search/trunk/src/java/org/hibernate/search/bridge/LuceneOptions.java)
===================================================================
--- search/trunk/src/java/org/hibernate/search/engine/LuceneOptionsImpl.java
(rev 0)
+++ search/trunk/src/java/org/hibernate/search/engine/LuceneOptionsImpl.java 2008-10-08
20:03:23 UTC (rev 15292)
@@ -0,0 +1,52 @@
+// $Id$
+package org.hibernate.search.engine;
+
+import org.apache.lucene.document.Field.Index;
+import org.apache.lucene.document.Field.Store;
+import org.apache.lucene.document.Field.TermVector;
+
+import org.hibernate.search.bridge.LuceneOptions;
+
+/**
+ * A wrapper class for Lucene parameters needed for indexing.
+ * This is a package level class
+ *
+ * @author Hardy Ferentschik
+ */
+class LuceneOptionsImpl implements LuceneOptions {
+ private final Store store;
+ private final Index index;
+ private final TermVector termVector;
+ private final Float boost;
+
+ public LuceneOptionsImpl(Store store, Index index, TermVector termVector, Float boost)
{
+ this.store = store;
+ this.index = index;
+ this.termVector = termVector;
+ this.boost = boost;
+ }
+
+ public Store getStore() {
+ return store;
+ }
+
+ public Index getIndex() {
+ return index;
+ }
+
+ public TermVector getTermVector() {
+ return termVector;
+ }
+
+ /**
+ * @return the boost value. If <code>boost == null</code>, the default boost
value
+ * 1.0 is returned.
+ */
+ public Float getBoost() {
+ if ( boost != null ) {
+ return boost;
+ } else {
+ return 1.0f;
+ }
+ }
+}
\ No newline at end of file
Property changes on:
search/trunk/src/java/org/hibernate/search/engine/LuceneOptionsImpl.java
___________________________________________________________________
Name: svn:keywords
+ Id
Name: svn:eol-style
+ native