java - Retrieving SQL Date Datatype from Table with lucene search -


I am using Lucene 3,6,2 as a search engine in my application which is Java derby DB and Swing interface uses Netbeans IDE

For now, I'm able to retrieve all the information about the query as a string datatype. I present the code below.

  // Create some index directory index = new RAM directory (); Standard Analyst Analyzer = New Standard Analyzer (Milan Version); IndexWriterConfig IWConfig = new index configuration (version LUCENE_36, analyzer); Index indicator IW = new index (index, IWCCF); Try {Con = DriverManager.getConnection (Host, UN, UPS); Statement stmt = con.createStatement (ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE); String sql = "download from app. APPRAGRISHI"; Rs = stmt.executeQuery (SQL); Rs.beforeFirst (); While (rsnext ()) {doc = new document (); Doc.add (new field ("id", rsgetstring ("id"), field.store.Yes, field.index.nlised)); Doc.add (new field ("subject", rsgetstring ("SUBJECT"), field. Store.YES, field. Index.ANALYZED)); Doc.add (new field ("letter_from", rsgetstring ("LETTER_FROM"), field.store.YES, field.index.nlised)); Doc.add (new field ("date_of_letter", rsgetstring ("DATE_OF_LETTER"), field. Store.YES, field. Index.ANALYZED)); Doc.add (new field ("date_received", rsgetstring ("DATE_RECEIVED"), field. Store.YES, field.index.ANALYZED););   

But there is a date column and I would like to retrieve date data type data from date data and not as string datatype.

Any suggestions on how to get it.

You can change your dates for a long time (Date.getTime ()), and can store them like a

  Numericfiled letterDateField = new NumericField ("date_of_letter", field. Store.YES, true); LetterDateField.setLongValue (rs.getDate ("DATE_OF_LETTER") getTime ().); Doc.add (letterDateField); NumericFilandAditedFiled = New NumericField ("date_received", field.store.Yes, true); ReceivedDateField.setLongValue (rs.getDate ("DATE_RECEIVED") getTime ().); Doc.add (receivedDateField);   

To get back to time, just drag the long value and create a new date with it:

  date letter date = new date (doctor. GetField ("Date_of_letter") numericValue () longValue ()) ..   

When searching for a category, you will also need to convert values ​​to values ​​compared to the lengths, such as:

  numerical range . Alternatively, if necessary, you can store dates of different fields (i.e. in one year field), one month area, one day area, etc.). This allows you to design some questions, which will be difficult or impossible to count on the numerical date value (i.e., if you want to ask any year with any date in February of any year).  

Personally, I would suggest against using it directly.

Comments

Popular posts from this blog

excel vba - How to delete Solver(SOLVER.XLAM) code -

github - Teamcity & Git - PR merge builds - anyway to get HEAD commit hash? -

ios - Replace text in UITextView run slowly -