⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 textsearchquerynode.java

📁 jsr170接口的java实现。是个apache的开源项目。
💻 JAVA
字号:
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements.  See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License.  You may obtain a copy of the License at * *      http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */package org.apache.jackrabbit.core.query;import org.apache.jackrabbit.name.QName;import org.apache.jackrabbit.name.Path;import org.apache.jackrabbit.name.MalformedPathException;/** * Implements a query node that defines a textsearch clause. */public class TextsearchQueryNode extends QueryNode {    /**     * The query statement inside the textsearch clause     */    private final String query;    /**     * Limits the scope of this textsearch clause to a node or a property with     * the given relative path.     * If <code>null</code> the scope of this textsearch clause is the fulltext     * index of all properties of the context node.     */    private Path relPath;    /**     * If set to <code>true</code> {@link #relPath} references a property,     * otherwise references a node.     */    private boolean propertyRef;    /**     * Creates a new <code>TextsearchQueryNode</code> with a <code>parent</code>     * and a textsearch <code>query</code> statement. The scope of the query     * is the fulltext index of the node, that contains all properties.     *     * @param parent the parent node of this query node.     * @param query  the textsearch statement.     */    public TextsearchQueryNode(QueryNode parent, String query) {        this(parent, query, null, false);    }    /**     * Creates a new <code>TextsearchQueryNode</code> with a <code>parent</code>     * and a textsearch <code>query</code> statement. The scope of the query is     * the property or node referenced by <code>relPath</code>.     *     * @param parent     the parent node of this query node.     * @param query      the textsearch statement.     * @param relPath    scope of the fulltext search. If <code>null</code> the     *                   context node is searched.     * @param isProperty if <code>relPath</code> references a property or a     *                   node.     */    public TextsearchQueryNode(QueryNode parent, String query, Path relPath, boolean isProperty) {        super(parent);        this.query = query;        this.relPath = relPath;        this.propertyRef = isProperty;    }    /**     * {@inheritDoc}     */    public Object accept(QueryNodeVisitor visitor, Object data) {        return visitor.visit(this, data);    }    /**     * Returns the type of this node.     *     * @return the type of this node.     */    public int getType() {        return QueryNode.TYPE_TEXTSEARCH;    }    /**     * Returns the textsearch statement.     *     * @return the textsearch statement.     */    public String getQuery() {        return query;    }    /**     * Returns a property name if the scope is limited to just a single property     * or <code>null</code> if the scope is spawned across all properties of a     * node. Please note that this method does not return the full relative path     * that reference the item to match, but only the name of the final name     * element of the path returned by {@link #getRelativePath()}.     *     * @return property name or <code>null</code>.     * @deprecated Use {@link #getRelativePath()} instead.     */    public QName getPropertyName() {        return relPath == null ? null : relPath.getNameElement().getName();    }    /**     * Sets a new name as the search scope for this fulltext query.     *     * @param property the name of the property.     * @deprecated Use {@link #setRelativePath(Path)} instead.     */    public void setPropertyName(QName property) {        Path.PathBuilder builder = new Path.PathBuilder();        builder.addLast(property);        try {            this.relPath = builder.getPath();            this.propertyRef = true;        } catch (MalformedPathException e) {            // path is always valid        }    }    /**     * @return the relative path that references the item where the textsearch     *         is performed. Returns <code>null</code> if the textsearch is     *         performed on the context node.     */    public Path getRelativePath() {        return relPath;    }    /**     * Sets the relative path to the item where the textsearch is performed. If     * <code>relPath</code> is <code>null</code> the textsearch is performed on     * the context node.     *     * @param relPath the relative path to an item.     * @throws IllegalArgumentException if <code>relPath</code> is absolute.     */    public void setRelativePath(Path relPath) {        if (relPath != null && relPath.isAbsolute()) {            throw new IllegalArgumentException("relPath must be relative");        }        this.relPath = relPath;        if (relPath == null) {            // context node is never a property            propertyRef = false;        }    }    /**     * Adds a path element to the existing relative path. To add a path element     * which matches all node names use {@link RelationQueryNode#STAR_NAME_TEST}.     *     * @param element the path element to append.     */    public void addPathElement(Path.PathElement element) {        Path.PathBuilder builder = new Path.PathBuilder();        if (relPath != null) {            builder.addAll(relPath.getElements());        }        builder.addLast(element);        try {            relPath = builder.getPath();        } catch (MalformedPathException e) {            // path is always valid        }    }    /**     * @return <code>true</code> if {@link #getRelativePath()} references a     *         property, returns <code>false</code> if it references a node.     */    public boolean getReferencesProperty() {        return propertyRef;    }    /**     * Is set to <code>true</code>, indicates that {@link #getRelativePath()}     * references a property, if set to <code>false</code> indicates that it     * references a node.     *     * @param b flag whether a property is referenced.     */    public void setReferencesProperty(boolean b) {        propertyRef = b;    }    /**     * @inheritDoc     */    public boolean equals(Object obj) {        if (obj instanceof TextsearchQueryNode) {            TextsearchQueryNode other = (TextsearchQueryNode) obj;            return (query == null ? other.query == null : query.equals(other.query))                    && (relPath == null ? other.relPath == null : relPath.equals(other.relPath)                    && propertyRef == other.propertyRef);        }        return false;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -