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 7DFF510898 for ; Sat, 7 Sep 2013 01:09:22 +0000 (UTC) Received: (qmail 38987 invoked by uid 500); 7 Sep 2013 01:09:20 -0000 Delivered-To: apmail-lucene-java-user-archive@lucene.apache.org Received: (qmail 38947 invoked by uid 500); 7 Sep 2013 01:09:20 -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 38939 invoked by uid 99); 7 Sep 2013 01:09:20 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 Sep 2013 01:09:20 +0000 X-ASF-Spam-Status: No, hits=2.5 required=5.0 tests=FREEMAIL_REPLY,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of eelstretching@gmail.com designates 209.85.219.46 as permitted sender) Received: from [209.85.219.46] (HELO mail-oa0-f46.google.com) (209.85.219.46) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 Sep 2013 01:09:15 +0000 Received: by mail-oa0-f46.google.com with SMTP id o20so4665235oag.33 for ; Fri, 06 Sep 2013 18:08:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=HzRf6rT9b5N3nsGl5rQ9w3j6y0aU/AgSRryf1jLwGH4=; b=dW7SbIHeY2vCj2Y56ZJAxFspniVCrD/UgQw9Bmi646KiB+YI2XrJV6srsUJGEZ6Tam PTwHEej/nIssxeG7/1FD6K7+tbKa6V0vByKLQRtpVTolZFpCxY9fdoqJ12j4PiJNd3qv tVJ4ibSQFhbQfekNZACqOxbRQYUYfuo29K29rGi11r2I07GvvYdu7Cae/RqvcYQDdjOA m5qKoUf9uGCMc2qnuebY2PlXkGXCi/jrgKoKhfgm4kL2ZmlAjdbwozbwKK3VjDgQ9ohn 9M/GhBtRcTOt2ZTWSVpJ518FN4+CeGA1GnMA13RauIYiMouPUaqCH7XQWKJpySAuLsc1 9uCQ== MIME-Version: 1.0 X-Received: by 10.60.40.67 with SMTP id v3mr4048294oek.16.1378516134969; Fri, 06 Sep 2013 18:08:54 -0700 (PDT) Received: by 10.60.14.138 with HTTP; Fri, 6 Sep 2013 18:08:54 -0700 (PDT) In-Reply-To: References: Date: Fri, 6 Sep 2013 21:08:54 -0400 Message-ID: Subject: Re: Lucene Concurrent Search From: Stephen Green To: "java-user@lucene.apache.org" Content-Type: multipart/alternative; boundary=089e0149ce4c8acc1e04e5c0cc0d X-Virus-Checked: Checked by ClamAV on apache.org --089e0149ce4c8acc1e04e5c0cc0d Content-Type: text/plain; charset=UTF-8 Mostly because it already handles all of the I sexing and querying that I expect you'll want to be doing and now with Solr Cloud you can ven scale search beyond one machine. If you're just looking to learn about this stuff, though, it is fun to roll your own! On Friday, September 6, 2013, David Miranda wrote: > Why use Solr instead of Lucene for this kind of application? > > > 2013/9/6 Stephen Green > > > Something like: > > > > public class SearchListener implements ServletContextListener { > > > > @Override > > public void contextInitialized(ServletContextEvent sce) { > > > > ServletContext sc = sce.getServletContext(); > > String indexDir = sc.getInitParameter("indexDir"); > > SearcherManager searcherManager = new > > SearcherManager(FSDirectory.open(new File(indexDir)), null); > > sc.setAttribute("searcherManager", searcherManager); > > } > > > > public void contextDestroyed(ServletContextEvent sce) { > > ServletContext sc = sce.getServletContext(); > > > > SearcherManager searcherManager = (SearcherManager) > > sc.getAttribute("searcherManager"); > > if(searcherManager != null) { > > try { > > searcherManager.close(); > > } catch(IOException ex) { > > logger.log(Level.SEVERE, String.format( > > "Error shutting down search engine"), ex); > > } > > } > > } > > } > > > > Usually does the trick. You need to put some parameters ("indexDir") > into > > your web.xml and make sure that it knows that SearchListener is a > > ServletListener for your Web app. > > > > But, to re-iterate what someone else said: if you really just want > RESTful > > search, you might be better off with Solr. > > > > > > > > On Thu, Sep 5, 2013 at 6:21 PM, David Miranda > >wrote: > > > > > Did you have a practical example of the use of SearchManager > (initialize, > > > use to do research)? > > > > > > Thanks in advance. > > > > > > > > > 2013/9/5 Stephen Green > > > > > > > You can implement a ServletListener for your app and open the index > > there > > > > (in the contextInitialized method). You can then create the > > > SearcherManager > > > > from the IndexReader/Searcher and store it in the ServletContext, > where > > > it > > > > can be fetched out by your REST servlets. > > > > > > > > This is a typical pattern that we use for lots of Web apps that use > > > > resources like Lucene. > > > > > > > > > > > > On Thu, Sep 5, 2013 at 12:05 PM, Ian Lea wrote: > > > > > > > > > I use a singleton class but there are other ways in tomcat. Can't > > > > > remember what - maybe application scope. > > > > > > > > > > > > > > > -- > > > > > Ian. > > > > > > > > > > > > > > > On Thu, Sep 5, 2013 at 4:46 PM, David Miranda < > > > david.b.miranda@gmail.com > > > > > > > > > > wrote: > > > > > > Where I can initialize the SearchManager variable to after use it > > in > > > > the > > > > > > REST servlet to do research in the index? > > > > > > > > > > > > > > > > > > 2013/9/5 Ian Lea > > > > > > > > > > > >> I think that blog post was bleeding edge and the API changed a > bit > > > > > >> subsequently. > > > > > >> > > > > > >> I use > > > > > >> > > > > > >> Directory dir = whatever; > > > > > >-- > Cumprimentos, > David Miranda > -- Stephen Green http://thesearchguy.wordpress.com --089e0149ce4c8acc1e04e5c0cc0d--