Hi I wrote the following class:
public class AlwaysPrefixMultiFieldQP extends MultiFieldQueryParser { public MyQP(String[] fields, Analyzer analyzer) { super(fields, analyzer); } protected Query getFieldQuery(String field, String queryText) throws ParseException { if (field != null) { return new PrefixQuery(new Term(field, queryText)); } return super.getFieldQuery(field, queryText); } } What it does is override getFieldQuery. If the field is not null, it creates a new PrefixQuery. Following is a sample code: AlwaysPrefixMultiFieldQP m = new AlwaysPrefixMultiFieldQP(new String[] { "field" }, analyzer); Query q = m.parse("sof was"); System.out.println(q); This code prints: (field:sof*) (field:was*), which is I believe what you need. As for splitting the query (pre processing) - this is not recommended. It may work great for space separated languages, however may produce poor results for Asian languages (for example). The way I propose above makes use of the Analyzer you use, thus guarantees you append a '*' to all the words in the query. Hope this helps. On Nov 22, 2007 3:35 PM, Erick Erickson <[EMAIL PROTECTED]> wrote: > The simplest way would be to pre-process the query. That > is, just split on words and add the '*' as appropriate. > > Erick > > On Nov 21, 2007 2:16 PM, Anders Lybecker <[EMAIL PROTECTED]> wrote: > > > How do I force the MultiFieldQueryParser to interpret a string like > > "dock boat" as "dock* boat*" and therefore use PrefixQuery instead of > > TemQuery? > > > > The customer wants always to search with <word>* as default when > entering > > <word> > > > > :-) > > Anders Lybecker > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [EMAIL PROTECTED] > > For additional commands, e-mail: [EMAIL PROTECTED] > > > > > -- Regards, Shai Erera