LUCENE-1600: don't over-intern String field names

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@764596 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael McCandless 2009-04-13 20:07:28 +00:00
parent 6cab0952aa
commit f6f1d00d72
4 changed files with 35 additions and 4 deletions

View File

@ -164,6 +164,9 @@ Bug fixes
without a collator equal to one with a collator.
(Mark Platvoet via Mark Miller)
11. LUCENE-1600: Don't call String.intern unnecessarily in some cases
when loading documents from the index. (P Eger via Mike
McCandless)
New features

View File

@ -295,6 +295,28 @@ public final class Field extends AbstractField implements Fieldable, Serializabl
* </ul>
*/
public Field(String name, String value, Store store, Index index, TermVector termVector) {
this(name, true, value, store, index, termVector);
}
/**
* Create a field by specifying its name, value and how it will
* be saved in the index.
*
* @param name The name of the field
* @param internName Whether to .intern() name or not
* @param value The string to process
* @param store Whether <code>value</code> should be stored in the index
* @param index Whether the field should be indexed, and if so, if it should
* be tokenized before indexing
* @param termVector Whether term vector should be stored
* @throws NullPointerException if name or value is <code>null</code>
* @throws IllegalArgumentException in any of the following situations:
* <ul>
* <li>the field is neither stored nor indexed</li>
* <li>the field is not indexed but termVector is <code>TermVector.YES</code></li>
* </ul>
*/
public Field(String name, boolean internName, String value, Store store, Index index, TermVector termVector) {
if (name == null)
throw new NullPointerException("name cannot be null");
if (value == null)
@ -308,7 +330,11 @@ public final class Field extends AbstractField implements Fieldable, Serializabl
throw new IllegalArgumentException("cannot store term vector information "
+ "for a field that is not indexed");
this.name = name.intern(); // field names are interned
if (internName) // field names are optionally interned
name = name.intern();
this.name = name;
this.fieldsData = value;
if (store == Store.YES){

View File

@ -214,8 +214,8 @@ final class FieldInfos {
private FieldInfo addInternal(String name, boolean isIndexed,
boolean storeTermVector, boolean storePositionWithTermVector,
boolean storeOffsetWithTermVector, boolean omitNorms, boolean storePayloads, boolean omitTermFreqAndPositions) {
FieldInfo fi =
new FieldInfo(name, isIndexed, byNumber.size(), storeTermVector, storePositionWithTermVector,
name = name.intern();
FieldInfo fi = new FieldInfo(name, isIndexed, byNumber.size(), storeTermVector, storePositionWithTermVector,
storeOffsetWithTermVector, omitNorms, storePayloads, omitTermFreqAndPositions);
byNumber.add(fi);
byName.put(name, fi);

View File

@ -380,6 +380,7 @@ final class FieldsReader implements Cloneable {
final byte[] b = new byte[toRead];
fieldsStream.readBytes(b, 0, b.length);
f = new Field(fi.name, // field name
false,
new String(uncompress(b), "UTF-8"), // uncompress the value and add as string
store,
index,
@ -388,6 +389,7 @@ final class FieldsReader implements Cloneable {
f.setOmitNorms(fi.omitNorms);
} else {
f = new Field(fi.name, // name
false,
fieldsStream.readString(), // read value
store,
index,