Oh boy! LOL 

The sample code is too crazy to post but, I'll get 'er my best and try to 
portray what it is I'm doing. You have to understand that this code is deep 
within an abstraction layer to facilitate multiple search options. I'm 99% 
positive that the query objects that I'm generating are just what I want. I 
just don't see how I can use my Analyzer with them. Which, I think is the real 
problem here.

Anyway, on with the code. This code lives in the lucene impl of IQueryPart so, 
some of it is bound to make no sense to anyone but my teammates. Also, the call 
to Query.ReWrite() is new today as a test. I've found that I can live without 
it. So, ignore it. :)

public virtual Query Query
{
        get
        {
                BooleanQuery toReturn = new BooleanQuery();

                TermQuery q = new TermQuery( new Term( field.Name, 
searchTerm.ToString() ) );
                q.SetBoost( boost );

                if( !useSynonyms )
                {
                        return q;
                }
                else
                {
                        toReturn.Add( q, modifier.Occur );
                        Query synonyms = new Synonym( this ).FindSynonyms();

                        if( synonyms != null )
                        {
                                toReturn.Add(synonyms, 
BooleanClause.Occur.SHOULD);
                        }
                }

                LuceneSearchService searchService = new LuceneSearchService();
                IndexReader reader = 
searchService.GetIndexReader(Account.CurrentAccount.KbId);

                return toReturn.Rewrite(reader);
        }
}

Thanks for your help!!!

Chris Martin
Software Developer – myKB.com
  http://mykb.com    [EMAIL PROTECTED]    +1 602-326-5200
-----Original Message-----
From: Joe Shaw [mailto:[EMAIL PROTECTED] 
Sent: Thursday, March 15, 2007 8:34 PM
To: [email protected]
Subject: Re: Help With Search Please

Hi,

Martin, Chris wrote:
> I have an application that uses Lucene.net. Up until today, I've had
> success using the query 'syntax' until I needed to programmatically
> add a TON of clauses to the queries. With ~700 clauses,
> QueryParser.Parse is very slow.

Definitely.  Building queries programmatically using QueryParser is Bad.

> So, I turned to the query API, which works absolutely great; except
> for one minor thing. I can't seem to get any results (Hits) by
> passing the Query object to my Searcher without going through the
> QueryParser.
> 
> What in the world am I missing here? I can't find a way to simply
> tell any of the players which Analyzer to use.

It's hard to saw without seeing the code, but you might want to 
Console.WriteLine() the query objects to see what the differences are 
between the one you built by hand and the one handed to you by the 
QueryParser.

Sample code is always helpful too...

Joe


Reply via email to