-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-2434 Implement null markers differently for the text datatype…
… in Elasticsearch 5
- Loading branch information
Showing
23 changed files
with
308 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
.../hibernate/search/elasticsearch/nulls/codec/impl/ElasticsearchAsTokenNullMarkerCodec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.elasticsearch.nulls.codec.impl; | ||
|
||
import org.hibernate.search.bridge.spi.NullMarker; | ||
import org.hibernate.search.engine.nulls.codec.impl.NullMarkerCodec; | ||
|
||
/** | ||
* A base class for {@link NullMarkerCodec}s that index null values as a non-null token. | ||
* <p> | ||
* This is necessary because Elasticsearch doesn't support 'null_value' on the 'text' datatype. | ||
* | ||
* @author Yoann Rodiere | ||
*/ | ||
abstract class ElasticsearchAsTokenNullMarkerCodec implements NullMarkerCodec { | ||
|
||
protected final NullMarker nullMarker; | ||
|
||
public ElasticsearchAsTokenNullMarkerCodec(NullMarker nullMarker) { | ||
super(); | ||
this.nullMarker = nullMarker; | ||
} | ||
|
||
@Override | ||
public NullMarker getNullMarker() { | ||
return nullMarker; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName() + "[" + nullMarker + "]"; | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
...nate/search/elasticsearch/nulls/codec/impl/ElasticsearchAsTokenStringNullMarkerCodec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.elasticsearch.nulls.codec.impl; | ||
|
||
import org.apache.lucene.document.Document; | ||
import org.apache.lucene.index.IndexableField; | ||
import org.apache.lucene.index.Term; | ||
import org.apache.lucene.search.Query; | ||
import org.apache.lucene.search.TermQuery; | ||
import org.apache.lucene.util.BytesRef; | ||
import org.hibernate.search.bridge.LuceneOptions; | ||
import org.hibernate.search.bridge.spi.NullMarker; | ||
import org.hibernate.search.engine.nulls.codec.impl.NullMarkerCodec; | ||
|
||
/** | ||
* A {@link NullMarkerCodec}s that index null values as the string token itself. | ||
* <p> | ||
* This is necessary because Elasticsearch doesn't support 'null_value' on the 'text' datatype. | ||
* | ||
* @author Sanne Grinovero | ||
*/ | ||
public class ElasticsearchAsTokenStringNullMarkerCodec extends ElasticsearchAsTokenNullMarkerCodec { | ||
|
||
private final BytesRef encodedToken; | ||
|
||
public ElasticsearchAsTokenStringNullMarkerCodec(NullMarker nullMarker) { | ||
super( nullMarker ); | ||
this.encodedToken = new BytesRef( (String) nullMarker.nullEncoded() ); | ||
} | ||
|
||
@Override | ||
public void encodeNullValue(String name, Document document, LuceneOptions luceneOptions) { | ||
luceneOptions.addFieldToDocument( name, (String) nullMarker.nullEncoded(), document ); | ||
} | ||
|
||
@Override | ||
public Query createNullMatchingQuery(String fieldName) { | ||
return new TermQuery( new Term( fieldName, encodedToken ) ); | ||
} | ||
|
||
@Override | ||
public boolean representsNullValue(IndexableField field) { | ||
String stringValue = field.stringValue(); | ||
return nullMarker.nullEncoded().equals( stringValue ); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.