-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add a WhitespaceAndQuoteTokenFactory as the default tokenizer, which …
…seems to fix #34 for reasons I do not understand
- Loading branch information
1 parent
4658949
commit 8a397ec
Showing
2 changed files
with
53 additions
and
1 deletion.
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
52 changes: 52 additions & 0 deletions
52
src/main/java/org/apache/solr/search/WhitespaceAndQuoteTokenizerFactory.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,52 @@ | ||
package org.apache.solr.search; | ||
|
||
import java.io.Reader; | ||
import java.util.Map; | ||
|
||
import org.apache.lucene.analysis.util.CharTokenizer; | ||
import org.apache.lucene.analysis.util.TokenizerFactory; | ||
import org.apache.lucene.util.Version; | ||
import org.apache.lucene.util.AttributeSource.AttributeFactory; | ||
|
||
/** | ||
* Copy of the WhitespaceTokenizerFactory, but tokenizes on quotes as well. Seems to work really well for most | ||
* of our synonym-related use cases. | ||
* @author nolan | ||
* | ||
*/ | ||
public class WhitespaceAndQuoteTokenizerFactory extends TokenizerFactory { | ||
|
||
public WhitespaceAndQuoteTokenizerFactory(Map<String, String> args) { | ||
super(args); | ||
assureMatchVersion(); | ||
if (!args.isEmpty()) { | ||
throw new IllegalArgumentException("Unknown parameters: " + args); | ||
} | ||
} | ||
|
||
@Override | ||
public WhitespaceAndQuoteTokenizer create(AttributeFactory factory, Reader input) { | ||
return new WhitespaceAndQuoteTokenizer(luceneMatchVersion, factory, input); | ||
} | ||
|
||
private static class WhitespaceAndQuoteTokenizer extends CharTokenizer { | ||
|
||
public WhitespaceAndQuoteTokenizer(Version matchVersion, Reader in) { | ||
super(matchVersion, in); | ||
} | ||
|
||
public WhitespaceAndQuoteTokenizer(Version matchVersion, AttributeFactory factory, Reader in) { | ||
super(matchVersion, factory, in); | ||
} | ||
|
||
/** | ||
* Collects only characters which do not satisfy | ||
* {@link Character#isWhitespace(int)}. or '"' This method represents the main | ||
* difference between this class and the normal WhitespaceTokenizer. | ||
*/ | ||
@Override | ||
protected boolean isTokenChar(int c) { | ||
return c != '"' && !Character.isWhitespace(c); | ||
} | ||
} | ||
} |