0
votes

I'm using lucene library to create an index from a number of documents. For example, the name of the first document is file1.txt and it contains the following text:

.T (title of the document) .A (author of the document) .S (summary of the document)

If i want define as Field all the contents fo the document i'm writing this: doc.add(new TextField("contents", new BufferedReader( new InputStreamReader(fis, "UTF-8"))));

What if i want to specify only the summary of the document as a Field? Im new to java and i can't find a way.

1

1 Answers

1
votes

You need to manually read the file, till you get your summary, save it all in some sort of String, e.g. StringBuilder and then add a TextField as you listed.

For reading files line by line you could use Scanner (http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Scanner.html), for String concatenation you could use StringBuilder (http://docs.oracle.com/javase/7/docs/api/java/lang/StringBuilder.html)