LUCENE-3307: don't require an analyzer, if all fields are NOT_ANALYZED

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1147530 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shai Erera 2011-07-17 05:30:50 +00:00
parent 06891eec12
commit 561723eca6
2 changed files with 5 additions and 16 deletions

View File

@ -78,7 +78,7 @@ final class DocInverterPerField extends DocFieldConsumerPerField {
if (field.isIndexed() && doInvert) { if (field.isIndexed() && doInvert) {
if (i > 0) if (i > 0)
fieldState.position += docState.analyzer.getPositionIncrementGap(fieldInfo.name); fieldState.position += docState.analyzer == null ? 0 : docState.analyzer.getPositionIncrementGap(fieldInfo.name);
if (!field.isTokenized()) { // un-tokenized field if (!field.isTokenized()) { // un-tokenized field
String stringValue = field.stringValue(); String stringValue = field.stringValue();
@ -188,7 +188,7 @@ final class DocInverterPerField extends DocFieldConsumerPerField {
} }
} }
fieldState.offset += docState.analyzer.getOffsetGap(field); fieldState.offset += docState.analyzer == null ? 0 : docState.analyzer.getOffsetGap(field);
fieldState.boost *= field.getBoost(); fieldState.boost *= field.getBoost();
} }

View File

@ -115,17 +115,6 @@ public class SpellChecker implements java.io.Closeable {
private StringDistance sd; private StringDistance sd;
private Comparator<SuggestWord> comparator; private Comparator<SuggestWord> comparator;
/** we don't need to actually analyze any content:
* all fields are indexed NOT_ANALYZED, but docsinverter
* needs this for the offset gap!
*/
private static Analyzer noAnalyzer = new Analyzer() {
@Override
public TokenStream tokenStream(String fieldName, Reader reader) {
return null;
}
};
/** /**
* Use the given directory as a spell checker index. The directory * Use the given directory as a spell checker index. The directory
@ -182,7 +171,7 @@ public class SpellChecker implements java.io.Closeable {
if (!IndexReader.indexExists(spellIndexDir)) { if (!IndexReader.indexExists(spellIndexDir)) {
IndexWriter writer = new IndexWriter(spellIndexDir, IndexWriter writer = new IndexWriter(spellIndexDir,
new IndexWriterConfig(Version.LUCENE_CURRENT, new IndexWriterConfig(Version.LUCENE_CURRENT,
noAnalyzer)); null));
writer.close(); writer.close();
} }
swapSearcher(spellIndexDir); swapSearcher(spellIndexDir);
@ -480,7 +469,7 @@ public class SpellChecker implements java.io.Closeable {
final Directory dir = this.spellIndex; final Directory dir = this.spellIndex;
final IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig( final IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(
Version.LUCENE_CURRENT, Version.LUCENE_CURRENT,
noAnalyzer) null)
.setOpenMode(OpenMode.CREATE)); .setOpenMode(OpenMode.CREATE));
writer.close(); writer.close();
swapSearcher(dir); swapSearcher(dir);
@ -517,7 +506,7 @@ public class SpellChecker implements java.io.Closeable {
synchronized (modifyCurrentIndexLock) { synchronized (modifyCurrentIndexLock) {
ensureOpen(); ensureOpen();
final Directory dir = this.spellIndex; final Directory dir = this.spellIndex;
final IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(Version.LUCENE_CURRENT, noAnalyzer).setRAMBufferSizeMB(ramMB)); final IndexWriter writer = new IndexWriter(dir, new IndexWriterConfig(Version.LUCENE_CURRENT, null).setRAMBufferSizeMB(ramMB));
((TieredMergePolicy) writer.getConfig().getMergePolicy()).setMaxMergeAtOnce(mergeFactor); ((TieredMergePolicy) writer.getConfig().getMergePolicy()).setMaxMergeAtOnce(mergeFactor);
IndexSearcher indexSearcher = obtainSearcher(); IndexSearcher indexSearcher = obtainSearcher();
final List<TermsEnum> termsEnums = new ArrayList<TermsEnum>(); final List<TermsEnum> termsEnums = new ArrayList<TermsEnum>();