1
votes

I am using lucene 4.0 now i want to analyze field for using StringField.. Could Anyone tell me there is any way to to to analyzed String...

Document d = new Document(); 

d.add(new StringField("id_c", rs.getString("id_c"), Field.Store.YES, Field.Index.ANALYZED));
d.add(new StringField("id_c",  Field.Store.YES, Field.Index.ANALYZED));
d.add(new StringField("name",   Field.Store.YES, Field.Index.ANALYZED));
d.add(new StringField("dob",   Field.Store.YES, Field.Index.ANALYZED));
d.add(new StringField("dep",   Field.Store.YES, Field.Index.ANALYZED));
d.add(new StringField("salary",  Field.Store.YES, Field.Index.ANALYZED));

how can i use Field.Index.ANALYZED this way .. any way to overcome this difficulties

1
Your question is not clear. Can you take some examples and state what your queries look etc. StringField is a field that is indexed but not tokenized: the entire String value is indexed as a single token. For example this might be used for a 'country' field or an 'id' field, or any field that you intend to use for sorting or access through the field cache. - Arun

1 Answers

1
votes

Field.Index is deprecated, and should not be used in Lucene 4.X. You should familiarize yourself with the subclasses of the Field class, and use the appropriate ones. StringField is not analyzed, TextField is. If you want an analyzed field containing textual content, you should use TextField.

Most of the time, one of the standard Field subclasses will provide what you need. If not, you can pass a FieldType into the Field constructor to customize how a field is indexed.

Also, generally, when you create a field and add it to a document, it should have a value provided as well, and only the first field you are adding actually provides a value. So that will need to be seen to as well.