You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Mihai Caraman <ca...@gmail.com> on 2011/11/29 16:18:21 UTC

Quoted search on Analyzed fields

field = new Field("author",(author).toLowerCase(),Field.Store.NO,
Field.Index.NOT_ANALYZED);
            field.setIndexOptions(FieldInfo.IndexOptions.DOCS_ONLY);
            field.setOmitNorms(true);

When in the above configuration i switched from NOT_ANALYZED to ANALYZED,
luke's results for author:"john doe" stopped showing(after rebuilding the
index). Why?

Also, how can, on the same index, luke show me results for author:"john
doe"(using not_analyzed), but when i debug the IndexSearcher which receives
a query parsed with the same standardanalyzer as at indexing time(and seems
to be correct), returns no results?!

Thank you,
Mihai C.

Re: Quoted search on Analyzed fields

Posted by Robert Muir <rc...@gmail.com>.
Again there is nothing wrong with the quotes: its instead how you are
configuring the analysis for this field.

If you put stuff in quotes and your analyzer breaks it into multiple
tokens, then queryparser forms a phrase query. You must index
positions to support phrase queries.

Normally DOCS_ONLY is only used for fields that contain a *single
term*, like a numeric field. If you want to exclude positions for a
field but at the same time allow tokenized queries against it like you
are doing, then you need to adjust your queryparsing to do the right
thing if someone enters quoted text like "john doe", such as forming a
boolean query (john AND doe) instead.

The way to do this is to subclass the queryparser and do something like:
@Override
protected Query getFieldQuery(String field, String queryText, boolean
quoted)  throws ParseException {
 if (quoted && field.equals("myfieldwithoutpositions") {
    // my special logic to form boolean queries or something else
 } else {
    return super.getFieldQuery(field, queryText, quoted);
 }
}


On Tue, Nov 29, 2011 at 10:58 AM, Mihai Caraman <ca...@gmail.com> wrote:
> Still no difference, it may be because of some other hidden
> bug.<ja...@lucene.apache.org>Anyway, adding freq and
> positions will be a no - no because of space :) so
> bye bye quotes.
>
> Thank you
>



-- 
lucidimagination.com

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Quoted search on Analyzed fields

Posted by Mihai Caraman <ca...@gmail.com>.
Still no difference, it may be because of some other hidden
bug.<ja...@lucene.apache.org>Anyway, adding freq and
positions will be a no - no because of space :) so
bye bye quotes.

Thank you

Re: Quoted search on Analyzed fields

Posted by Robert Muir <rc...@gmail.com>.
if you use standardanalyzer it will break "john doe" into 2 tokens and
form a phrase query.
if you want to do phrase queries, don't set the indexoptions to
DOCS_ONLY. otherwise they won't work.

if what you want is for "john doe" to only be 1 term without
positions, then use KeywordAnalyzer, and DOCS_ONLY is then ok because
you don't need any positions.

On Tue, Nov 29, 2011 at 10:18 AM, Mihai Caraman <ca...@gmail.com> wrote:
> field = new Field("author",(author).toLowerCase(),Field.Store.NO,
> Field.Index.NOT_ANALYZED);
>            field.setIndexOptions(FieldInfo.IndexOptions.DOCS_ONLY);
>            field.setOmitNorms(true);
>
> When in the above configuration i switched from NOT_ANALYZED to ANALYZED,
> luke's results for author:"john doe" stopped showing(after rebuilding the
> index). Why?
>
> Also, how can, on the same index, luke show me results for author:"john
> doe"(using not_analyzed), but when i debug the IndexSearcher which receives
> a query parsed with the same standardanalyzer as at indexing time(and seems
> to be correct), returns no results?!
>
> Thank you,
> Mihai C.
>



-- 
lucidimagination.com

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org