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", "");
resourceNode.setProperty("jcr:data", new
FileInputStream(file));
Calendar lastModified = Calendar.getInstance();
lastModified.setTimeInMillis(file.lastModified());
resourceNode.setProperty("jcr:lastModified", lastModified);
session.save();
//Now do my test search
Workspace workspace = session.getWorkspace();
QueryManager queryManager = workspace.getQueryManager();
Query query =
queryManager.createQuery("/jcr:root/foldernode//element(*,nt:resource)[jcr:contains(.,'cool')]",
Query.XPATH);
QueryResult result = query.execute();
RowIterator iter = result.getRows();
//No hits found when I expect one!
/*
When I create a .doc file like this, the same query returns the
document
as a hit as I expect.
File file = new
File("C:/DocumentSearchTests/testdocuments/testwordfile.doc");
//Create an nt:file child node called "testfilenode"
Node fileNode = folderNode.addNode(file.getName(),
"nt:file");
String mimeType = "application/msword";
//See pdf page 151, make jcr:content type nt:resource
Node resourceNode = fileNode.addNode("jcr:content",
"nt:resource");
resourceNode.setProperty("jcr:mimeType", mimeType);
//resourceNode.setProperty("jcr:encoding", ""); //Needed?
resourceNode.setProperty("jcr:data", new
FileInputStream(file));
Calendar lastModified = Calendar.getInstance();
lastModified.setTimeInMillis(file.lastModified());
resourceNode.setProperty("jcr:lastModified", lastModified);
*/
I would have expected the .doc to be the more difficult to get working but
the TextFilters in Repository.xml work fine. I guess that no index is
getting created for the .txt file but not sure why. (Also tried
"//*[jcr:contains(.,'cool')]" as my xpath query with same result)
Any help greatly appreciated. Thomas
--
View this message in context:
http://www.nabble.com/No-hits-returned-when-searching-.txt-file-t1349111.html#a3609159
Sent from the Jackrabbit - Dev forum at Nabble.com.