lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Doug Cutting <DCutt...@grandcentral.com>
Subject RE: Boolean Query Parsing with "IN" keyword
Date Tue, 26 Feb 2002 17:38:13 GMT
> From: Otis Gospodnetic [mailto:otis_gospodnetic@yahoo.com]
> 
> But, StandardAnalyzer is no longer final (get the latest 
> build) and you
> can write a class that subclasses it

Right.  To flesh out Otis' example of how to change StandardAnalyzer's stop
list by defining a subclass of it:

  public class MyAnalyzer extends StandardAnalyzer {
    private static final String[] MY_STOP_WORDS = {"a", "b", ... };
    public MyAnalyzer() {
      super(MY_STOP_WORDS);
    }
  }

Another way to do this is to use a different analyzer for the "state" field
than for your other fields:

  public class MyAnalyzer2 extends Analyzer {
    private Analyzer stateAnalyzer = new SimpleAnalyzer();
    private Analyzer otherAnalyzer = new StandardAnalyzer();
    public TokenStream tokenStream(String field, Reader reader) {
      if ("state".equals(field))
        return stateAnalyzer.tokenStream(field, reader);
      else
        return otherAnalyzer.tokenStream(field, reader);
    }
  }

This technique is handy for fields that aren't normal text.  For example,
you could use WhitespaceAnalyzer for a case-sensitive field whose values
contain punctuation.

Doug

--
To unsubscribe, e-mail:   <mailto:lucene-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:lucene-user-help@jakarta.apache.org>


Mime
View raw message