lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From theDude_2 <>
Subject Re: MultiFieldQueryParser - using a different analyzer per field...
Date Mon, 04 May 2009 13:24:03 GMT

Hey guys: original poster here, and I found a solution! I created a wrapper
that could accept multiple analyzers and then combined them into a search: 
here is the code.

------wrapper class---------

public class PositionalPorterStopAnalyzer extends Analyzer {
	private Set stopWords;
	public PositionalPorterStopAnalyzer() {
	public PositionalPorterStopAnalyzer(String[] stopList) {
		stopWords = StopFilter.makeStopSet(stopList);
	public TokenStream tokenStream(String fieldName, Reader reader) {
		StopFilter stopFilter = new StopFilter(new LowerCaseTokenizer(reader),
		return new PorterStemFilter(stopFilter);

------creating the search---------

PerFieldAnalyzerWrapper pfawBoth = new PerFieldAnalyzerWrapper(
					new StandardAnalyzer());
					pfawBoth.addAnalyzer("Field_1", new StandardAnalyzer());
					pfawBoth.addAnalyzer("Field_2", new PositionalPorterStopAnalyzer());
mfqp = new MultiFieldQueryParser(


thanks for all the help


theDude_2 wrote:
> Hello fellow Lucene developers!
> I have a bit of a question - and I can't find the answer in my lucene
> book....
> Im trying to create a query that will query 2 fields using different
> analyzers and combine the scores together to give me my "hits".  The idea
> is that for the one dataset I want a pure text match only, and for the
> other I want to use the stemming concept by using a custom made analyzer.  
> Is there a way to do this?
> --This is what I am thinking (conceptually)------
> MultiFieldQueryParser mfqp1 = new MultiFieldQueryParser(field1, new
> StandardAnalyzer(), boosts); 
> MultiFieldQueryParser mfqp2 = new MultiFieldQueryParser(field2, new
> PositionalPorterStopAnalyzer(), boosts);
> my MultiFieldQueryParser = mfqp1 + mfqp2
> ----------------
> The issue that I see is that if I just use one analyzer, I lose out.  I
> know I need to query multiple fields, in multiple ways, but I just dont
> know how to make this work....
> Any ideas?

View this message in context:
Sent from the Lucene - Java Users mailing list archive at

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message