You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Ro...@ipaustralia.gov.au on 2010/05/13 02:06:56 UTC

Re: Not returning any result when I am doing text search from added file from jackrabbit [SEC=UNCLASSIFIED]

I use the inputstream from the file to create an instance of 
javax.jcr.Binary, and set that, not just the inputstream.  I dont know if 
the code that reads the text contents uses the mime type to know how to 
read the data, but I would say it probably does.

        Node file = appNode.addNode(documentId, "nt:file");
                    Node resource = file.addNode("jcr:content", 
"ed:docreftype");
                    InputStream in = new FileInputStream(fileName);
 
                    Binary binary = 
session.getValueFactory().createBinary(in);
                    binary.dispose();

                    resource.setProperty("jcr:data", binary);
                    String mimeType = null;
                    if (fileName.endsWith(".txt")) {
                        mimeType = "text/plain";
                    }
                    else if (fileName.endsWith(".xls")) {
                        mimeType = "application/vnd.ms-excel";
                    }
                    else if (fileName.endsWith(".ppt")) {
                        mimeType = "application/mspowerpoint";
                    }
                    else {
                        mimeType = "application/octet-stream";
                    }

                        resource.setProperty("jcr:mimeType", mimeType);

Ross

"Jenni Pothu" <Je...@virtusa.com> wrote on 12/05/2010 09:23:49 PM:

> From: "Jenni Pothu" <Je...@virtusa.com>
> To: <us...@jackrabbit.apache.org>
> Date: 12/05/2010 09:24 PM
> Subject: Not returning any result when I am doing text search from 
> added file from jackrabbit
> 
> Hi All,
> 
>                 I am attaching the file to blogEntry node and blogEntry
> node is added into repository. Now I want to search the content from the
> added file.
> 
> 
> 
>      I have node like blogEntry and I am adding file to that node like
> below
> 
>                                                 //getting the
> blogEntryNode form method getBlogEntryNode(blogTitle, session);
> 
> Node blogEntryNode = getBlogEntryNode(blogTitle, session);
> 
> Node NewblogEntry = blogEntryNode.addNode("NewblogEntry", "nt:file");
> 
>                   Node resNode = NewblogEntry.addNode("jcr:content",
> "nt:resource");
> 
>                   resNode.setProperty("jcr:data", file);
> 
> 
> 
> here file is of type Inputstream.
> 
> 
> 
> When I am searching with the  query like Query query =
> queryManager.createQuery
> 
>                   ("//blogEntry/NewblogEntry(*, nt:file)[jcr:contains(.,
> '"+sometext+"')]",Query.XPATH);
> 
> Here sometext is any content which I want to search in the file.
> 
> 
> 
> My query not returning any result. Is my query correct. Please correct
> me if anything wrong in the code. Thanks in advance. 
> 
> 
> 
> Thanks,
> 
> Jenni
> 
> 
> 
--------------------------------------------------------------------------------------------
> 
> This message, including any attachments, contains confidential 
information 
> intended for a specific individual and purpose, and is intended for 
> the addressee only. Any unauthorized disclosure, use, dissemination,
> copying, or distribution of 
> this message or any of its attachments or the information contained 
> in this e-mail, or the taking of any action based on it, is strictly
> prohibited. If you are not the intended recipient, please notify the
> sender immediately by return e-mail and delete this message.
> 
> 
--------------------------------------------------------------------------------------------

Re: Not returning any result when I am doing text search from added file from jackrabbit [SEC=UNCLASSIFIED]

Posted by Alexander Klimetschek <ak...@day.com>.
On Thu, May 13, 2010 at 02:06,  <Ro...@ipaustralia.gov.au> wrote:
> "Jenni Pothu" <Je...@virtusa.com> wrote on 12/05/2010 09:23:49 PM:
>> //blogEntry/NewblogEntry(*, nt:file)[jcr:contains(.,'"+sometext+"')]

I think you want to use the "element()" function for this, to specify
both a node name and its type in a single xpath location step:

//blogEntry/element(NewblogEntry, nt:file)[jcr:contains(.,'"+sometext+"')]

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com