On Feb 11, 2008 8:51 PM, Ryan McKinley <[EMAIL PROTECTED]> wrote:
> Hello-
>
> I'm working on a SearchComponent that should limit results to entries
> within a geographic range.  I would love some feedback to make sure I'm
> not building silly queries and/or can change them to be better.  I have
> four fields:
>
>    <field name="north" type="sfloat" ... />
>    <field name="south" type="sfloat" ... />
>    <field name="east"  type="sfloat" ... />
>    <field name="west"  type="sfloat" ... />
>
> The component looks for a "bounds" argument and parses out the NSEW
> corners.  Currently, I'm building a boolean query and adding that to the
> filter list:
>
>        FieldType ft = req.getSchema().getFieldTypes().get( "sfloat" );
>
>        BooleanQuery range = new BooleanQuery( true );
>        range.add( new ConstantScoreRangeQuery( "north", null,
> ft.toInternal(n), true, true ), BooleanClause.Occur.MUST );
>        range.add( new ConstantScoreRangeQuery( "south",
> ft.toInternal(s), null, true, true ), BooleanClause.Occur.MUST );
>        range.add( new ConstantScoreRangeQuery( "east", null,
> ft.toInternal(e), true, true ), BooleanClause.Occur.MUST );
>        range.add( new ConstantScoreRangeQuery( "west", ft.toInternal(w),
> null, true, true ), BooleanClause.Occur.MUST );
>
> essentially, this is:
>   +north:[* TO nnn] +south:[sss TO *] +east:[* TO eee] +west:[www TO *]
>
>
> Would this be better as four individual filters?

Only if there were likely to occur again in combination with different
constraints.
My guess would be no.

Perhaps you want 2 fields (lat and long) instead of 4?

One issue here is range queries that include many terms are currently slow.
That's something we need to address sometime (there has been some work
on this in Lucene, but nothing yet committed AFAIK).

-Yonik

Reply via email to