【问题标题】:JCR - Jackrabbit - Xpath expression for search content text of a file contained inside a nodeJCR - Jackrabbit - 节点内包含的文件的搜索内容文本的 Xpath 表达式
【发布时间】:2012-07-16 17:04:45
【问题描述】:

我在使用 Java 中的 JackRabbit JCR 时感到头疼。 这是关于制作一个 xpath 表达式来搜索我的存储库中的实体。

让我们简要介绍一下存储什么样的数据,我们有 3 个名为“Entry”的节点类,它扩展了另一个名为“BaseEntry”的节点类,并扩展了另一个名为“BaseNode”的节点类。 Entry 类代表我们 JCR 系统中的一个 Node,并具有一组属性(映射为相应类中的属性),并且还继承了映射在其超类中的属性。 “BaseEntry”类聚合了许多(零个或多个)附件。这表示与条目关联的原始文件(.doc、.xls、.pdf、.txt、.etc :D)。

这些是类定义和感兴趣的属性的一部分...

“入口”类

@Node(jcrType = "entry",  extend = BaseEntry.class)
public class Entry extends BaseEntry {

  ... // nothing really important here
}

“BaseEntry”类

@Node(jcrType = "baseEntry", extend = BaseNode.class, isAbstract = true)
public abstract class BaseEntry extends BaseNode {

  @Collection (jcrType = "attachment",
      collectionConverter = NTCollectionConverterImpl.class)
  protected List<Attachment> attachments = new ArrayList<Attachment>();

  ...

}

“BaseNode”类

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

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

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

  ...
}

“附件”类

@Node(jcrType = "attachment", discriminator = true)
public class Attachment extends BaseNode implements Comparable<Attachment> {

  /** The attachment's content resource. It cannot be null. */
  @Bean(jcrType = "skl:resource", autoUpdate = false)
  private Resource content;
  ...
}

“资源”类 @Node(jcrType = "skl:resource", 鉴别器 = true)

public class Resource extends BaseNode {

  /** 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;

  ...
}

custom_nodes.xml 对这些节点有以下定义:

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

  <!-- Attachment node type definition -->
  <nodeType name="skl:attachment"
            isMixin="false"
            hasOrderableChildNodes="false" >
    <supertypes>
      <supertype>docs:baseNode</supertype>
    </supertypes>
    <propertyDefinition name="skl:requestId"
                        requiredType="String"
                        autoCreated="false"
                        mandatory="false"
                        onParentVersion="COPY"
                        protected="false"
                        multiple="false" />
    <propertyDefinition name="skl:contentExternalUri"
                        requiredType="String"
                        autoCreated="false"
                        mandatory="false"
                        onParentVersion="COPY"
                        protected="false"
                        multiple="false" />
    <propertyDefinition name="skl:multiPagePreviewUrl"
                        requiredType="String"
                        autoCreated="false"
                        mandatory="false"
                        onParentVersion="COPY"
                        protected="false"
                        multiple="false" />
  </nodeType>

  <!-- Base Entry node type definition -->
  <nodeType name="skl:baseEntry"
            isMixin="false"
            hasOrderableChildNodes="false" >
    <supertypes>
      <supertype>docs:baseNode</supertype>
    </supertypes>
    <propertyDefinition name="skl:title"
                        requiredType="String"
                        autoCreated="false"
                        mandatory="true"
                        onParentVersion="COPY"
                        protected="false"
                        multiple="false" />
    <propertyDefinition name="skl:description"
                        requiredType="String"
                        autoCreated="false"
                        mandatory="false"
                        onParentVersion="COPY"
                        protected="false"
                        multiple="false" />
    <propertyDefinition name="skl:author"
                        requiredType="String"
                        autoCreated="false"
                        mandatory="false"
                        onParentVersion="COPY"
                        protected="false"
                        multiple="false" />
    <propertyDefinition name="skl:creator"
                        requiredType="String"
                        autoCreated="false"
                        mandatory="true"
                        onParentVersion="COPY"
                        protected="false"
                        multiple="false" />
    <propertyDefinition name="skl:creatorUnique"
                        requiredType="String"
                        autoCreated="false"
                        mandatory="true"
                        onParentVersion="COPY"
                        protected="false"
                        multiple="false" />
    <propertyDefinition name="skl:creatorMail"
                        requiredType="String"
                        autoCreated="false"
                        mandatory="true"
                        onParentVersion="COPY"
                        protected="false"
                        multiple="false" />
    <propertyDefinition name="skl:office"
                        requiredType="String"
                        autoCreated="false"
                        mandatory="true"
                        onParentVersion="COPY"
                        protected="false"
                        multiple="false" />
    <propertyDefinition name="skl:tags"
                        requiredType="String"
                        autoCreated="false"
                        mandatory="false"
                        onParentVersion="COPY"
                        protected="false"
                        multiple="true" />
  </nodeType>

  <!-- SKL Entry node type definition -->
  <nodeType name="skl:entry"
            isMixin="false"
            hasOrderableChildNodes="false" >
    <supertypes>
      <supertype>docs:baseNode</supertype>
      <supertype>skl:baseEntry</supertype>
    </supertypes>
    <propertyDefinition name="skl:languageName"
                        requiredType="String"
                        autoCreated="false"
                        mandatory="true"
                        onParentVersion="COPY"
                        protected="false"
                        multiple="false" />
    <propertyDefinition name="skl:rating"
                        requiredType="Long"
                        autoCreated="false"
                        mandatory="true"
                        onParentVersion="COPY"
                        protected="false"
                        multiple="false" />
    <propertyDefinition name="skl:urls"
                        requiredType="String"
                        autoCreated="false"
                        mandatory="false"
                        onParentVersion="COPY"
                        protected="false"
                        multiple="true" />
    <propertyDefinition name="skl:visitors"
                        requiredType="String"
                        autoCreated="false"
                        mandatory="false"
                        onParentVersion="COPY"
                        protected="false"
                        multiple="true" />
    <propertyDefinition name="skl:datePublished"
                        requiredType="String"
                        autoCreated="false"
                        mandatory="false"
                        onParentVersion="COPY"
                        protected="false"
                        multiple="false" />
    </nodeType>

所以我期待使用 make 和 xpath 语句来搜索那些在附件中包含某种文本的条目。所以基本上,这个想法是搜索具有包含特定文本或关键字的文件的条目。

到目前为止,我尝试过这样的事情......

String xPathQuery = "<BASE PATH>//element(*, skl:entry) [jcr:contains(*//content,'*<keyword>*')]";
String xPathQuery = "<BASE PATH>//element(*, skl:entry) [jcr:contains(*//@jcr:data,'*<keyword>*')]";

但是这些东西,并没有你猜到的那么好用……

我希望,一个慈善灵魂可以帮助我完成这个任务.. 不太好:S。 谢谢大家怎么看这个!。

你好!!

维克多

【问题讨论】:

  • 嗨,在显示节点类型信息时,大多数情况下最好使用紧凑的节点类型定义 (.cnd),因为它更易于阅读。

标签: full-text-search jackrabbit jcr


【解决方案1】:

Jackrabbit FAQ 解释了您的问题:

为什么 //*[jcr:contains(@jcr:data, 'foo')] 不返回匹配项 二进制内容?

从二进制内容中提取的文本仅在父节点上建立索引 @jcr:data 属性。在 nt:resource 节点上使用 jcr:contains()。

所以在你的情况下,我会使用类似的东西:

String xPathQuery = "<BASE PATH>//element(*, skl:resource)[jcr:contains(.,'*<keyword>*')]";

String xPathQuery = "<BASE PATH>//element(*, skl:entry)//element(*, skl:resource)[jcr:contains(.,'*<keyword>*')]";

我也强烈反对在您的 contains 语句开头使用 * 通配符。由于 Lucene 是倒排索引,因此效率极低。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-28
    • 2010-09-19
    • 1970-01-01
    • 2014-10-02
    • 2011-11-01
    相关资源
    最近更新 更多