You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Alan Burlison <al...@gmail.com> on 2013/09/17 16:38:56 UTC
Writing Lucene analyzers - in Scala
I know this is the Lucene Java forum but it seemed vaguely appropriate.
I'm using Lucene from Scala and I needed to subclass a couple of the
analyzers to set the position increment gap. As the standard analysers
in question were all final classes I couldn't simply subclass them.
However it's perfectly possible to write Lucene analyzers entirely in
Scala. For example, here's the standard KeywordAnalyzer written in Scala
with a position increment gap of 100.
@throws(classOf[java.io.IOException])
class MultiKeywordAnalyzer extends Analyzer {
override protected def createComponents(fieldName: String, reader:
Reader):
TokenStreamComponents = {
new TokenStreamComponents(new KeywordTokenizer(reader))
}
override def getPositionIncrementGap(fieldName: String) = 100
}
Hopefully this might help someone in the future who googles to see if
it's possible :-)
--
Alan Burlison
--
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org