FAQ
Hi everyone,

I've a simple question, but until now I couldn´t find the answer googling
it... If you could help me, thanks so much...

In the book Lucene in Action, this table is written:

Table 3.7 Boolean query operator shortcuts

Verbose syntax Shortcut syntax
a AND b +a +b
a OR b a b
a AND NOT b +a –b


Now I ask you: a - b will be also translated to a AND NOT b?


Thanks!
Gustavo Poll

Search Discussions

  • Franklin Simmons at Jul 25, 2011 at 8:10 pm
    I believe "a -b" is "a OR NOT b", assuming the default operator is OR.

    -----Original Message-----
    From: Gustavo Poll
    Sent: Monday, July 25, 2011 3:55 PM
    To: lucene-net-user@lucene.apache.org
    Subject: [Lucene.Net] Simple Question: boolean operator shortcut

    Hi everyone,

    I've a simple question, but until now I couldn´t find the answer googling it... If you could help me, thanks so much...

    In the book Lucene in Action, this table is written:

    Table 3.7 Boolean query operator shortcuts

    Verbose syntax Shortcut syntax
    a AND b +a +b
    a OR b a b
    a AND NOT b +a -b


    Now I ask you: a - b will be also translated to a AND NOT b?


    Thanks!
    Gustavo Poll
  • Digy at Jul 25, 2011 at 8:45 pm
    Just run the code, and see the result yourself :)

    Lucene.Net.Store.Directory dir = new RAMDirectory();
    Document doc = null;

    IndexWriter writer = new IndexWriter(dir, new
    WhitespaceAnalyzer(), true);

    doc = new Document();
    doc.Add(new Field("field", "a
    b",Field.Store.YES,Field.Index.ANALYZED));
    writer.AddDocument(doc);

    doc = new Document();
    doc.Add(new Field("field", "a", Field.Store.YES,
    Field.Index.ANALYZED));
    writer.AddDocument(doc);

    doc = new Document();
    doc.Add(new Field("field", "b", Field.Store.YES,
    Field.Index.ANALYZED));
    writer.AddDocument(doc);

    writer.Close();

    IndexReader rdr = Lucene.Net.Index.IndexReader.Open(dir);
    IndexSearcher src = new IndexSearcher(rdr);
    Query query1 = new QueryParser("field", new
    WhitespaceAnalyzer()).Parse("a -b");
    Query query2 = new QueryParser("field", new
    WhitespaceAnalyzer()).Parse("+a -b");
    TopDocs topdocs1 = src.Search(query1, 10);
    TopDocs topdocs2 = src.Search(query2, 10);


    DIGY

    -----Original Message-----
    From: Gustavo Poll
    Sent: Monday, July 25, 2011 10:55 PM
    To: lucene-net-user@lucene.apache.org
    Subject: [Lucene.Net] Simple Question: boolean operator shortcut

    Hi everyone,

    I've a simple question, but until now I couldn´t find the answer googling
    it... If you could help me, thanks so much...

    In the book Lucene in Action, this table is written:

    Table 3.7 Boolean query operator shortcuts

    Verbose syntax Shortcut syntax
    a AND b +a +b
    a OR b a b
    a AND NOT b +a -b


    Now I ask you: a - b will be also translated to a AND NOT b?


    Thanks!
    Gustavo Poll
  • Gustavo Poll at Jul 25, 2011 at 9:04 pm
    Ok...

    Conclusion:

    +a –b and a -b are both translated to a AND NOT b

    the plus sign in the first expression is not required...


    Thanks very much.


    2011/7/25 Digy <digydigy@gmail.com>
    Just run the code, and see the result yourself :)

    Lucene.Net.Store.Directory dir = new RAMDirectory();
    Document doc = null;

    IndexWriter writer = new IndexWriter(dir, new
    WhitespaceAnalyzer(), true);

    doc = new Document();
    doc.Add(new Field("field", "a
    b",Field.Store.YES,Field.Index.ANALYZED));
    writer.AddDocument(doc);

    doc = new Document();
    doc.Add(new Field("field", "a", Field.Store.YES,
    Field.Index.ANALYZED));
    writer.AddDocument(doc);

    doc = new Document();
    doc.Add(new Field("field", "b", Field.Store.YES,
    Field.Index.ANALYZED));
    writer.AddDocument(doc);

    writer.Close();

    IndexReader rdr = Lucene.Net.Index.IndexReader.Open(dir);
    IndexSearcher src = new IndexSearcher(rdr);
    Query query1 = new QueryParser("field", new
    WhitespaceAnalyzer()).Parse("a -b");
    Query query2 = new QueryParser("field", new
    WhitespaceAnalyzer()).Parse("+a -b");
    TopDocs topdocs1 = src.Search(query1, 10);
    TopDocs topdocs2 = src.Search(query2, 10);


    DIGY

    -----Original Message-----
    From: Gustavo Poll
    Sent: Monday, July 25, 2011 10:55 PM
    To: lucene-net-user@lucene.apache.org
    Subject: [Lucene.Net] Simple Question: boolean operator shortcut

    Hi everyone,

    I've a simple question, but until now I couldn´t find the answer googling
    it... If you could help me, thanks so much...

    In the book Lucene in Action, this table is written:

    Table 3.7 Boolean query operator shortcuts

    Verbose syntax Shortcut syntax
    a AND b +a +b
    a OR b a b
    a AND NOT b +a -b


    Now I ask you: a - b will be also translated to a AND NOT b?


    Thanks!
    Gustavo Poll

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouplucene-net-user @
categorieslucene
postedJul 25, '11 at 7:55p
activeJul 25, '11 at 9:04p
posts4
users3
websitelucene.apache.org

People

Translate

site design / logo © 2022 Grokbase