lucene-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Doug Cutting <cutt...@apache.org>
Subject Re: Lucene Search Applet
Date Mon, 23 Aug 2004 17:51:46 GMT
[ Moved to lucene-dev. ]

Perhaps we should first look for these in a lucene properties file that 
is found on the classpath with Classloader.getResource().  Then an 
applet can just include a different properties file to override these. 
The file could be something like "org/apache/lucene/lucene.properties". 
  We could even include versions of the file designed for applet use, 
for read-only use (e.g., CDROM), etc.

Doug

Jon Schuster wrote:
> Hi all,
> 
> The changes I made to get past the System.getProperty issues are essentially
> the same in the three files org.apache.lucene.index.IndexWriter,
> org.apache.lucene.store.FSDirectory, and
> org.apache.lucene.search.BooleanQuery.
> 
> Change the static initializations from a form like this:
> 
>   public static long WRITE_LOCK_TIMEOUT = 
>  
> Integer.parseInt(System.getProperty("org.apache.lucene.writeLockTimeout",
>       "1000"));
> 
> to a separate declaration and static initializer block like this:
> 
>    public static long WRITE_LOCK_TIMEOUT;
>    static
>    {
> 	try
> 	{
>                 WRITE_LOCK_TIMEOUT =
> Integer.parseInt(System.getProperty("org.apache.lucene.writeLockTimeout",
> "1000"));
> 	}
> 	catch ( Exception e )
> 	{
> 	    WRITE_LOCK_TIMEOUT = 1000;
> 	}
>    };
> 
> As before, the variables are initialized when the class is loaded, but if
> the System.getProperty fails, the variable still gets initialized to its
> default value in the catch block.
> 
> You can use a separate static block for each variable, or put them all into
> a single static block. You could also add a setter for each variable if you
> want the ability to set the value separately from the class init.
> 
> In the FSDirectory class, the variables DISABLE_LOCKS and LOCK_DIR are
> marked final, which I had to remove to do the initialization as described.
> 
> I've also attached the three modified files if you want to just copy and
> paste.
> 
> --Jon
> 
> -----Original Message-----
> From: Simon mcIlwaine [mailto:smcilwaine@lendac.ie] 
> Sent: Monday, August 23, 2004 7:37 AM
> To: Lucene Users List
> Subject: Re: Lucene Search Applet
> 
> 
> Hi,
> 
> Just used the RODirectory and I'm now getting the following error:
> java.security.AccessControlException: access denied
> (java.util.PropertyPermission user.dir read) I'm reckoning that this is what
> Jon was on about with System.getProperty() within certain files because im
> using an applet. Is this correct and if so can someone show me one of the
> hacked files so that I know what I need to modify.
> 
> Many Thanks
> 
> Simon
> .
> ----- Original Message -----
> From: "Simon mcIlwaine" <smcilwaine@lendac.ie>
> To: "Lucene Users List" <lucene-user@jakarta.apache.org>
> Sent: Monday, August 23, 2004 3:12 PM
> Subject: Re: Lucene Search Applet
> 
> 
>>Hi Stephane,
>>
>>A bit of a stupid question but how do you mean set the system property
>>disableLuceneLocks=true? Can I do it from a call from FSDirectory API or
> 
> do
> 
>>I have to actually hack the code? Also if I do use RODirectory how do I go
>>about using it? Do I have to update the Lucene JAR archive file with
>>RODirectory class included as I tried using it and its not recognising the
>>class?
>>
>>Many Thanks
>>
>>Simon
>>
>>----- Original Message -----
>>From: "Stephane James Vaucher" <vauchers@cirano.qc.ca>
>>To: "Lucene Users List" <lucene-user@jakarta.apache.org>
>>Sent: Monday, August 23, 2004 2:22 PM
>>Subject: Re: Lucene Search Applet
>>
>>
>>
>>>Hi Simon,
>>>
>>>Does this work? From FSDirectory api:
>>>
>>>If the system property 'disableLuceneLocks' has the String value of
>>>"true", lock creation will be disabled.
>>>
>>>Otherwise, I think there was a Read-Only Directory hack:
>>>
>>>http://www.mail-archive.com/lucene-user@jakarta.apache.org/msg05148.html
>>>
>>>HTH,
>>>sv
>>>
>>>On Mon, 23 Aug 2004, Simon mcIlwaine wrote:
>>>
>>>
>>>>Thanks Jon that works by putting the jar file in the archive
> 
> attribute.
> 
>>Now
>>
>>>>im getting the disablelock error cause of the unsigned applet. Do I
> 
> just
> 
>>>>comment out the code anywhere where System.getProperty() appears in
> 
> the
> 
>>>>files that you specified and then update the JAR Archive?? Is it
>>
>>possible
>>
>>>>you could show me one of the hacked files so that I know what I'm
>>
>>modifying?
>>
>>>>Does anyone else know if there is another way of doing this without
>>
>>having
>>
>>>>to hack the source code?
>>>>
>>>>Many thanks.
>>>>
>>>>Simon
>>>>
>>>>----- Original Message -----
>>>>From: "Jon Schuster" <jons@wrq.com>
>>>>To: "Lucene Users List" <lucene-user@jakarta.apache.org>
>>>>Sent: Saturday, August 21, 2004 2:08 AM
>>>>Subject: Re: Lucene Search Applet
>>>>
>>>>
>>>>
>>>>>I have Lucene working in an applet and I've seen this problem only
>>
>>when
>>
>>>>>the jar file really was not available (typo in the jar name), which
> 
> is
> 
>>>>>what you'd expect. It's possible that the classpath for your
>>>>>application is not the same as the classpath for the applet; perhaps
>>>>>they're using different VMs or JREs from different locations.
>>>>>
>>>>>Try referencing the Lucene jar file in the archive attribute of the
>>>>>applet tag.
>>>>>
>>>>>Also, to get Lucene to work from an unsigned applet, I had to modify
> 
> a
> 
>>>>>few classes that call System.getProperty(), because the properties
>>
>>that
>>
>>>>>were being requested were disallowed for applets. I think the
> 
> classes
> 
>>>>>were IndexWriter, FSDirectory, and BooleanQuery.
>>>>>
>>>>>--Jon
>>>>>
>>>>>
>>>>>On Aug 20, 2004, at 6:57 AM, Simon mcIlwaine wrote:
>>>>>
>>>>>
>>>>>>Im a new Lucene User and I'm not too familiar with Applets either
>>
>>but
>>
>>>>>>I've
>>>>>>been doing a bit of testing on java applet security and if im
>>
>>correct
>>
>>>>>>in
>>>>>>saying that applets can read anything below there codebase then my
>>>>>>problem
>>>>>>is not a security restriction one. The error is reading
>>>>>>java.lang.NoClassDefFoundError and the classpath is set as I have
> 
> it
> 
>>>>>>working
>>>>>>in a Swing App. Does someone actually have Lucene working in an
>>>>>>Applet? Can
>>>>>>it be done?? Please help.
>>>>>>
>>>>>>Thanks
>>>>>>
>>>>>>Simon
>>>>>>
>>>>>>----- Original Message -----
>>>>>>
>>>>>>From: "Terry Steichen" <terry@net-frame.com>
>>>>>>To: "Lucene Users List" <lucene-user@jakarta.apache.org>
>>>>>>Sent: Wednesday, August 18, 2004 4:17 PM
>>>>>>Subject: Re: Lucene Search Applet
>>>>>>
>>>>>>
>>>>>>I suspect it has to do with the security restrictions of the
> 
> applet,
> 
>>>>>>'cause
>>>>>>it doesn't appear to be finding your Lucene jar file.  Also,
>>
>>regarding
>>
>>>>>>the
>>>>>>lock files, I believe you can disable the locking stuff just for
>>>>>>purposes
>>>>>>like yours (read-only index).
>>>>>>
>>>>>>Regards,
>>>>>>
>>>>>>Terry
>>>>>>  ----- Original Message -----
>>>>>>  From: Simon mcIlwaine
>>>>>>  To: Lucene Users List
>>>>>>  Sent: Wednesday, August 18, 2004 11:03 AM
>>>>>>  Subject: Lucene Search Applet
>>>>>>
>>>>>>
>>>>>>  Im developing a Lucene CD-ROM based search which will search
> 
> html
> 
>>>>>>pages on
>>>>>>CD-ROM, using an applet as the UI. I know that theres a problem
> 
> with
> 
>>>>>>lock
>>>>>>files and also security restrictions on applets so I am using the
>>>>>>RAMDirectory. I have it working in a Swing application however
> 
> when
> 
>>I
>>
>>>>>>put it
>>>>>>into an applet its giving me problems. It compiles but when I go
> 
> to
> 
>>>>>>run the
>>>>>>applet I get the error below. Can anyone help? Thanks in advance.
>>>>>>  Simon
>>>>>>
>>>>>>  Error:
>>>>>>
>>>>>>  Java.lang.noClassDefFoundError:
> 
> org/apache/lucene/store/Directory
> 
>>>>>>  At: Java.lang.Class.getDeclaredConstructors0(Native Method)
>>>>>>
>>>>>>  At:
>>
>>Java.lang.Class.privateGetDeclaredConstructors(Class.java:1610)
>>
>>>>>>  At: Java.lang.Class.getConstructor0(Class.java:1922)
>>>>>>
>>>>>>  At: Java.lang.Class.newInstance0(Class.java:278)
>>>>>>
>>>>>>  At: Java.lang.Class.newInstance(Class.java:261)
>>>>>>
>>>>>>  At: sun.applet.AppletPanel.createApplet(AppletPanel.java:617)
>>>>>>
>>>>>>  At: sun.applet.AppletPanel.runloader(AppletPanel.java:546)
>>>>>>
>>>>>>  At: sun.applet.AppletPanel.run(AppletPanel.java:298)
>>>>>>
>>>>>>  At: java.lang.Thread.run(Thread.java:534)
>>>>>>
>>>>>>  Code:
>>>>>>
>>>>>>  import org.apache.lucene.search.IndexSearcher;
>>>>>>
>>>>>>  import org.apache.lucene.search.Query;
>>>>>>
>>>>>>  import org.apache.lucene.search.TermQuery;
>>>>>>
>>>>>>  import org.apache.lucene.store.RAMDirectory;
>>>>>>
>>>>>>  import org.apache.lucene.store.Directory;
>>>>>>
>>>>>>  import org.apache.lucene.index.Term;
>>>>>>
>>>>>>  import org.apache.lucene.search.Hits;
>>>>>>
>>>>>>  import java.awt.*;
>>>>>>
>>>>>>  import java.awt.event.*;
>>>>>>
>>>>>>  import javax.swing.*;
>>>>>>
>>>>>>  import java.io.*;
>>>>>>
>>>>>>  public class MemorialApp2 extends JApplet implements
>>
>>ActionListener{
>>
>>>>>>  JLabel prompt;
>>>>>>
>>>>>>  JTextField input;
>>>>>>
>>>>>>  JButton search;
>>>>>>
>>>>>>  JPanel panel;
>>>>>>
>>>>>>  String indexDir = "C:/Java/lucene/index-list";
>>>>>>
>>>>>>  private static RAMDirectory idx;
>>>>>>
>>>>>>  public void init(){
>>>>>>
>>>>>>  Container cp = getContentPane();
>>>>>>
>>>>>>  panel = new JPanel();
>>>>>>
>>>>>>  panel.setLayout(new FlowLayout(FlowLayout.CENTER, 4, 4));
>>>>>>
>>>>>>  prompt = new JLabel("Keyword search:");
>>>>>>
>>>>>>  input = new JTextField("",20);
>>>>>>
>>>>>>  search = new JButton("Search");
>>>>>>
>>>>>>  search.addActionListener(this);
>>>>>>
>>>>>>  panel.add(prompt);
>>>>>>
>>>>>>  panel.add(input);
>>>>>>
>>>>>>  panel.add(search);
>>>>>>
>>>>>>  cp.add(panel);
>>>>>>
>>>>>>  }
>>>>>>
>>>>>>  public void actionPerformed(ActionEvent e){
>>>>>>
>>>>>>  if (e.getSource() == search){
>>>>>>
>>>>>>  String surname = (input.getText());
>>>>>>
>>>>>>  try {
>>>>>>
>>>>>>  findSurname(indexDir, surname);
>>>>>>
>>>>>>  } catch(Exception ex) {
>>>>>>
>>>>>>  System.err.println(ex);
>>>>>>
>>>>>>  }
>>>>>>
>>>>>>  }
>>>>>>
>>>>>>  }
>>>>>>
>>>>>>  public static void findSurname(String indexDir, String surname)
>>>>>>throws
>>>>>>Exception{
>>>>>>
>>>>>>  idx = new RAMDirectory(indexDir);
>>>>>>
>>>>>>  IndexSearcher searcher = new IndexSearcher(idx);
>>>>>>
>>>>>>  Query query = new TermQuery(new Term("surname", surname));
>>>>>>
>>>>>>  Hits hits = searcher.search(query);
>>>>>>
>>>>>>  for (int i = 0; i < hits.length(); i++) {
>>>>>>
>>>>>>  //Document doc = hits.doc(i);
>>>>>>
>>>>>>  System.out.println("Surname: " + hits.doc(i).get("surname"));
>>>>>>
>>>>>>  }
>>>>>>
>>>>>>  }
>>>>>>
>>>>>>  }
>>>>>>
>>>>>>
>>>>>>
>>>>>
>>>---------------------------------------------------------------------
>>>
>>>>>>To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
>>>>>>For additional commands, e-mail:
> 
> lucene-user-help@jakarta.apache.org
> 
>>>>>
>>---------------------------------------------------------------------
>>
>>>>>To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
>>>>>For additional commands, e-mail: lucene-user-help@jakarta.apache.org
>>>>>
>>>>>
>>>>
>>>>
>>>>
>>>>---------------------------------------------------------------------
>>>>To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
>>>>For additional commands, e-mail: lucene-user-help@jakarta.apache.org
>>>>
>>>
>>>
>>>---------------------------------------------------------------------
>>>To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
>>>For additional commands, e-mail: lucene-user-help@jakarta.apache.org
>>>
>>>
>>
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
>>For additional commands, e-mail: lucene-user-help@jakarta.apache.org
>>
>>
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-user-help@jakarta.apache.org
> 
> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: lucene-user-help@jakarta.apache.org

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


Mime
View raw message