You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@jackrabbit.apache.org by Victor Giordano <vi...@globant.com> on 2012/07/16 20:51:28 UTC

Search by an inputstream property

Hi friends, i have a question about making a xpath expression for 
filtering resources by a property of type inputStream called data.
How i can do a text search... for example... this is working:

String xpath1 = "<my app path>//element(*, nt:resource) 
[jcr:contains(@jcr:mimeType,'*plain*')]";
String xpath2 = "<my app path>//element(*, nt:resource) 
[jcr:contains(@jcr:encoding,'*utf*')]";

But this is not working....
String xpath3 = "<my app path>//element(*, nt:resource) 
[jcr:contains(@jcr:data,'*plain*')]";

The really fact is that we use some custom nodes.. let's explain the 
properties definitions:

In Java Terms...

|public class*Resource*extends BaseNode {
||
   /** Encoding media type. It cannot be null or empty. */
   @Field(jcrName = "jcr:encoding", jcrDefaultValue = "")
   private String encoding;|
|
   /** Resource's MIME type. It cannot be null or empty. */
   @Field(jcrName="jcr:mimeType", jcrDefaultValue = "")
   private String mimeType;

   /** Resource's size (bytes). */
   @Field(jcrName="skl:size")
   private long size;

   /** Resource's content data as stream. It cannot be null. */
   @Field(jcrName="jcr:data")
   private InputStream data;

   ...
}

||@Node(jcrType = "baseNode", isAbstract = true)
public abstract class*BaseNode*{

   @Field(jcrName = "name", id = true)
   protected String name;

   @Field(jcrName = "creationDate")
   protected Date creationDate;

   ...
}|

And in JackRabbit Terms...


<!-- Base node type definition -->
   <nodeType *name="docs:baseNode"*
             isMixin="false"
             hasOrderableChildNodes="false" >
     <supertypes>
       <supertype>nt:hierarchyNode</supertype>
     </supertypes>
     <propertyDefinition name="docs:name"
                         requiredType="String"
                         autoCreated="false"
                         mandatory="true"
                         onParentVersion="COPY"
                         protected="false"
                         multiple="false" />
     <propertyDefinition name="docs:searchPath"
                         requiredType="String"
                         autoCreated="false"
                         mandatory="false"
                         onParentVersion="COPY"
                         protected="false"
                         multiple="false" />
     <propertyDefinition name="docs:creationDate"
                         requiredType="Date"
                         autoCreated="false"
                         mandatory="true"
                         onParentVersion="COPY"
                         protected="false"
                         multiple="false" />
     <propertyDefinition name="docs:lastModified"
                         requiredType="Date"
                         autoCreated="false"
                         mandatory="true"
                         onParentVersion="COPY"
                         protected="false"
                         multiple="false" />
     <childNodeDefinition name="*"
                          defaultPrimaryType="docs:baseNode"
                          autoCreated="false"
                          mandatory="false"
                          onParentVersion="COPY"
                          protected="false"
                          sameNameSiblings="false">
       <requiredPrimaryTypes>
<requiredPrimaryType>docs:baseNode</requiredPrimaryType>
       </requiredPrimaryTypes>
     </childNodeDefinition>
   </nodeType>


   <!-- Resource node type definition -->
   <nodeType *name="skl:resource"*
             isMixin="false"
             hasOrderableChildNodes="false" >
     <supertypes>
       <supertype>docs:baseNode</supertype>
       <supertype>*nt:resource*</supertype>
     </supertypes>
     <propertyDefinition name="skl:size"
                         requiredType="Long"
                         autoCreated="false"
                         mandatory="true"
                         onParentVersion="COPY"
                         protected="false"
                         multiple="false" />
     <propertyDefinition name="skl:externalUri"
                         requiredType="String"
                         autoCreated="false"
                         mandatory="false"
                         onParentVersion="COPY"
                         protected="false"
                         multiple="false" />
   </nodeType>

The point is.. how i do this query... in order to filter by jcr:data 
property...
Thanks for advance, and for reading this!
Greetings.
Victor.


Re: Search by an inputstream property

Posted by Victor Giordano <vi...@globant.com>.
Alex, thanks for your quick reply. I will have all of this in mind!!!.
We fixed these problem by adding a new property to the node, that 
contains the text context, whose type is String. So we make the query 
against that property. We use a custom text extractor (tika text 
extractor), and we add the necessary code to populate the new property 
when a file is uploaded.
Thanks again
Greeting
Victor

On 7/19/2012 4:09 PM, Alexander Klimetschek wrote:
> On 16.07.2012, at 20:51, Victor Giordano wrote:
>
>> Hi friends, i have a question about making a xpath expression for filtering resources by a property of type inputStream called data.
>> How i can do a text search... for example... this is working:
>>
>> String xpath1 = "<my app path>//element(*, nt:resource) [jcr:contains(@jcr:mimeType,'*plain*')]";
>> String xpath2 = "<my app path>//element(*, nt:resource) [jcr:contains(@jcr:encoding,'*utf*')]";
> FYI: jcr:contains() runs full text searches (with terms split up, word stemming etc.), so you don't need wildcards. Just use
>
> jcr:contains(@jcr:mimeType, 'plain')
>
> If you want real pattern-like matching (and highly-structured mime type or encoding values are probably better served by that), use jcr:like, which uses % as wildcard:
>
> jcr:like(@jcr:mimeType, '%plain')
>
> This should only match a value "text/plain" or "plain", but not "plain with a suffix".
>
>> But this is not working....
>> String xpath3 = "<my app path>//element(*, nt:resource) [jcr:contains(@jcr:data,'*plain*')]";
> The full text index for binary content is by default aggregated on the node itself, which you address with ".":
>
> //element(*, nt:resource) [jcr:contains(.,'plain')]
>
> The index configuration is documented here: http://wiki.apache.org/jackrabbit/IndexingConfiguration
>
> Cheers,
> Alex
>


Re: Search by an inputstream property

Posted by Alexander Klimetschek <ak...@adobe.com>.
On 16.07.2012, at 20:51, Victor Giordano wrote:

> Hi friends, i have a question about making a xpath expression for filtering resources by a property of type inputStream called data.
> How i can do a text search... for example... this is working:
> 
> String xpath1 = "<my app path>//element(*, nt:resource) [jcr:contains(@jcr:mimeType,'*plain*')]";
> String xpath2 = "<my app path>//element(*, nt:resource) [jcr:contains(@jcr:encoding,'*utf*')]";

FYI: jcr:contains() runs full text searches (with terms split up, word stemming etc.), so you don't need wildcards. Just use

jcr:contains(@jcr:mimeType, 'plain')

If you want real pattern-like matching (and highly-structured mime type or encoding values are probably better served by that), use jcr:like, which uses % as wildcard:

jcr:like(@jcr:mimeType, '%plain')

This should only match a value "text/plain" or "plain", but not "plain with a suffix".

> But this is not working....
> String xpath3 = "<my app path>//element(*, nt:resource) [jcr:contains(@jcr:data,'*plain*')]";

The full text index for binary content is by default aggregated on the node itself, which you address with ".":

//element(*, nt:resource) [jcr:contains(.,'plain')]

The index configuration is documented here: http://wiki.apache.org/jackrabbit/IndexingConfiguration

Cheers,
Alex