001/* 002 * Copyright (c) 2015 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * All rights reserved. This program and the accompanying materials 005 * are made available under the terms of the GNU Lesser General Public License 006 * (LGPL) version 2.1 which accompanies this distribution, and is available at 007 * http://www.gnu.org/licenses/lgpl-2.1.html 008 * 009 * This library is distributed in the hope that it will be useful, 010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 012 * Lesser General Public License for more details. 013 * 014 * Contributors: 015 * Benoit Delbosc 016 */ 017 018package org.nuxeo.ecm.core.query.sql.model; 019 020import org.apache.commons.lang.StringUtils; 021 022public class EsHint implements Operand { 023 024 private static final long serialVersionUID = 4590329982296853715L; 025 026 public final String index; 027 028 public final String analyzer; 029 030 public final String operator; 031 032 public EsHint(EsIdentifierList index, String analyzer, String operator) { 033 this.index = (index == null) ? null : index.toString(); 034 this.analyzer = analyzer; 035 this.operator = operator; 036 } 037 038 @Override 039 public void accept(IVisitor visitor) { 040 } 041 042 @Override 043 public String toString() { 044 StringBuilder buf = new StringBuilder(); 045 buf.append("/*+ES: "); 046 if (index != null) { 047 buf.append(String.format("INDEX(%s) ", index)); 048 } 049 if (analyzer != null) { 050 buf.append(String.format("ANALYZER(%s) ", analyzer)); 051 } 052 if (operator != null) { 053 buf.append(String.format("OPERATOR(%s) ", operator)); 054 } 055 buf.append("*/"); 056 return buf.toString(); 057 } 058 059 @Override 060 public boolean equals(Object obj) { 061 if (obj == this) { 062 return true; 063 } 064 if (!(obj instanceof EsHint)) { 065 return false; 066 } 067 return equals((EsHint) obj); 068 } 069 070 private boolean equals(EsHint other) { 071 return StringUtils.equals(index, other.index) && StringUtils.equals(analyzer, other.analyzer) 072 && StringUtils.equals(operator, other.operator); 073 } 074 075 public String[] getIndex() { 076 if (index == null) { 077 return null; 078 } 079 return index.split(","); 080 } 081}