按输入流属性搜索

时间:2012-07-16 20:50:29

标签: full-text-search inputstream jackrabbit jcr

我有一个问题,即通过名为data的inputStream类型的属性创建一个xpath表达式来过滤资源。 如何进行文本搜索,例如这是有效的:

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*')]";

但这不起作用。

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

真正的事实是我们使用了一些自定义节点,让我们来解释属性定义:

在Java条款中......

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;

  ...
}

在JackRabbit条款中......

<!-- 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>

重点是,如何进行此查询以便按jcr:data属性进行过滤。

1 个答案:

答案 0 :(得分:0)

我认为您必须打开文本提取,以便将“jcr:data”属性中的可搜索文本编入索引。请参阅Jackrabbit讨论列表中的this email thread

BTW,JCR CND format是一种描述节点类型的更紧凑的方式。