Jts+lucene to achieve a simple perimeter search

Source: Internet
Author: User
Tags bitset

The realization idea is according to 文斌 to provide. The concept of the perimeter search implemented in this article is only a trivial part of the engine being implemented as a 文斌. Thank you for 文斌 's guidance here!

For a space based index, the first example of this idea in the sixth chapter of the Lucene in action is to illustrate how to use Lucene to find space information. The need to solve the problem is "what Mexican food restaurant are nearest to me?" The solution is to use the Lucene filter function. And my idea is this, is to provide a filter to the Lucene index file filtering.

Filtering as a mechanism to reduce the scope of Lucene search, the possible results are limited to one of all documents in a child set. An attribute that can be used to implement a search based on permissions and to search again in search results.

When it comes to concrete implementations, the key is that the filter itself is based on the logo bit setting.

The filter part implements the following code:

/** *//**
*
* @author Lang
* @date 2007-12-19
* @email lanfanss@126.com
* @desc provided with a certain space position to provide a    Filter
* @since
*
*/
public class Spatialfilter extends filter {
int lo;
int LA;
int scope;
Quadtree Quadtree;     
Public spatialfilter (int lo, int la, int scope, Quadtree quadtree) {
super ();
This.lo = lo;
this.la = LA;
This.scope = scope;
This.quadtree = Quadtree;
}
@Override
public bitset bits (Indexreader reader) throws IOException {
Final bitset bits = New Bitset (Reader.maxdoc ());     
//Set All documents cannot be retrieved
Bits.set (0, Bits.size ()-1, false);
     Judge scope, if unreasonable, using the default 500 m
if (scope <= 0) {
scope = +;
        
//currently using a simple rectangular box as a range search
list<string> ids = quadtree.query (New Envelope (The new coordinate (LO
-Scope, La-scope), new coordinate (lo + scope, la + scope));
for (String id:ids) {
//rectangle-scoped dots are
Bits.set (integer.valueof (IDs) that can be searched by Lucene). Intvalue (), TR UE);   
}
return bits;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.