lucene-core-2.9.4-dev

ad nextPerThread;
  final CharBlockPool charPool;
  final IntBlockPool intPool;
  final ByteBlockPool bytePool;
  final boolean primary;
  final DocumentsWriter.DocState docState;
  final RawPostingList[] freePostings = new RawPostingList['?'];
  int freePostingsCount;
  
  public TermsHashPerThread(DocInverterPerThread docInverterPerThread, TermsHash termsHash, TermsHash nextTermsHash, TermsHashPerThread primaryPerThread)
  {
    docState = docState;
    
    this.termsHash = termsHash;
    consumer = consumer.addThread(this);
    if (nextTermsHash != null)
    {
      charPool = new CharBlockPool(docWriter);
      primary = true;
    }
    else
    {
      charPool = charPool;
      primary = false;
    }
    intPool = new IntBlockPool(docWriter, trackAllocations);
    bytePool = new ByteBlockPool(docWriter.byteBlockAllocator, trackAllocations);
    if (nextTermsHash != null) {
      nextPerThread = nextTermsHash.addThread(docInverterPerThread, this);
    } else {
      nextPerThread = null;
    }
  }
  
  InvertedDocConsumerPerField addField(DocInverterPerField docInverterPerField, FieldInfo fieldInfo)
  {
    return new TermsHashPerField(docInverterPerField, this, nextPerThread, fieldInfo);
  }
  
  public synchronized void abort()
  {
    reset(true);
    consumer.abort();
    if (nextPerThread != null) {
      nextPerThread.abort();
    }
  }
  
  void morePostings()
    throws IOException
  {
    assert (freePostingsCount == 0);
    termsHash.getPostings(freePostings);
    freePostingsCount = freePostings.length;
    assert (noNullPostings(freePostings, freePostingsCount, "consumer=" + consumer));
  }
  
  private static boolean noNullPostings(RawPostingList[] postings, int count, String details)
  {
    for (int i = 0; i < count; i++) {
      assert (postings[i] != null) : ("postings[" + i + "] of " + count + " is null: " + details);
    }
    return true;
  }
  
  public void startDocument()
    throws IOException
  {
    consumer.startDocument();
    if (nextPerThread != null) {
      nextPerThread.consumer.startDocument();
    }
  }
  
  public DocumentsWriter.DocWriter finishDocument()
    throws IOException
  {
    DocumentsWriter.DocWriter doc = consumer.finishDocument();
    DocumentsWriter.DocWriter doc2;
    DocumentsWriter.DocWriter doc2;
    if (nextPerThread != null) {
      doc2 = nextPerThread.consumer.finishDocument();
    } else {
      doc2 = null;
    }
    if (doc == null) {
      return doc2;
    }
    doc.setNext(doc2);
    return doc;
  }
  
  void reset(boolean recyclePostings)
  {
    intPool.reset();
    bytePool.reset();
    if (primary) {
      charPool.reset();
    }
    if (recyclePostings)
    {
      termsHash.recyclePostings(freePostings, freePostingsCount);
      freePostingsCount = 0;
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.lucene.index.TermsHashPerThread
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.lucene.messages;

import java.io.Serializable;
import java.util.Locale;

public abstract interface Message
  extends Serializable
{
  public abstract String getKey();
  
  public abstract Object[] getArguments();
  
  public abstract String getLocalizedMessage();
  
  public abstract String getLocalizedMessage(Locale paramLocale);
}

/* Location:
 * Qualified Name:     org.apache.lucene.messages.Message
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.lucene.messages;

import java.util.Locale;

public class MessageImpl
  implements Message
{
  private static final long serialVersionUID = -3077643314630884523L;
  private String key;
  private Object[] arguments = new Object[0];
  
  public MessageImpl(String key)
  {
    this.key = key;
  }
  
  public MessageImpl(String key, Object[] args)
  {
    this(key);
  }
  
  public Object[] getArguments()
  {
    return arguments;
  }
  
  public String getKey()
  {
    return key;
  }
  
  public String getLocalizedMessage()
  {
    return getLocalizedMessage(Locale.getDefault());
  }
  
  public String getLocalizedMessage(Locale locale)
  {
    return NLS.getLocalizedMessage(getKey(), locale, getArguments());
  }
  
  public String toString()
  {
    Object[] args = getArguments();
    String argsString = "";
    if (args != null) {
      for (int i = 0; i < args.length; i++) {
        argsString = argsString + args[i] + (i < args.length ? "" : ", ");
      }
    }
    return getKey() + " " + argsString;
  }
}

/* Location:
 * Qualified Name:     org.apache.lucene.messages.MessageImpl
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.lucene.messages;

import java.lang.reflect.Field;
import java.security.PrivilegedAction;

final class NLS$1
  implements PrivilegedAction
{
  private final Field val$field;
  
  NLS$1(Field paramField) {}
  
  public Object run()
  {
    val$field.setAccessible(true);
    return null;
  }
}

/* Location:
 * Qualified Name:     org.apache.lucene.messages.NLS.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.lucene.messages;

import java.io.PrintStream;
import java.lang.reflect.Field;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.MissingResourceException;
import java.util.ResourceBundle;
import java.util.Set;

public class NLS
{
  private static Map bundles = new HashMap(0);
  
  public static String getLocalizedMessage(String key)
  {
    return getLocalizedMessage(key, Locale.getDefault());
  }
  
  public static String getLocalizedMessage(String key, Locale locale)
  {
    Object message = getResourceBundleObject(key, locale);
    if (message == null) {
      return "Message with key:" + key + " and locale: " + locale + " not found.";
    }
    return message.toString();
  }
  
  public static String getLocalizedMessage(String key, Locale locale, Object[] args)
  {
    String str = getLocalizedMessage(key, locale);
    if (args.length > 0) {
      str = MessageFormat.format(str, args);
    }
    return str;
  }
  
  public static String getLocalizedMessage(String key, Object[] args)
  {
    return getLocalizedMessage(key, Locale.getDefault(), args);
  }
  
  protected static void initializeMessages(String bundleName, Class clazz)
  {
    try
    {
      load(clazz);
      if (!bundles.containsKey(bundleName)) {
        bundles.put(bundleName, clazz);
      }
    }
    catch (Throwable e) {}
  }
  
  private static Object getResourceBundleObject(String messageKey, Locale locale)
  {
    for (Iterator it = bundles.keySet().iterator(); it.hasNext();)
    {
      Class clazz = (Class)bundles.get((String)it.next());
      ResourceBundle resourceBundle = ResourceBundle.getBundle(clazz.getName(), locale);
      if (resourceBundle != null) {
        try
        {
          Object obj = resourceBundle.getObject(messageKey);
          if (obj != null) {
            return obj;
          }
        }
        catch (MissingResourceException e) {}
      }
    }
    return null;
  }
  
  private static void load(Class clazz)
  {
    Field[] fieldArray = clazz.getDeclaredFields();
    
    boolean isFieldAccessible = (clazz.getModifiers() & 0x1) != 0;
    
    int len = fieldArray.length;
    Map fields = new HashMap(len * 2);
    for (int i = 0; i < len; i++)
    {
      fields.put(fieldArray[i].getName(), fieldArray[i]);
      loadfieldValue(fieldArray[i], isFieldAccessible, clazz);
    }
  }
  
  private static void loadfieldValue(Field field, boolean isFieldAccessible, Class clazz)
  {
    int MOD_EXPECTED = 9;
    int MOD_MASK = MOD_EXPECTED | 0x10;
    if ((field.getModifiers() & MOD_MASK) != MOD_EXPECTED) {
      return;
    }
    if (!isFieldAccessible) {
      makeAccessible(field);
    }
    try
    {
      field.set(null, field.getName());
      validateMessage(field.getName(), clazz);
    }
    catch (IllegalArgumentException e) {}catch (IllegalAccessException e) {}
  }
  
  private static void validateMessage(String key, Class clazz)
  {
    try
    {
      ResourceBundle resourceBundle = ResourceBundle.getBundle(clazz.getName(), Locale.getDefault());
      if (resourceBundle != null)
      {
        Object obj = resourceBundle.getObject(key);
        if (obj == null) {
          System.err.println("WARN: Message with key:" + key + " and locale: " + Locale.getDefault() + " not found.");
        }
      }
    }
    catch (MissingResourceException e)
    {
      System.err.println("WARN: Message with key:" + key + " and locale: " + Locale.getDefault() + " not found.");
    }
    catch (Throwable e) {}
  }
  
  private static void makeAccessible(Field field)
  {
    if (System.getSecurityManager() == null) {
      field.setAccessible(true);
    } else {
      AccessController.doPrivileged(new PrivilegedAction()
      {
        private final Field val$field;
        
        public Object run()
        {
          val$field.setAccessible(true);
          return null;
        }
      });
    }
  }
}

/* Location:
 * Qualified Name:     org.apache.lucene.messages.NLS
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.lucene.messages;

public abstract interface NLSException
{
  public abstract Message getMessageObject();
}

/* Location:
 * Qualified Name:     org.apache.lucene.messages.NLSException
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.lucene.queryParser;

import java.io.IOException;

public abstract interface CharStream
{
  public abstract char readChar()
    throws IOException;
  
  /**
   * @deprecated
   */
  public abstract int getColumn();
  
  /**
   * @deprecated
   */
  public abstract int getLine();
  
  public abstract int getEndColumn();
  
  public abstract int getEndLine();
  
  public abstract int getBeginColumn();
  
  public abstract int getBeginLine();
  
  public abstract void backup(int paramInt);
  
  public abstract char BeginToken()
    throws IOException;
  
  public abstract String GetImage();
  
  public abstract char[] GetSuffix(int paramInt);
  
  public abstract void Done();
}

/* Location:
 * Qualified Name:     org.apache.lucene.queryParser.CharStream
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.lucene.queryParser;

import java.io.IOException;
import java.io.PrintStream;
import java.io.Reader;

public final class FastCharStream
  implements CharStream
{
  char[] buffer = null;
  int bufferLength = 0;
  int bufferPosition = 0;
  int tokenStart = 0;
  int bufferStart = 0;
  Reader input;
  
  public FastCharStream(Reader r)
  {
    input = r;
  }
  
  public final char readChar()
    throws IOException
  {
    if (bufferPosition >= bufferLength) {
      refill();
    }
    return buffer[(bufferPosition++)];
  }
  
  private final void refill()
    throws IOException
  {
    int newPosition = bufferLength - tokenStart;
    if (tokenStart == 0)
    {
      if (buffer == null)
      {
        buffer = new char['?'];
      }
      else if (bufferLength == buffer.length)
      {
        char[] newBuffer = new char[buffer.length * 2];
        System.arraycopy(buffer, 0, newBuffer, 0, bufferLength);
        buffer = newBuffer;
      }
    }
    else {
      System.arraycopy(buffer, tokenStart, buffer, 0, newPosition);
    }
    bufferLength = newPosition;
    bufferPosition = newPosition;
    bufferStart += tokenStart;
    tokenStart = 0;
    
    int charsRead = input.read(buffer, newPosition, buffer.length - newPosition);
    if (charsRead == -1) {
      throw new IOException("read past eof");
    }
    bufferLength += charsRead;
  }
  
  public final char BeginToken()
    throws IOException
  {
    tokenStart = bufferPosition;
    return readChar();
  }
  
  public final void backup(int amount)
  {
    bufferPosition -= amount;
  }
  
  public final String GetImage()
  {
    return new String(buffer, tokenStart, bufferPosition - tokenStart);
  }
  
  public final char[] GetSuffix(int len)
  {
    char[] value = new char[len];
    System.arraycopy(buffer, bufferPosition - len, value, 0, len);
    return value;
  }
  
  public final void Done()
  {
    try
    {
      input.close();
    }
    catch (IOException e)
    {
      System.err.println("Caught: " + e + "; ignoring.");
    }
  }
  
  public final int getColumn()
  {
    return bufferStart + bufferPosition;
  }
  
  public final int getLine()
  {
    return 1;
  }
  
  public final int getEndColumn()
  {
    return bufferStart + bufferPosition;
  }
  
  public final int getEndLine()
  {
    return 1;
  }
  
  public final int getBeginColumn()
  {
    return bufferStart + tokenStart;
  }
  
  public final int getBeginLine()
  {
    return 1;
  }
}

/* Location:
 * Qualified Name:     org.apache.lucene.queryParser.FastCharStream
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.lucene.queryParser;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.MultiPhraseQuery;
import org.apache.lucene.search.PhraseQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.util.Version;

public class MultiFieldQueryParser
  extends QueryParser
{
  protected String[] fields;
  protected Map boosts;
  
  /**
   * @deprecated
   */
  public MultiFieldQueryParser(String[] fields, Analyzer analyzer, Map boosts)
  {
    this(Version.LUCENE_24, fields, analyzer);
    this.boosts = boosts;
  }
  
  public MultiFieldQueryParser(Version matchVersion, String[] fields, Analyzer analyzer, Map boosts)
  {
    this(matchVersion, fields, analyzer);
    this.boosts = boosts;
  }
  
  /**
   * @deprecated
   */
  public MultiFieldQueryParser(String[] fields, Analyzer analyzer)
  {
    this(Version.LUCENE_24, fields, analyzer);
  }
  
  public MultiFieldQueryParser(Version matchVersion, String[] fields, Analyzer analyzer)
  {
    super(matchVersion, null, analyzer);
    this.fields = fields;
  }
  
  protected Query getFieldQuery(String field, String queryText, int slop)
    throws ParseException
  {
    if (field == null)
    {
      List clauses = new ArrayList();
      for (int i = 0; i < fields.length; i++)
      {
        Query q = super.getFieldQuery(fields[i], queryText);
        if (q != null)
        {
          if (boosts != null)
          {
            Float boost = (Float)boosts.get(fields[i]);
            if (boost != null) {
              q.setBoost(boost.floatValue());
            }
          }
          applySlop(q, slop);
          clauses.add(new BooleanClause(q, BooleanClause.Occur.SHOULD));
        }
      }
      if (clauses.size() == 0) {
        return null;
      }
      return getBooleanQuery(clauses, true);
    }
    Query q = super.getFieldQuery(field, queryText);
    applySlop(q, slop);
    return q;
  }
  
  private void applySlop(Query q, int slop)
  {
    if ((q instanceof PhraseQuery)) {
      ((PhraseQuery)q).setSlop(slop);
    } else if ((q instanceof MultiPhraseQuery)) {
      ((MultiPhraseQuery)q).setSlop(slop);
    }
  }
  
  protected Query getFieldQuery(String field, String queryText)
    throws ParseException
  {
    return getFieldQuery(field, queryText, 0);
  }
  
  protected Query getFuzzyQuery(String field, String termStr, float minSimilarity)
    throws ParseException
  {
    if (field == null)
    {
      List clauses = new ArrayList();
      for (int i = 0; i < fields.length; i++) {
        clauses.add(new BooleanClause(getFuzzyQuery(fields[i], termStr, minSimilarity), BooleanClause.Occur.SHOULD));
      }
      return getBooleanQuery(clauses, true);
    }
    return super.getFuzzyQuery(field, termStr, minSimilarity);
  }
  
  protected Query getPrefixQuery(String field, String termStr)
    throws ParseException
  {
    if (field == null)
    {
      List clauses = new ArrayList();
      for (int i = 0; i < fields.length; i++) {
        clauses.add(new BooleanClause(getPrefixQuery(fields[i], termStr), BooleanClause.Occur.SHOULD));
      }
      return getBooleanQuery(clauses, true);
    }
    return super.getPrefixQuery(field, termStr);
  }
  
  protected Query getWildcardQuery(String field, String termStr)
    throws ParseException
  {
    if (field == null)
    {
      List clauses = new ArrayList();
      for (int i = 0; i < fields.length; i++) {
        clauses.add(new BooleanClause(getWildcardQuery(fields[i], termStr), BooleanClause.Occur.SHOULD));
      }
      return getBooleanQuery(clauses, true);
    }
    return super.getWildcardQuery(field, termStr);
  }
  
  protected Query getRangeQuery(String field, String part1, String part2, boolean inclusive)
    throws ParseException
  {
    if (field == null)
    {
      List clauses = new ArrayList();
      for (int i = 0; i < fields.length; i++) {
        clauses.add(new BooleanClause(getRangeQuery(fields[i], part1, part2, inclusive), BooleanClause.Occur.SHOULD));
      }
      return getBooleanQuery(clauses, true);
    }
    return super.getRangeQuery(field, part1, part2, inclusive);
  }
  
  /**
   * @deprecated
   */
  public static Query parse(String[] queries, String[] fields, Analyzer analyzer)
    throws ParseException
  {
    return parse(Version.LUCENE_24, queries, fields, analyzer);
  }
  
  public static Query parse(Version matchVersion, String[] queries, String[] fields, Analyzer analyzer)
    throws ParseException
  {
    if (queries.length != fields.length) {
      throw new IllegalArgumentException("queries.length != fields.length");
    }
    BooleanQuery bQuery = new BooleanQuery();
    for (int i = 0; i < fields.length; i++)
    {
      QueryParser qp = new QueryParser(matchVersion, fields[i], analyzer);
      Query q = qp.parse(queries[i]);
      if ((q != null) && ((!(q instanceof BooleanQuery)) || (((BooleanQuery)q).getClauses().length > 0))) {
        bQuery.add(q, BooleanClause.Occur.SHOULD);
      }
    }
    return bQuery;
  }
  
  /**
   * @deprecated
   */
  public static Query parse(String query, String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer)
    throws ParseException
  {
    return parse(Version.LUCENE_24, query, fields, flags, analyzer);
  }
  
  public static Query parse(Version matchVersion, String query, String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer)
    throws ParseException
  {
    if (fields.length != flags.length) {
      throw new IllegalArgumentException("fields.length != flags.length");
    }
    BooleanQuery bQuery = new BooleanQuery();
    for (int i = 0; i < fields.length; i++)
    {
      QueryParser qp = new QueryParser(matchVersion, fields[i], analyzer);
      Query q = qp.parse(query);
      if ((q != null) && ((!(q instanceof BooleanQuery)) || (((BooleanQuery)q).getClauses().length > 0))) {
        bQuery.add(q, flags[i]);
      }
    }
    return bQuery;
  }
  
  /**
   * @deprecated
   */
  public static Query parse(String[] queries, String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer)
    throws ParseException
  {
    return parse(Version.LUCENE_24, queries, fields, flags, analyzer);
  }
  
  public static Query parse(Version matchVersion, String[] queries, String[] fields, BooleanClause.Occur[] flags, Analyzer analyzer)
    throws ParseException
  {
    if ((queries.length != fields.length) || (queries.length != flags.length)) {
      throw new IllegalArgumentException("queries, fields, and flags array have have different length");
    }
    BooleanQuery bQuery = new BooleanQuery();
    for (int i = 0; i < fields.length; i++)
    {
      QueryParser qp = new QueryParser(matchVersion, fields[i], analyzer);
      Query q = qp.parse(queries[i]);
      if ((q != null) && ((!(q instanceof BooleanQuery)) || (((BooleanQuery)q).getClauses().length > 0))) {
        bQuery.add(q, flags[i]);
      }
    }
    return bQuery;
  }
}

/* Location:
 * Qualified Name:     org.apache.lucene.queryParser.MultiFieldQueryParser
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.lucene.queryParser;

public class ParseException
  extends Exception
{
  protected boolean specialConstructor;
  public Token currentToken;
  public int[][] expectedTokenSequences;
  public String[] tokenImage;
  
  public ParseException(Token currentTokenVal, int[][] expectedTokenSequencesVal, String[] tokenImageVal)
  {
    super("");
    specialConstructor = true;
    currentToken = currentTokenVal;
    expectedTokenSequences = expectedTokenSequencesVal;
    tokenImage = tokenImageVal;
  }
  
  public ParseException()
  {
    specialConstructor = false;
  }
  
  public ParseException(String message)
  {
    super(message);
    specialConstructor = false;
  }
  
  public String getMessage()
  {
    if (!specialConstructor) {
      return super.getMessage();
    }
    StringBuffer expected = new StringBuffer();
    int maxSize = 0;
    for (int i = 0; i < expectedTokenSequences.length; i++)
    {
      if (maxSize < expectedTokenSequences[i].length) {
        maxSize = expectedTokenSequences[i].length;
      }
      for (int j = 0; j < expectedTokenSequences[i].length; j++) {
        expected.append(tokenImage[expectedTokenSequences[i][j]]).append(' ');
      }
      if (expectedTokenSequences[i][(expectedTokenSequences[i].length - 1)] != 0) {
        expected.append("...");
      }
      expected.append(eol).append("    ");
    }
    String retval = "Encountered \"";
    Token tok = currentToken.next;
    for (int i = 0; i < maxSize; i++)
    {
      if (i != 0) {
        retval = retval + " ";
      }
      if (kind == 0)
      {
        retval = retval + tokenImage[0];
        break;
      }
      retval = retval + " " + tokenImage[kind];
      retval = retval + " \"";
      retval = retval + add_escapes(image);
      retval = retval + " \"";
      tok = next;
    }
    retval = retval + "\" at line " + currentToken.next.beginLine + ", column " + currentToken.next.beginColumn;
    retval = retval + "." + eol;
    if (expectedTokenSequences.length == 1) {
      retval = retval + "Was expecting:" + eol + "    ";
    } else {
      retval = retval + "Was expecting one of:" + eol + "    ";
    }
    retval = retval + expected.toString();
    return retval;
  }
  
  protected String eol = System.getProperty("line.separator", "\n");
  
  protected String add_escapes(String str)
  {
    StringBuffer retval = new StringBuffer();
    for (int i = 0; i < str.length(); i++) {
      switch (str.charAt(i))
      {
      case '\000': 
        break;
      case '\b': 
        retval.append("\\b");
        break;
      case '\t': 
        retval.append("\\t");
        break;
      case '\n': 
        retval.append("\\n");
        break;
      case '\f': 
        retval.append("\\f");
        break;
      case '\r': 
        retval.append("\\r");
        break;
      case '"': 
        retval.append("\\\"");
        break;
      case '\'': 
        retval.append("\\'");
        break;
      case '\\': 
        retval.append("\\\\");
        break;
      default: 
        char ch;
        if (((ch = str.charAt(i)) < ' ') || (ch > '~'))
        {
          String s = "0000" + Integer.toString(ch, 16);
          retval.append("\\u" + s.substring(s.length() - 4, s.length()));
        }
        else
        {
          retval.append(ch);
        }
        break;
      }
    }
    return retval.toString();
  }
}

/* Location:
 * Qualified Name:     org.apache.lucene.queryParser.ParseException
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.lucene.queryParser;

class QueryParser$1 {}

/* Location:
 * Qualified Name:     org.apache.lucene.queryParser.QueryParser.1
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.lucene.queryParser;

final class QueryParser$JJCalls
{
  int gen;
  Token first;
  int arg;
  JJCalls next;
}

/* Location:
 * Qualified Name:     org.apache.lucene.queryParser.QueryParser.JJCalls
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.lucene.queryParser;

final class QueryParser$LookaheadSuccess
  extends Error
{
  private QueryParser$LookaheadSuccess() {}
  
  QueryParser$LookaheadSuccess(QueryParser.1 x0)
  {
    this();
  }
}

/* Location:
 * Qualified Name:     org.apache.lucene.queryParser.QueryParser.LookaheadSuccess
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.lucene.queryParser;

import org.apache.lucene.util.Parameter;

public final class QueryParser$Operator
  extends Parameter
{
  private QueryParser$Operator(String name)
  {
    super(name);
  }
  
  public static final Operator OR = new Operator("OR");
  public static final Operator AND = new Operator("AND");
}

/* Location:
 * Qualified Name:     org.apache.lucene.queryParser.QueryParser.Operator
 * Java Class Version: 1.4 (48.0)
 * JD-Core Version:    0.7.1
 */
package org.apache.lucene.queryParser;

import java.io.IOException;
import java.io.PrintStream;
import java.io.StringReader;
import java.text.Collator;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Vector;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.CachingTokenFilter;
import org.apache.lucene.analysis.SimpleAnalyzer;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.PositionIncrementAttribute;
import org.apache.lucene.analysis.tokenattributes.TermAttribute;
import org.apache.lucene.document.DateField;
import org.apache.lucene.document.DateTools;
import org.apache.lucene.document.DateTools.Resolution;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanClause.Occur;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.BooleanQuery.TooManyClauses;
import org.apache.lucene.search.FuzzyQuery;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.MultiPhraseQuery;
import org.apache.lucene.search.MultiTermQuery;
import org.apache.lucene.search.MultiTermQuery.RewriteMethod;
import org.apache.lucene.search.PhraseQuery;
import org.apache.lucene.search.PrefixQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.TermRangeQuery;
import org.apache.lucene.search.WildcardQuery;
import org.apache.lucene.util.Parameter;
import org.apache.lucene.util.Version;

public class QueryParser
  implements QueryParserConstants
{
  private static final int CONJ_NONE = 0;
  private static final int CONJ_AND = 1;
  private static final int CONJ_OR = 2;
  private static final int MOD_NONE = 0;
  private static final int MOD_NOT = 10;
  private static final int MOD_REQ = 11;
  public static final Operator AND_OPERATOR;
  public static final Operator OR_OPERATOR;
  private Operator operator = OR_OPERATOR;
  boolean lowercaseExpandedTerms = true;
  MultiTermQuery.RewriteMethod multiTermRewriteMethod = MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT;
  boolean allowLeadingWildcard = false;
  boolean enablePositionIncrements = true;
  Analyzer analyzer;
  String field;
  int phraseSlop = 0;
  float fuzzyMinSim = 0.5F;
  int fuzzyPrefixLength = 0;
  Locale locale = Locale.getDefault();
  DateTools.Resolution dateResolution = null;
  Map fieldToDateResolution = null;
  Collator rangeCollator = null;
  public QueryParserTokenManager token_source;
  public Token token;
  public Token jj_nt;
  private int jj_ntk;
  private Token jj_scanpos;
  private Token jj_lastpos;
  private int jj_la;
  private int jj_gen;
  
  public static final class Operator
    extends Parameter
  {
    private Operator(String name)
    {
      super();
    }
    
    public static final Operator OR = new Operator("OR");
    public static final Operator AND = new Operator("AND");
  }
  
  /**
   * @deprecated
   */
  public QueryParser(String f, Analyzer a)
  {
    this(Version.LUCENE_24, f, a);
  }
  
  public QueryParser(Version matchVersion, String f, Analyzer a)
  {
    this(new FastCharStream(new StringReader("")));
    analyzer = a;
    field = f;
    if (matchVersion.onOrAfter(Version.LUCENE_29)) {
      enablePositionIncrements = true;
    } else {
      enablePositionIncrements = false;
    }
  }
  
  public Query parse(String query)
    throws ParseException
  {
    ReInit(new FastCharStream(new StringReader(query)));
    try
    {
      Query res = TopLevelQuery(field);
      return res != null ? res : newBooleanQuery(false);
    }
    catch (ParseException tme)
    {
      ParseException e = new ParseException("Cannot parse '" + query + "': " + tme.getMessage());
      e.initCause(tme);
      throw e;
    }
    catch (TokenMgrError tme)
    {
      ParseException e = new ParseException("Cannot parse '" + query + "': " + tme.getMessage());
      e.initCause(tme);
      throw e;
    }
    catch (BooleanQuery.TooManyClauses tmc)
    {
      ParseException e = new ParseException("Cannot parse '" + query + "': too many boolean clauses");
      e.initCause(tmc);
      throw e;
    }
  }
  
  public Analyzer getAnalyzer()
  {
    return analyzer;
  }
  
  public String getField()
  {
    return field;
  }
  
  public float getFuzzyMinSim()
  {
    return fuzzyMinSim;
  }
  
  public void setFuzzyMinSim(float fuzzyMinSim)
  {
    this.fuzzyMinSim = fuzzyMinSim;
  }
  
  public int getFuzzyPrefixLength()
  {
    return fuzzyPrefixLength;
  }
  
  public void setFuzzyPrefixLength(int fuzzyPrefixLength)
  {
    this.fuzzyPrefixLength = fuzzyPrefixLength;
  }
  
  public void setPhraseSlop(int phraseSlop)
  {
    this.phraseSlop = phraseSlop;
  }
  
  public int getPhraseSlop()
  {
    return phraseSlop;
  }
  
  public void setAllowLeadingWildcard(boolean allowLeadingWildcard)
  {
    this.allowLeadingWildcard = allowLeadingWildcard;
  }
  
  public boolean getAllowLeadingWildcard()
  {
    return allowLeadingWildcard;
  }
  
  public void setEnablePositionIncrements(boolean enable)
  {
    enablePositionIncrements = enable;
  }
  
  public boolean getEnablePositionIncrements()
  {
    return enablePositionIncrements;
  }
  
  public void setDefaultOperator(Operator op)
  {
    operator = op;
  }
  
  public Operator getDefaultOperator()
  {
    return operator;
  }
  
  public void setLowercaseExpandedTerms(boolean lowercaseExpandedTerms)
  {
    this.lowercaseExpandedTerms = lowercaseExpandedTerms;
  }
  
  public boolean getLowercaseExpandedTerms()
  {
    return lowercaseExpandedTerms;
  }
  
  /**
   * @deprecated
   */
  public void setUseOldRangeQuery(boolean useOldRangeQuery)
  {
    if (useOldRangeQuery) {
      setMultiTermRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
    } else {
      setMultiTermRewriteMethod(MultiTermQuery.CONSTANT_SCORE_AUTO_REWRITE_DEFAULT);
    }
  }
  
  /**
   * @deprecated
   */
  public boolean getUseOldRangeQuery()
  {
    if (getMultiTermRewriteMethod() == MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE) {
      return true;
    }
    return false;
  }
  
  public void setMultiTermRewriteMethod(MultiTermQuery.RewriteMethod method)
  {
    multiTermRewriteMethod = method;
  }
  
  public MultiTermQuery.RewriteMethod getMultiTermRewriteMethod()
  {
    return multiTermRewriteMethod;
  }
  
  public void setLocale(Locale locale)
  {
    this.locale = locale;
  }
  
  public Locale getLocale()
  {
    return locale;
  }
  
  public void setDateResolution(DateTools.Resolution dateResolution)
  {
    this.dateResolution = dateResolution;
  }
  
  public void setDateResolution(String fieldName, DateTools.Resolution dateResolution)
  {
    if (fieldName == null) {
      throw new IllegalArgumentException("Field cannot be null.");
    }
    if (fieldToDateResolution == null) {
      fieldToDateResolution = new HashMap();
    }
    fieldToDateResolution.put(fieldName, dateResolution);
  }
  
  public DateTools.Resolution getDateResolution(String fieldName)
  {
    if (fieldName == null) {
      throw new IllegalArgumentException("Field cannot be null.");
    }
    if (fieldToDateResolution == null) {
      return dateResolution;
    }
    DateTools.Resolution resolution = (DateTools.Resolution)fieldToDateResolution.get(fieldName);
    if (resolution == null) {
      resolution = dateResolution;
    }
    return resolution;
  }
  
  public void setRangeCollator(Collator rc)
  {
    rangeCollator = rc;
  }
  
  public Collator getRangeCollator()
  {
    return rangeCollator;
  }
  
  /**
   * @deprecated
   */
  protected void addClause(Vector clauses, int conj, int mods, Query q)
  {
    addClause(clauses, conj, mods, q);
  }
  
  protected void addClause(List clauses, int conj, int mods, Query q)
  {
    if ((clauses.size() > 0) && (conj == 1))
    {
      BooleanClause c = (BooleanClause)clauses.get(clauses.size() - 1);
      if (!c.isProhibited()) {
        c.setOccur(BooleanClause.Occur.MUST);
      }
    }
    if ((clauses.size() > 0) && (operator == AND_OPERATOR) && (conj == 2))
    {
      BooleanClause c = (BooleanClause)clauses.get(clauses.size() - 1);
      if (!c.isProhibited()) {
        c.setOccur(BooleanClause.Occur.SHOULD);
      }
    }
    if (q == null) {
      return;
    }
    boolean prohibited;
    boolean required;
    if (operator == OR_OPERATOR)
    {
      boolean prohibited = mods == 10;
      boolean required = mods == 11;
      if ((conj == 1) && (!prohibited)) {
        required = true;
      }
    }
    else
    {
      prohibited = mods == 10;
      required = (!prohibited) && (conj != 2);
    }
    if ((required) && (!prohibited)) {
      clauses.add(newBooleanClause(q, BooleanClause.Occur.MUST));
    } else if ((!required) && (!prohibited)) {
      clauses.add(newBooleanClause(q, BooleanClause.Occur.SHOULD));
    } else if ((!required) && (prohibited)) {
      clauses.add(newBooleanClause(q, BooleanClause.Occur.MUST_NOT));
    } else {
      throw new RuntimeException("Clause cannot be both required and prohibited");
    }
  }
  
  protected Query getFieldQuery(String field, String queryText)
    throws ParseException
  {
    TokenStream source;
    try
    {
      source = analyzer.reusableTokenStream(field, new StringReader(queryText));
      source.reset();
    }
    catch (IOException e)
    {
      source = analyzer.tokenStream(field, new StringReader(queryText));
    }
    CachingTokenFilter buffer = new CachingTokenFilter(source);
    TermAttribute termAtt = null;
    PositionIncrementAttribute posIncrAtt = null;
    int numTokens = 0;
    
    boolean success = false;
    try
    {
      buffer.reset();
      success = true;
    }
    catch (IOException e) {}
    if (success)
    {
      if (buffer.hasAttribute(TermAttribute.class)) {
        termAtt = (TermAttribute)buffer.getAttribute(TermAttribute.class);
      }
      if (buffer.hasAttribute(PositionIncrementAttribute.class)) {
        posIncrAtt = (PositionIncrementAttribute)buffer.getAttribute(PositionIncrementAttribute.class);
      }
    }
    int positionCount = 0;
    boolean severalTokensAtSamePosition = false;
    
    boolean hasMoreTokens = false;
    if (termAtt != null) {
      try
      {
        hasMoreTokens = buffer.incrementToken();
        while (hasMoreTokens)
        {
          numTokens++;
          int positionIncrement = posIncrAtt != null ? posIncrAtt.getPositionIncrement() : 1;
          if (positionIncrement != 0) {
            positionCount += positionIncrement;
          } else {
            severalTokensAtSamePosition = true;
          }
          hasMoreTokens = buffer.incrementToken();
        }
      }
      catch (IOException e) {}
    }
    try
    {
      buffer.reset();
      
      source.close();
    }
    catch (IOException e) {}
    if (numTokens == 0) {
      return null;
    }
    if (numTokens == 1)
    {
      String term = null;
      try
      {
        boolean hasNext = buffer.incrementToken();
        assert (hasNext == true);
        term = termAtt.term();
      }
      catch (IOException e) {}
      return newTermQuery(new Term(field, term));
    }
    if (severalTokensAtSamePosition)
    {
      if (positionCount == 1)
      {
        BooleanQuery q = newBooleanQuery(true);
        for (int i = 0; i < numTokens; i++)
        {
          String term = null;
          try
          {
            boolean hasNext = buffer.incrementToken();
            assert (hasNext == true);
            term = termAtt.term();
          }
          catch (IOException e) {}
          Query currentQuery = newTermQuery(new Term(field, term));
          
          q.add(currentQuery, BooleanClause.Occur.SHOULD);
        }
        return q;
      }
      MultiPhraseQuery mpq = newMultiPhraseQuery();
      mpq.setSlop(phraseSlop);
      List multiTerms = new ArrayList();
      int position = -1;
      for (int i = 0; i < numTokens; i++)
      {
        String term = null;
        int positionIncrement = 1;
        try
        {
          boolean hasNext = buffer.incrementToken();
          assert (hasNext == true);
          term = termAtt.term();
          if (posIncrAtt != null) {
            positionIncrement = posIncrAtt.getPositionIncrement();
          }
        }
        catch (IOException e) {}
        if ((positionIncrement > 0) && (multiTerms.size() > 0))
        {
          if (enablePositionIncrements) {
            mpq.add((Term[])multiTerms.toArray(new Term[0]), position);
          } else {
            mpq.add((Term[])multiTerms.toArray(new Term[0]));
          }
          multiTerms.clear();
        }
        position += positionIncrement;
        multiTerms.add(new Term(field, term));
      }
      if (enablePositionIncrements) {
        mpq.add((Term[])multiTerms.toArray(new Term[0]), position);
      } else {
        mpq.add((Term[])multiTerms.toArray(new Term[0]));
      }
      return mpq;
    }
    PhraseQuery pq = newPhraseQuery();
    pq.setSlop(phraseSlop);
    int position = -1;
    for (int i = 0; i < numTokens; i++)
    {
      String term = null;
      int positionIncrement = 1;
      try
      {
        boolean hasNext = buffer.incrementToken();
        assert (hasNext == true);
        term = termAtt.term();
        if (posIncrAtt != null) {
          positionIncrement = posIncrAtt.getPositionIncrement();
        }
      }
      catch (IOException e) {}
      if (enablePositionIncrements)
      {
        position += positionIncrement;
        pq.add(new Term(field, term), position);
      }
      else
      {
        pq.add(new Term(field, term));
      }
    }
    return pq;
  }
  
  protected Query getFieldQuery(String field, String queryText, int slop)
    throws ParseException
  {
    Query query = getFieldQuery(field, queryText);
    if ((query instanceof PhraseQuery)) {
      ((PhraseQuery)query).setSlop(slop);
    }
    if ((query instanceof MultiPhraseQuery)) {
      ((MultiPhraseQuery)query).setSlop(slop);
    }
    return query;
  }
  
  protected Query getRangeQuery(String field, String part1, String part2, boolean inclusive)
    throws ParseException
  {
    if (lowercaseExpandedTerms)
    {
      part1 = part1.toLowerCase();
      part2 = part2.toLowerCase();
    }
    try
    {
      DateFormat df = DateFormat.getDateInstance(3, locale);
      df.setLenient(true);
      Date d1 = df.parse(part1);
      Date d2 = df.parse(part2);
      if (inclusive)
      {
        Calendar cal = Calendar.getInstance(locale);
        cal.setTime(d2);
        cal.set(11, 23);
        cal.set(12, 59);
        cal.set(13, 59);
        cal.set(14, 999);
       
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd