Return-Path: X-Original-To: apmail-lucene-java-user-archive@www.apache.org Delivered-To: apmail-lucene-java-user-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C715018D1E for ; Mon, 11 Jan 2016 05:53:55 +0000 (UTC) Received: (qmail 23638 invoked by uid 500); 11 Jan 2016 05:53:54 -0000 Delivered-To: apmail-lucene-java-user-archive@lucene.apache.org Received: (qmail 23588 invoked by uid 500); 11 Jan 2016 05:53:54 -0000 Mailing-List: contact java-user-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: java-user@lucene.apache.org Delivered-To: mailing list java-user@lucene.apache.org Received: (qmail 23576 invoked by uid 99); 11 Jan 2016 05:53:54 -0000 Received: from Unknown (HELO spamd2-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 11 Jan 2016 05:53:54 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd2-us-west.apache.org (ASF Mail Server at spamd2-us-west.apache.org) with ESMTP id AF0D71A0923 for ; Mon, 11 Jan 2016 05:53:53 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd2-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: 2.9 X-Spam-Level: ** X-Spam-Status: No, score=2.9 tagged_above=-999 required=6.31 tests=[DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, HTML_MESSAGE=3, SPF_PASS=-0.001, URIBL_BLOCKED=0.001] autolearn=disabled Authentication-Results: spamd2-us-west.apache.org (amavisd-new); dkim=pass (2048-bit key) header.d=gmail.com Received: from mx1-us-east.apache.org ([10.40.0.8]) by localhost (spamd2-us-west.apache.org [10.40.0.9]) (amavisd-new, port 10024) with ESMTP id Iqd67aVQRUrl for ; Mon, 11 Jan 2016 05:53:43 +0000 (UTC) Received: from mail-io0-f176.google.com (mail-io0-f176.google.com [209.85.223.176]) by mx1-us-east.apache.org (ASF Mail Server at mx1-us-east.apache.org) with ESMTPS id 3BD4E43B61 for ; Mon, 11 Jan 2016 05:53:43 +0000 (UTC) Received: by mail-io0-f176.google.com with SMTP id 1so291921993ion.1 for ; Sun, 10 Jan 2016 21:53:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :content-type; bh=2tibq9PnbHNVXer45D5Selsi3lGueWiPApl0dsF4YUI=; b=HHctaKhDP1nWO+fFbPAiNFp9y+XfpeqDAeyOFI+Dtmf2teSx6RvfRCKXUA8ahhrlLE QZvk+XFYgE9F7OOIZ2J+PbHY1IliCt0n3LdO1wRLDJFRTnM8z/4qfwMBf96F56u9D9a7 Qld7XVAAI9O2UesKJ8qClB27mXFUkQWbR9HTKffMhu8RwY4i3VOp4PznhLBpdMZRHj2w bxg2Q+Z73ySpTyjZbbKk8yGx5GJyuUg6c6PzhfTH+GEWwyXlOQjL7UFcG35kLbfxQ7li qBVf9zZBfL+DWjn0nO408geY5qkJTM5vzqB5ksVkxPGpcy0rS8pY0XKkAZCYXDdxkl7Q 1utA== X-Received: by 10.107.34.201 with SMTP id i192mr69441724ioi.161.1452491622759; Sun, 10 Jan 2016 21:53:42 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: "david.w.smiley@gmail.com" Date: Mon, 11 Jan 2016 05:53:33 +0000 Message-ID: Subject: Re: [spatial] Indexing polygons? To: java-user@lucene.apache.org Content-Type: multipart/alternative; boundary=001a1140e10c36c1f50529088fe5 --001a1140e10c36c1f50529088fe5 Content-Type: text/plain; charset=UTF-8 Hi Robert, First, for the basics of the spatial module, see SpatialExample.java in the tests area. It doesn't include a polygon example but shows the concepts of a SpatialContext, Shape, and SpatialStrategy which are the key abstractions. The default SpatialContext implementation doesn't handle polygons -- not yet any way. So use JtsSpatialContext.GEO or some other configured variant created via JtsSpatialContextFactory and add JTS to your classpath (LGPL licensed, by the way). With that, you can create polygons parsed from WKT or GeoJSON -- see the SpatialContext.getFormats().getWktReader() for example. That'll produce a Shape instance parsed from a polygon WKT string you give it. Then re-aquaint yourself with SpatialExample.java to see how to index a Shape and how to query by a Shape. An important difference with the example is the choice of an appropriate SpatialStrategy. The example uses RecursivePrefixTreeStrategy which is best for points-only data; otherwise I recommend CompositeSpatialStrategy. I'm actively working on a SpatialContext implementation for "Geo3d" which will be another option. Your code wouldn't change other than choosing a different SpatialContext impl. By the way, the one-liner in your email I see you found in SpatialExample.java: doc.add(new StoredField(strategy.getFieldName, pt.getX + " " + pt.getY)) -- is purely for the "stored" version (for document retrieval in search results); not for indexing/search. See the comments preceding it ;-) Good luck. And sorry for leaving you hanging for a few days; I overlooked your email. ~ David On Wed, Jan 6, 2016 at 10:59 PM Robert Nix wrote: > Hi, > > Is there an example in the lucene-solr source to show how to index polygons > and how to search with and for indexed polys? I'm looking in > lucene/spatial/src/test/ and I see an example of a point and it seems > obvious: > > doc.add(new StoredField(strategy.getFieldName, pt.getX + " " + pt.getY)) > > But nothing regarding polygons is jumping out at me. If there isn't such an > example, can someone provide a short one? > > Thanks > -- > --nix > -- Lucene/Solr Search Committer, Consultant, Developer, Author, Speaker LinkedIn: http://linkedin.com/in/davidwsmiley | Book: http://www.solrenterprisesearchserver.com --001a1140e10c36c1f50529088fe5--