On Monday 07 February 2005 19:17, David Spencer wrote:
> This is interesting and may match what I've wanted - a way to register
> customized query expansion modules w/ the query parser so that you can
> experiment with different ways of expanding the query e.g. I wrote a
> "WordNet" package that's in the sandbox that expands terms by adding
> their synonyms e.g. "big" might expand to "big large^.9 huge^.9".

I took a quick look at the WordNet CVS and I'm not quite sure so I'm kind of 
working off what's below!

> So is it safe to assume I could use your code like this (with 2 lines
> changed from your example):
>
> QueryParser parser =
>    new QueryParser(
>       "synonym",                 // pseudo field?
>       new StandardAnalyzer(),
>       new SpecialQueryFactory(new WordNetQueryFactoryImpl())); //
> wordnet factory?

It would probably be something like:

QueryParser parser = 
  new QueryParser(
    "defaultSearchField",                       // default search field (as 
normal)
    new StandardAnalyzer(),
    new WordNetQueryFactoryImpl("synonym", new QueryFactoryImpl()));

I'm thinking that an instance of your QueryFactory implementation would 
effectively decorate another instance and might have your pseudo-field passed 
as a parameter.  It would then be implemented to catch any pseudo-field (in 
this case "synonym") queries and process the text itself.  

> Then a query can use the pseudo-field "synonym" any place:
>
> "+synonym:big dog"
>
> expands to:
>
> "+(big large^.9 huge^.9) dog"

Your WordNetQueryFactoryImpl would be something like this:

public class WordNetQueryFactoryImpl implements QueryFactory {
  private final QueryFactory m_delegate;
  private final String m_pseudoField;

  public WordNetQueryFactoryImpl(String pseudoField, QueryFactory delegate) {
    m_pseudoField = pseudoField;
    m_delegate = delegate;
  }

  // ... a few other interface methods here but cut for clarity ...

  public Query getFieldQuery(
      String field,
      Analyzer analyzer,
      String queryText,
      int slop)
  {
    // If the field is our pseudo-field and the value for it is 'big'
    if (m_pseudoField.equals(field) && "big".equals(queryText)) {
      // Use the delegate to build our query?
      BooleanQuery tmp = new BooleanQuery();
      tmp.add(
          m_delegate.getFieldQuery(field, analyzer, "big", slop), 
          BooleanClause.Occur.SHOULD);
      tmp.add(
          m_delegate.getFieldQuery(field, analyzer, "large", slop), 
          BooleanClause.Occur.SHOULD);
      tmp.add(
          m_delegate.getFieldQuery(field, analyzer, "huge", slop), 
          BooleanClause.Occur.SHOULD);
      return tmp;
    } else {
      // ... otherwise delegate the handling to the other QueryFactory
      return m_delegate.getFieldQuery(field, analyzer, queryText, slop);
    }
  }
}

Just as an example, I'm sure you'll work out what I mean!

> If so cool, I've wanted an extensible query parser for a while..

I don't think it quite fits an "extensible query parser", but I think it might 
get you somewhere.

Matt

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to