Thank you Marc and thank u all... it` working :)
:clap:

Marc Schwarz wrote:
> 
> Maybe you should seperate the add method from the database function...
> 
> Separate the db loop something like that:
> 
> try
>            {
>             ResultSet rs2 = stm.executeQuery(sql);
>             while(rs2.next()) {
>                 String text = rs2.getString("textvalue");
>                 addDoc(w, text,rs2.getString("id"));
>                 count_ds++;
>             }
> 
> 
> and then the addDoc seems something like that:
> 
> 
> private static void addDoc(IndexWriter w, String value,String empty)
> throws
> IOException {
>     Document doc = new Document();
>     doc.add(new Field("title", value, Field.Store.YES,
> Field.Index.ANALYZED));
>     w.addDocument(doc);
>   }
> 
> 
> -----Ursprüngliche Nachricht-----
> Von: luciusvorenus [mailto:lucius.vore...@hotmail.de] 
> Gesendet: Donnerstag, 28. Januar 2010 23:02
> An: java-user@lucene.apache.org
> Betreff: Re: AW: index a database
> 
> 
> yes.... many thanks ..
>  But .... /.../my index folder is empty. Have I done something wrong in
> "private static void indexDocs"? It is not indexed
> 
> 
> 
> 
> Marc Schwarz wrote:
>> 
>> StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT);
>> 
>> any difference with that ?
>> 
>> -----Ursprüngliche Nachricht-----
>> Von: luciusvorenus [mailto:lucius.vore...@hotmail.de] 
>> Gesendet: Donnerstag, 28. Januar 2010 22:46
>> An: java-user@lucene.apache.org
>> Betreff: Re: index a database
>> 
>> 
>> lucene 3.3
>> 
>> i tried liek this
>> 
>> ""
>> import org.apache.lucene.demo.FileDocument;
>> import org.apache.lucene.document.Document;
>> import org.apache.lucene.document.Field;
>> import org.apache.lucene.analysis.Analyzer;
>> import org.apache.lucene.analysis.standard.StandardAnalyzer;
>> import org.apache.lucene.index.IndexWriter;
>> import org.apache.lucene.search.IndexSearcher;
>> import org.apache.lucene.search.Query;
>> import org.apache.lucene.queryParser.QueryParser;
>> import org.apache.lucene.store.FSDirectory;
>> import org.apache.lucene.util.Version;
>> import java.sql.*;
>> import java.util.Properties;
>> import org.apache.lucene.document.*;
>> import java.io.*;
>> import org.apache.lucene.store.Directory;
>> import org.apache.lucene.store.FSDirectory;
>> import org.apache.lucene.store.SimpleFSDirectory;
>> 
>> public class Con{
>>      public static void main(String[] args) throws Exception
>> 
>>        {
>>              final File INDEX_DIR = new File("index");
>> 
>>              
>>                 Class.forName("com.mysql.jdbc.Driver").newInstance();
>>                 Connection conn =
>> DriverManager.getConnection("jdbc:mysql://127.0.0.1/test", "root",
>> "passwort");
>>                 StandardAnalyzer analyzer = new StandardAnalyzer(null);
>>                    Directory directory = new SimpleFSDirectory(new
>> File("home/lucius/Desktop/index"));
>>                 IndexWriter w = new IndexWriter(directory, analyzer,true,
>> new
>> IndexWriter.MaxFieldLength(25000));
>>  
>>                 System.out.println("Indexing to directory '" + INDEX_DIR
>> + "'...");
>>                 indexDocs(w, conn);
>>                 w.optimize();
>>                 w.close();
>>              
>> 
>>              
>>              }
>>        
>> 
>> private static       void indexDocs(IndexWriter writer, Connection conn)
> throws
>> Exception {
>>        String sql = "select c_id, city from city";
>>        Statement stmt = conn.createStatement();
>>        ResultSet rs = stmt.executeQuery(sql);
>>        while (rs.next()) {
>>           Document d = new Document();
>>           d.add(new Field("c_id", rs.getString("c_id"), Field.Store.YES,
>> Field.Index.NO));
>>           d.add(new Field("city", rs.getString("city"), Field.Store.NO,
>> Field.Index.ANALYZED));
>>           
>>           writer.addDocument(d);
>>       }
>> 
>> }
>> }
>>  
>>      
>>              
>> """"
>> I ' on the right track ?
>> 
>> now i get this message after compiling
>> ""
>> Exception in thread "main" java.lang.NullPointerException
>>      at
>>
> org.apache.lucene.analysis.StopFilter.getEnablePositionIncrementsVersionDefa
>> ult(StopFilter.java:162)
>>      at
>>
> org.apache.lucene.analysis.standard.StandardAnalyzer.<init>(StandardAnalyzer
>> .java:73)
>>      at
>>
> org.apache.lucene.analysis.standard.StandardAnalyzer.<init>(StandardAnalyzer
>> .java:63)
>>      at Con.main(Con.java:29)
>> """
>> 
>> 
>> once again many thanks
>> 
>> Erick Erickson wrote:
>>> 
>>> What version are you using? Because there's no such constructor
>>> (i.e. one that takes a File) in 3.0.....
>>> 
>>> You might want to use something like FSDirectory.open(file) in
>>> your IndexWriter constructor....
>>> 
>>> If this doesn't work, more details please....
>>> 
>>> Erick
>>> 
>>> On Thu, Jan 28, 2010 at 3:30 PM, luciusvorenus
>>> <lucius.vore...@hotmail.de>wrote:
>>> 
>>>>
>>>> Hello
>>>>
>>>> I tried to index a database
>>>>
>>>> ""
>>>> import org.apache.lucene.demo.FileDocument;
>>>> import org.apache.lucene.document.Document;
>>>> import org.apache.lucene.document.Field;
>>>> import org.apache.lucene.analysis.Analyzer;
>>>> import org.apache.lucene.analysis.standard.StandardAnalyzer;
>>>> import org.apache.lucene.index.IndexWriter;
>>>> import org.apache.lucene.search.IndexSearcher;
>>>> import org.apache.lucene.search.Query;
>>>> import org.apache.lucene.queryParser.QueryParser;
>>>> import org.apache.lucene.store.FSDirectory;
>>>> import org.apache.lucene.util.Version;
>>>> import java.sql.*;
>>>> import java.util.Properties;
>>>> import org.apache.lucene.document.*;
>>>> import java.io.*;
>>>> import org.apache.lucene.store.Directory;
>>>> import org.apache.lucene.store.FSDirectory;
>>>>
>>>> public class Con{
>>>>        public static void main(String[] args) throws Exception
>>>>
>>>>          {
>>>>                final File INDEX_DIR = new File("index");
>>>>
>>>>
>>>>                   Class.forName("com.mysql.jdbc.Driver").newInstance();
>>>>                   Connection conn =
>>>> DriverManager.getConnection("jdbc:mysql://127.0.0.1/test", "root",
>>>> "passwort");
>>>>                   StandardAnalyzer analyzer = new
>>>> StandardAnalyzer(null);
>>>>                   IndexWriter writer = new IndexWriter(INDEX_DIR,
>>>> analyzer,
>>>> true);
>>>>                   System.out.println("Indexing to directory '" +
>>>> INDEX_DIR
>>>> + "'...");
>>>>                   indexDocs(writer, conn);
>>>>                   writer.optimize();
>>>>                   writer.close();
>>>>
>>>>
>>>>
>>>>                }
>>>>
>>>>
>>>> private static  void indexDocs(IndexWriter writer, Connection conn)
>>>> throws
>>>> Exception {
>>>>          String sql = "select c_id, city from city";
>>>>          Statement stmt = conn.createStatement();
>>>>          ResultSet rs = stmt.executeQuery(sql);
>>>>          while (rs.next()) {
>>>>             Document d = new Document();
>>>>             d.add(new Field("c_id", rs.getString("c_id"),
>>>> Field.Store.YES,
>>>> Field.Index.NO));
>>>>             d.add(new Field("city", rs.getString("city"),
>>>> Field.Store.NO,
>>>> Field.Index.ANALYZED));
>>>>
>>>>             writer.addDocument(d);
>>>>         }
>>>>
>>>> }
>>>> }
>>>>  """
>>>> and i get this message
>>>>
>>>> ""
>>>> symbol  : constructor
>>>>
>>>>
>>
> IndexWriter(java.io.File,org.apache.lucene.analysis.standard.StandardAnalyze
>> r,boolean)
>>>> location: class org.apache.lucene.index.IndexWriter
>>>>                   IndexWriter writer = new IndexWriter(INDEX_DIR,
>>>> analyzer,
>>>> true);
>>>>                                        ^
>>>> 1 error
>>>>
>>>> What i am doing wrong??
>>>>
>>>> I'm a newbie ...
>>>>
>>>> Thank U
>>>> --
>>>> View this message in context:
>>>> http://old.nabble.com/index-a-database-tp27358959p27358959.html
>>>> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
>>>>
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
>>>> For additional commands, e-mail: java-user-h...@lucene.apache.org
>>>>
>>>>
>>> 
>>> 
>> 
>> -- 
>> View this message in context:
>> http://old.nabble.com/index-a--mysql-database-tp27358959p27363073.html
>> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
>> For additional commands, e-mail: java-user-h...@lucene.apache.org
>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
>> For additional commands, e-mail: java-user-h...@lucene.apache.org
>> 
>> 
>> 
> 
> -- 
> View this message in context:
> http://old.nabble.com/index-a--mysql-database-tp27358959p27363752.html
> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
> For additional commands, e-mail: java-user-h...@lucene.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
> For additional commands, e-mail: java-user-h...@lucene.apache.org
> 
> 
> 

-- 
View this message in context: 
http://old.nabble.com/index-a--mysql-database-tp27358959p27374590.html
Sent from the Lucene - Java Users mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-user-h...@lucene.apache.org

Reply via email to