lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tri Cao <tm...@me.com>
Subject Re: Lucene Query
Date Tue, 19 Aug 2014 20:05:23 GMT
OR operator does that, AND only returns docs with ALL terms present.

Note that you have two options here
1. Create a BooleanQuery object (see the Java doc I linked below) and programatically
add the term queries with the following constraint:
http://lucene.apache.org/core/4_6_0/core/org/apache/lucene/search/BooleanClause.Occur.html#MUST_NOT

2. Use Lucene classic QueryParser and pass in the query string "states AND america AND united"

I would suggest 1) if you are going to learn more about Lucene, and 2) if you are just want
to get some thing out.

Hope this helps,
Tri

On Aug 19, 2014, at 12:17 PM, Jin Guang Zheng <zhengj3@rpi.edu> wrote:

Thanks for reply, but won't BooleanQuery return both doc1 and doc2 with
query:

label:States AND label:America AND label:United

Best,
Jin


On Tue, Aug 19, 2014 at 2:07 PM, Tri Cao <tmcao@me.com      > wrote:

        > given that example, the easy way is a boolean AND query of all the terms:
        >
        >
        > http://lucene.apache.org/core/4_6_0/core/org/apache/lucene/search/BooleanQuery.html
        >
        > However, if your corpus is more sophisticated you'll find that relevance
        > ranking is not always that trivial :)
        >
        > On Aug 19, 2014, at 11:00 AM, Jin Guang Zheng <zhengj3@rpi.edu    >
wrote:
        >
        > Hi,
        >
        > I am wondering if someone can help me on this:
        >
        > I have index:
        >
        > doc 1 -- label: United States of America
        >
        > doc 2 -- label: United
        > doc 2 -- label: America
        > doc 2 -- label: States
        >
        > I am wondering how to generate a query with terms: states united america
        >
        > so only doc 1 returns.
        >
        >
        > I was thinking SpanNearQuery, but can't make it work.
        >
        > Thanks,
        > Jin
        >
        >

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
    • Unnamed multipart/related (inline, None, 0 bytes)
View raw message