You are viewing a plain text version of this content. The canonical link for it is here.
Posted to general@lucene.apache.org by ravishekhar <ra...@gmail.com> on 2011/05/18 10:10:52 UTC

Writing new peice of code in Lucene

Hi,

 I am new to Lucene. I am able to run demo code given. 
 I wrote my code for training and searching based on some simple
modification. 
 I have put that files in lucene-3.0.3/src/demo/org/apache/lucene/demo and
tried to run as I run the demo file by just giving name of my files. 

 I used netbeans for the same and I am able to do the same, validating my
program is correct.
 I want to run the code through command line as done in case of demo
program. 

 Please let me know how to do this. 

 Thanks, 
 Ravi 

--
View this message in context: http://lucene.472066.n3.nabble.com/Writing-new-peice-of-code-in-Lucene-tp2956161p2956161.html
Sent from the Lucene - General mailing list archive at Nabble.com.

Re: Writing new peice of code in Lucene

Posted by Anurag <an...@gmail.com>.
1. Do you know , why u are getting the first error. You should find it?
Learn Java. The File in which the program is should be saved with the same
name of public  class, that is file should be saved as HelloLucene.java(not
Hello.java)
2. use lucene 2.9.1

On Thu, May 19, 2011 at 12:03 AM, ravishekhar [via Lucene] <
ml-node+2958052-1222437878-146354@n3.nabble.com> wrote:

> Hi,
>
>  I am getting following errors:
>
> ravi@ravi-desktop:~/Desktop/sw/lucene-3.0.3$ javac -Xlint -cp
> lucene-core-3.0.3.jar Hello.java
> Hello.java:19: class HelloLucene is public, should be declared in a file
> named HelloLucene.java
> public class HelloLucene {
>        ^
> Hello.java:23: cannot find symbol
> symbol  : constructor StandardAnalyzer()
> location: class org.apache.lucene.analysis.standard.StandardAnalyzer
>     IndexWriter w = new IndexWriter(index, new StandardAnalyzer(), true,
> new MaxFieldLength(250));
>                                            ^
> Hello.java:33: cannot find symbol
> symbol  : constructor StandardAnalyzer()
> location: class org.apache.lucene.analysis.standard.StandardAnalyzer
>     Query q = new QueryParser("title", new
> StandardAnalyzer()).parse(querystr);
>                                        ^
> Hello.java:33: internal error; cannot instantiate
> org.apache.lucene.queryParser.QueryParser.<init> at
> org.apache.lucene.queryParser.QueryParser to ()
>     Query q = new QueryParser("title", new
> StandardAnalyzer()).parse(querystr);
>               ^
> 4 errors
>
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://lucene.472066.n3.nabble.com/Writing-new-peice-of-code-in-Lucene-tp2956161p2958052.html
>  To start a new topic under Lucene - General, email
> ml-node+642108-1580214077-146354@n3.nabble.com
> To unsubscribe from Lucene - General, click here<http://lucene.472066.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=642108&code=YW51cmFnLml0LmpvbGx5QGdtYWlsLmNvbXw2NDIxMDh8LTIwOTgzNDQxOTY=>.
>
>



-- 
Kumar Anurag


-----
Kumar Anurag

--
View this message in context: http://lucene.472066.n3.nabble.com/Writing-new-peice-of-code-in-Lucene-tp2956161p2960159.html
Sent from the Lucene - General mailing list archive at Nabble.com.

Re: Writing new peice of code in Lucene

Posted by ravishekhar <ra...@gmail.com>.
Hi, 

 I am getting following errors: 

ravi@ravi-desktop:~/Desktop/sw/lucene-3.0.3$ javac -Xlint -cp
lucene-core-3.0.3.jar Hello.java
Hello.java:19: class HelloLucene is public, should be declared in a file
named HelloLucene.java
public class HelloLucene {
       ^
Hello.java:23: cannot find symbol
symbol  : constructor StandardAnalyzer()
location: class org.apache.lucene.analysis.standard.StandardAnalyzer
    IndexWriter w = new IndexWriter(index, new StandardAnalyzer(), true, new
MaxFieldLength(250));
                                           ^
Hello.java:33: cannot find symbol
symbol  : constructor StandardAnalyzer()
location: class org.apache.lucene.analysis.standard.StandardAnalyzer
    Query q = new QueryParser("title", new
StandardAnalyzer()).parse(querystr);
                                       ^
Hello.java:33: internal error; cannot instantiate
org.apache.lucene.queryParser.QueryParser.<init> at
org.apache.lucene.queryParser.QueryParser to ()
    Query q = new QueryParser("title", new
StandardAnalyzer()).parse(querystr);
              ^
4 errors


--
View this message in context: http://lucene.472066.n3.nabble.com/Writing-new-peice-of-code-in-Lucene-tp2956161p2958052.html
Sent from the Lucene - General mailing list archive at Nabble.com.

Re: Writing new peice of code in Lucene

Posted by Anurag <an...@gmail.com>.
Fibd my File attached

Can you please describe ur error? It will help us in finding the mistake
that u may be doing.

compiling and running HelloLucene.java is similar as compiling and running
any other java . HelloLucene uses Lucene class files , so it is needed in
classpath

My compilation and run(using commandline to set the classpath) -> try it
*compile-*>
$javac -Xlint -cp /home/anurag/lucene-2.9.1/lucene-core-2.9.1.jar
HelloLucene.java
output:
HelloLucene.java:23: warning: [deprecation] StandardAnalyzer() in
org.apache.lucene.analysis.standard.StandardAnalyzer has been deprecated
    IndexWriter w = new IndexWriter(index, new StandardAnalyzer(), true, new
MaxFieldLength(250));
                                           ^
HelloLucene.java:33: warning: [deprecation] StandardAnalyzer() in
org.apache.lucene.analysis.standard.StandardAnalyzer has been deprecated
    Query q = new QueryParser("title", new
StandardAnalyzer()).parse(querystr);
                                       ^
HelloLucene.java:33: warning: [deprecation]
QueryParser(java.lang.String,org.apache.lucene.analysis.Analyzer) in
org.apache.lucene.queryParser.QueryParser has been deprecated
    Query q = new QueryParser("title", new
StandardAnalyzer()).parse(querystr);
              ^
HelloLucene.java:36: warning: [deprecation]
IndexSearcher(org.apache.lucene.store.Directory) in
org.apache.lucene.search.IndexSearcher has been deprecated
    IndexSearcher s = new IndexSearcher(index);

*run->*
$java HelloLucene
output:
Found 2 hits.
1. Document<stored/uncompressed,indexed,tokenized<title:Lucene in Action>>
2. Document<stored/uncompressed,indexed,tokenized<title:Lucene for Dummies>>

Note: I am attaching my HelloLucene.java( try it)


On Wed, May 18, 2011 at 8:26 PM, ravishekhar [via Lucene] <
ml-node+2957248-2072374620-146354@n3.nabble.com> wrote:

> Hi,
>
>  Ya I am using Ubuntu.
>  I think ClassPath  is set properly else how I am able to run Demo code
> with Lucene.
>  Also I am able to run my written code through Netbeans too.
>
>  Can you please tell me I have that  " HelloLucene.java " program.
>  How to compile and run it.
>
> Thanks,
> Ravi.
>
> ------------------------------
>  If you reply to this email, your message will be added to the discussion
> below:
>
> http://lucene.472066.n3.nabble.com/Writing-new-peice-of-code-in-Lucene-tp2956161p2957248.html
>  To start a new topic under Lucene - General, email
> ml-node+642108-1580214077-146354@n3.nabble.com
> To unsubscribe from Lucene - General, click here<http://lucene.472066.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=642108&code=YW51cmFnLml0LmpvbGx5QGdtYWlsLmNvbXw2NDIxMDh8LTIwOTgzNDQxOTY=>.
>
>



-- 
Kumar Anurag


-----
Kumar Anurag

--
View this message in context: http://lucene.472066.n3.nabble.com/Writing-new-peice-of-code-in-Lucene-tp2956161p2958035.html
Sent from the Lucene - General mailing list archive at Nabble.com.

Re: Writing new peice of code in Lucene

Posted by ravishekhar <ra...@gmail.com>.
Hi, 

 Ya I am using Ubuntu. 
 I think ClassPath  is set properly else how I am able to run Demo code with
Lucene. 
 Also I am able to run my written code through Netbeans too. 

 Can you please tell me I have that  " HelloLucene.java " program. 
 How to compile and run it. 

Thanks, 
Ravi. 

--
View this message in context: http://lucene.472066.n3.nabble.com/Writing-new-peice-of-code-in-Lucene-tp2956161p2957248.html
Sent from the Lucene - General mailing list archive at Nabble.com.

Re: Writing new peice of code in Lucene

Posted by Anurag <an...@gmail.com>.
which os u are using? it it linux?
Setting the classpath free you from saving the file anywhere..........

The error shows that u have not set the proper classpath.

On 5/18/11, ravishekhar [via Lucene]
<ml...@n3.nabble.com> wrote:
>
>
>  Hi,
>
>  Thanks for the code.
>  But still my problem is not solved.
>  First of all where to put the code (i.e HelloLucene.java ).
>  I have put it in lucene-3.0.3/src/demo/org/apache/lucene/demo
>  Then to run I am doing  java org.apache.lucene.demo.HelloLucene.
>
>  Even it did javac HelloLucene.java but getting error.
>
>  My classpath is set i.e.
>                 /usr/lib/jvm/java-6-sun/lib:
>                /home/ravi/Desktop/sw/lucene-3.0.3/lucene-core-3.0.3.jar:
>               /home/ravi/Desktop/sw/lucene-3.0.3/lucene-demos-3.0.3.jar
>
>
>
>
> _______________________________________________
> If you reply to this email, your message will be added to the discussion
> below:
> http://lucene.472066.n3.nabble.com/Writing-new-peice-of-code-in-Lucene-tp2956161p2956458.html
> To start a new topic under Lucene - General, email
> ml-node+642108-1580214077-146354@n3.nabble.com
> To unsubscribe from Lucene - General, visit
> http://lucene.472066.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=642108&code=YW51cmFnLml0LmpvbGx5QGdtYWlsLmNvbXw2NDIxMDh8LTIwOTgzNDQxOTY=


-- 
Kumar Anurag


-----
Kumar Anurag

--
View this message in context: http://lucene.472066.n3.nabble.com/Writing-new-peice-of-code-in-Lucene-tp2956161p2956832.html
Sent from the Lucene - General mailing list archive at Nabble.com.

Re: Writing new peice of code in Lucene

Posted by ravishekhar <ra...@gmail.com>.
 Hi, 

 Thanks for the code. 
 But still my problem is not solved. 
 First of all where to put the code (i.e HelloLucene.java ). 
 I have put it in lucene-3.0.3/src/demo/org/apache/lucene/demo
 Then to run I am doing  java org.apache.lucene.demo.HelloLucene. 

 Even it did javac HelloLucene.java but getting error. 

 My classpath is set i.e.  
                /usr/lib/jvm/java-6-sun/lib:
               /home/ravi/Desktop/sw/lucene-3.0.3/lucene-core-3.0.3.jar:
              /home/ravi/Desktop/sw/lucene-3.0.3/lucene-demos-3.0.3.jar




--
View this message in context: http://lucene.472066.n3.nabble.com/Writing-new-peice-of-code-in-Lucene-tp2956161p2956458.html
Sent from the Lucene - General mailing list archive at Nabble.com.

Re: Writing new peice of code in Lucene

Posted by Anurag <an...@gmail.com>.
set classpath for the lucene version that u r using. of course Java
classpath  also needed. Then try to run this
http://www.panix.com/~mitzi/HelloLucene.java

If u get any error  do ask, the forum is very active in solving ur problem.
Run more sample codes from here
http://www.lucenetutorial.com/your-first-project.html

Thanks

On 5/18/11, ravishekhar [via Lucene]
<ml...@n3.nabble.com> wrote:
>
>
> Hi,
>
>  I am new to Lucene. I am able to run demo code given.
>  I wrote my code for training and searching based on some simple
> modification.
>  I have put that files in lucene-3.0.3/src/demo/org/apache/lucene/demo and
> tried to run as I run the demo file by just giving name of my files.
>
>  I used netbeans for the same and I am able to do the same, validating my
> program is correct.
>  I want to run the code through command line as done in case of demo
> program.
>
>  Please let me know how to do this.
>
>  Thanks,
>  Ravi
>
> _______________________________________________
> If you reply to this email, your message will be added to the discussion
> below:
> http://lucene.472066.n3.nabble.com/Writing-new-peice-of-code-in-Lucene-tp2956161p2956161.html
> To start a new topic under Lucene - General, email
> ml-node+642108-1580214077-146354@n3.nabble.com
> To unsubscribe from Lucene - General, visit
> http://lucene.472066.n3.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=642108&code=YW51cmFnLml0LmpvbGx5QGdtYWlsLmNvbXw2NDIxMDh8LTIwOTgzNDQxOTY=


-- 
Kumar Anurag


-----
Kumar Anurag

--
View this message in context: http://lucene.472066.n3.nabble.com/Writing-new-peice-of-code-in-Lucene-tp2956161p2956362.html
Sent from the Lucene - General mailing list archive at Nabble.com.