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 Harald Kirsch <Ha...@raytion.com> on 2013/11/13 16:03:51 UTC

default or cascaded fallback query

Hello all,

I wonder if a query according to the following rules is possible.

We have several fields with increasing hierarchy, say f_0 to f_{2n}. The 
rule to search for a term is that starting with index 0 the first field 
to contain a hit defines whether to return the document or not, i.e.:

If Field f_{2i} contains the term -> return the document, don't look at 
further fields f_j with j>2i

If Field f_{2i+1} contains the term -> do not return the document and 
don't look at further fields f_j with j>2i+1

I call this cascaded fallback query, because each field f_{i+1} is kind 
of a fallback for the case that no field before it contained any 
explicit information for the term. If it were not for the fields with 
the negative information, I could just use a big OR over all the fields, 
but with negation this does not work.

Due to the algorithmic rather than plain boolean (set theoretic) 
function to be computed, I have the impression that just creating query 
objects the right way would not work, in particular given that at query 
time I cannot be sure about the size of n, so I don't know how many 
fields to include in the query.

I would even dare to dig deep down into the place where terms are 
matched agains fields in Lucene. I had a look already at the source code 
of IndexSearcher but could not really spot the place where terms are 
matched. But I may be looking at the wrong place.

Any hints appreciated,
Harald.



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


Re: default or cascaded fallback query

Posted by Michael Sokolov <ms...@safaribooksonline.com>.
It sounds as if you want to create a new Query type.  I would start by 
having a look at BooleanQuery and trying to write an analogous object 
that does what you want instead.

-Mike

On 11/13/2013 10:03 AM, Harald Kirsch wrote:
> Hello all,
>
> I wonder if a query according to the following rules is possible.
>
> We have several fields with increasing hierarchy, say f_0 to f_{2n}. 
> The rule to search for a term is that starting with index 0 the first 
> field to contain a hit defines whether to return the document or not, 
> i.e.:
>
> If Field f_{2i} contains the term -> return the document, don't look 
> at further fields f_j with j>2i
>
> If Field f_{2i+1} contains the term -> do not return the document and 
> don't look at further fields f_j with j>2i+1
>
> I call this cascaded fallback query, because each field f_{i+1} is 
> kind of a fallback for the case that no field before it contained any 
> explicit information for the term. If it were not for the fields with 
> the negative information, I could just use a big OR over all the 
> fields, but with negation this does not work.
>
> Due to the algorithmic rather than plain boolean (set theoretic) 
> function to be computed, I have the impression that just creating 
> query objects the right way would not work, in particular given that 
> at query time I cannot be sure about the size of n, so I don't know 
> how many fields to include in the query.
>
> I would even dare to dig deep down into the place where terms are 
> matched agains fields in Lucene. I had a look already at the source 
> code of IndexSearcher but could not really spot the place where terms 
> are matched. But I may be looking at the wrong place.
>
> Any hints appreciated,
> Harald.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>


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


Re: default or cascaded fallback query

Posted by Harald Kirsch <Ha...@raytion.com>.
Hmm, this needs some digging into as it seems. I must admit that by 
looking over the code I get yet not idea where the real matching of 
terms against the index happens.

If someone could point to the place in the code where the core test of a 
term against the index is, that would help a lot. Or is there some 
online descriptions somewhere.

Thanks,
Harald.


Michael Sokolov-3 answered (lost his answer, copied from archive)

It sounds as if you want to create a new Query type.  I would start by
having a look at BooleanQuery and trying to write an analogous object
that does what you want instead.


On 13.11.2013 16:03, Harald Kirsch wrote:
> Hello all,
>
> I wonder if a query according to the following rules is possible.
>
> We have several fields with increasing hierarchy, say f_0 to f_{2n}. The
> rule to search for a term is that starting with index 0 the first field
> to contain a hit defines whether to return the document or not, i.e.:
>
> If Field f_{2i} contains the term -> return the document, don't look at
> further fields f_j with j>2i
>
> If Field f_{2i+1} contains the term -> do not return the document and
> don't look at further fields f_j with j>2i+1
>
> I call this cascaded fallback query, because each field f_{i+1} is kind
> of a fallback for the case that no field before it contained any
> explicit information for the term. If it were not for the fields with
> the negative information, I could just use a big OR over all the fields,
> but with negation this does not work.
>
> Due to the algorithmic rather than plain boolean (set theoretic)
> function to be computed, I have the impression that just creating query
> objects the right way would not work, in particular given that at query
> time I cannot be sure about the size of n, so I don't know how many
> fields to include in the query.
>
> I would even dare to dig deep down into the place where terms are
> matched agains fields in Lucene. I had a look already at the source code
> of IndexSearcher but could not really spot the place where terms are
> matched. But I may be looking at the wrong place.
>
> Any hints appreciated,
> Harald.
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

-- 
Harald Kirsch
Raytion GmbH
Kaiser-Friedrich-Ring 74
40547 Duesseldorf
Fon +49-211-550266-0
Fax +49-211-550266-19
http://www.raytion.com

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