parser question

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

parser question

Chris Salem
i set the default operator to AND, but if i have a query with an OR in it it doesn't work, for example, if i have the query 'software OR engineer' the parser interprets it as 'field:software field:engineer' and AND's them.  how would i fix this?


Chris Salem
440.946.5214 x5458
[hidden email]

----- Original Message -----
To: [hidden email]
From: Mark Miller <[hidden email]>
Sent: Tue 9/5/2006 5:38:50 PM
Subject: Re: parser question


QueryParser.setDefaultOperator(Operator op)

Chris Salem wrote:

> With all the parsers I have tried a space in a query, such as doing a search for "sales manager", interprets the space as an OR, is there a way to change it so that it interprets a space as an AND?
>
>
> Chris Salem
> 440.946.5214 x5458
> [hidden email]
>
> (The following links were included with this email:)
> mailto:[hidden email]
>
>
>
> (The following links were included with this email:)
> mailto:[hidden email]
>
>
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

(The following links were included with this email:)
mailto:[hidden email]

mailto:[hidden email]



(The following links were included with this email:)
mailto:[hidden email]

mailto:[hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: parser question

Mark Miller-3
Are you sure it is anding them?

field:software field:engineer

indicates an OR operation.

+field:software +field:engineer

indicates an AND operation.

- Mark





Chris Salem wrote:

> i set the default operator to AND, but if i have a query with an OR in it it doesn't work, for example, if i have the query 'software OR engineer' the parser interprets it as 'field:software field:engineer' and AND's them.  how would i fix this?
>
>
> Chris Salem
> 440.946.5214 x5458
> [hidden email]
>
> ----- Original Message -----
> To: [hidden email]
> From: Mark Miller <[hidden email]>
> Sent: Tue 9/5/2006 5:38:50 PM
> Subject: Re: parser question
>
>
> QueryParser.setDefaultOperator(Operator op)
>
> Chris Salem wrote:
>  
>> With all the parsers I have tried a space in a query, such as doing a search for "sales manager", interprets the space as an OR, is there a way to change it so that it interprets a space as an AND?
>>
>>
>> Chris Salem
>> 440.946.5214 x5458
>> [hidden email]
>>
>> (The following links were included with this email:)
>> mailto:[hidden email]
>>
>>
>>
>> (The following links were included with this email:)
>> mailto:[hidden email]
>>
>>
>>
>>
>>    
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
> (The following links were included with this email:)
> mailto:[hidden email]
>
> mailto:[hidden email]
>
>
>
> (The following links were included with this email:)
> mailto:[hidden email]
>
> mailto:[hidden email]
>
>
>
>  

---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: parser question

Erick Erickson
In reply to this post by Chris Salem
Also, watch your query, the OR is case-sensitive. If you lowercase the
entire string, the 'OR' gets lowercased too, in which case it's not
interpreted as an operator.

On 9/6/06, Chris Salem <[hidden email]> wrote:

>
> i set the default operator to AND, but if i have a query with an OR in it
> it doesn't work, for example, if i have the query 'software OR engineer' the
> parser interprets it as 'field:software field:engineer' and AND's them.  how
> would i fix this?
>
>
> Chris Salem
> 440.946.5214 x5458
> [hidden email]
>
> ----- Original Message -----
> To: [hidden email]
> From: Mark Miller <[hidden email]>
> Sent: Tue 9/5/2006 5:38:50 PM
> Subject: Re: parser question
>
>
> QueryParser.setDefaultOperator(Operator op)
>
> Chris Salem wrote:
> > With all the parsers I have tried a space in a query, such as doing a
> search for "sales manager", interprets the space as an OR, is there a way to
> change it so that it interprets a space as an AND?
> >
> >
> > Chris Salem
> > 440.946.5214 x5458
> > [hidden email]
> >
> > (The following links were included with this email:)
> > mailto:[hidden email]
> >
> >
> >
> > (The following links were included with this email:)
> > mailto:[hidden email]
> >
> >
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
> (The following links were included with this email:)
> mailto:[hidden email]
>
> mailto:[hidden email]
>
>
>
> (The following links were included with this email:)
> mailto:[hidden email]
>
> mailto:[hidden email]
>
>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: parser question

Mark Miller-3
In reply to this post by Chris Salem
yes its ANDing them.  Doing the query 'software engineer', 'software OR
engineer', 'software AND engineer' all return the same results.  the
generated queries for them respectively are '(field:software
field:engineer)', '(field:software field:engineer)' and
'(+field:software +field:engineer)'.  I do set the default operator to
AND and i'm using the MultiFieldQueryParser if that makes a difference
(it was doing the same thing with the QueryParser as well).


Chris Salem
440.946.5214 x5458
[hidden email] <mailto:[hidden email]>
 
------

If you keep the exchange on the list you'll get the benefit of someone
smarter and more experienced than me stepping in.

See if the following code does not convince  you that it works
correctly.  I am using Lucene 2.0. Maybe there is a bug in an earlier
version, but I doubt it:

import java.io.IOException;
import java.util.Date;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.WhitespaceAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.queryParser.QueryParser.Operator;
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.store.RAMDirectory;


public class TestWildCardFilter {
    private static RAMDirectory directory;

    private static Analyzer analyzer;

    public static void main(String[] args) {
        setupIndex();
       
        try {
            search("coconut stone");
            search("coconut OR stone");
            search("coconut AND stone");
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    private static void setupIndex() {
        directory = new RAMDirectory();

        analyzer = new WhitespaceAnalyzer();

        IndexWriter writer;

        try {
            writer = new IndexWriter(directory, analyzer, true);

            Document doc = new Document();
            doc.add(new Field("allFields",
                    "levely bunch of coconuts",
                    Field.Store.NO, Field.Index.TOKENIZED));

            writer.addDocument(doc);


            doc = new Document();
            doc.add(new Field("allFields", "crazy rolling stone",
                    Field.Store.NO, Field.Index.TOKENIZED));
            writer.addDocument(doc);
           
            doc = new Document();
            doc.add(new Field("allFields", "rolling stone done in by
coconut",
                    Field.Store.NO, Field.Index.TOKENIZED));
            writer.addDocument(doc);


            writer.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
   
    public static int search(String q) throws Exception {
        IndexSearcher is = new IndexSearcher(directory);

        QueryParser qp = new QueryParser("allFields", analyzer);
        qp.setDefaultOperator(Operator.AND);
        Query query = qp.parse(q);
       
        long start = new Date().getTime();
        Hits hits = is.search(query);
        long end = new Date().getTime();
        System.err.println("\nquery: " + query.toString());
        System.err.println("Found " + hits.length() + " document(s) (in " +
            (end - start) + " milliseconds) that matched query '" + q +
"':");
       
        return hits.length();
    }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]