Hi Thomas,
thomasg wrote:
Hi, any advice on this would be appreciated. I guess its an easy fix but
can't find the solution at present. Basically I have a .txt file and a .doc
file containing the same textual content. When I search for a word contained
in both files, I only get a hit from the .doc and not the .txt. This is the
relevant code:
Node folderNode = root.addNode("foldernode", "nt:folder");
//Now want to add this file
File file = new
File("C:/DocumentSearchTests/testdocuments/testtextfile.txt");
//Create an nt:file child node called "testfilenode"
Node fileNode = folderNode.addNode(file.getName(),
"nt:file");
String mimeType = "text/plain";
Node resourceNode = fileNode.addNode("jcr:content",
"nt:resource");
resourceNode.setProperty("jcr:mimeType", mimeType);
//resourceNode.setProperty("jcr:encoding", "");
if jcr:encoding is missing the jcr:data stream gets read with the
platform encoding. This might not be the same as your text file, e.g. if
your text file uses unicode.
Try the following:
- set an appropriate value for jcr:encoding
or
- make sure that the encoding of your text file matches the jvm platform
encoding.
I suggest you go with the first option because it does not depend on
what the default encoding of the jvm is.
regards
marcel
resourceNode.setProperty("jcr:data", new
FileInputStream(file));
Calendar lastModified = Calendar.getInstance();
lastModified.setTimeInMillis(file.lastModified());
resourceNode.setProperty("jcr:lastModified", lastModified);
session.save();