Example usage for org.apache.lucene.util AttributeSource AttributeSource

List of usage examples for org.apache.lucene.util AttributeSource AttributeSource

Introduction

In this page you can find the example usage for org.apache.lucene.util AttributeSource AttributeSource.

Prototype

public AttributeSource() 

Source Link

Document

An AttributeSource using the default attribute factory AttributeFactory#DEFAULT_ATTRIBUTE_FACTORY .

Usage

From source file:com.lucene.MyMultiTermQuery.java

License:Apache License

protected final TermsEnum getTermsEnum(Terms terms) throws IOException {
    return getTermsEnum(terms, new AttributeSource());
}

From source file:com.sindicetech.siren.index.DocsNodesAndPositionsEnum.java

License:Open Source License

/** Returns the related attributes. */
public AttributeSource attributes() {
    if (atts == null)
        atts = new AttributeSource();
    return atts;//from   w  ww  .  j a  v a2 s.  c o  m
}

From source file:com.sindicetech.siren.search.node.MultiNodeTermQuery.java

License:Open Source License

/**
 * Convenience method, if no attributes are needed:
 * This simply passes empty attributes and is equal to:
 * <code>getTermsEnum(terms, new AttributeSource())</code>
 *//* w  w  w . j  a v a 2s  . c o  m*/
protected final TermsEnum getTermsEnum(final Terms terms) throws IOException {
    return this.getTermsEnum(terms, new AttributeSource());
}

From source file:newseman.SemanticTaggerTokenFilter.java

License:Apache License

/**
 * Creates an instance for the given underlying stream and synonym table.
 * //  ww w.  j a  v  a 2  s . co  m
 * @param input
 *            the underlying child token stream
 * @param seman
 *            instance of {@link SemanticTagger} which will be called to
 *            translate the input {@link TokenStream}
 */
public SemanticTaggerTokenFilter(TokenStream input, SemanticTagger seman) {

    super(input);
    if (input == null)
        throw new IllegalArgumentException("input must not be null");
    if (seman == null)
        throw new IllegalArgumentException("seman must not be null");
    this.semanTagger = seman;

    if (wrapper == null) {
        wrapper = new AttributeSource();
        //wrapper = input.cloneAttributes();
        wrapper.addAttribute(CharTermAttribute.class);
        wrapper.addAttribute(FlagsAttribute.class);
        wrapper.addAttribute(OffsetAttribute.class);
        wrapper.addAttribute(TypeAttribute.class);
        wrapper.addAttribute(PositionIncrementAttribute.class);
        wrapper.addAttribute(SemanticTagAttribute.class);
        wrapper.addAttribute(PayloadAttribute.class);
    }

    valueSeparator = Pattern.quote(semanTagger.getSeparator());
}

From source file:org.eu.bitzone.Leia.java

License:Apache License

private void addTermsEnum(final Object parent, final Class<? extends Query> clz, final String field,
        final Query instance) throws Exception {
    final Method m = clz.getDeclaredMethod("getTermsEnum", Terms.class, AttributeSource.class);
    m.setAccessible(true);//from w w w  . j a  v  a 2s  .c o  m
    final Terms terms = ar.terms(field);
    final TermsEnum fte = (TermsEnum) m.invoke(instance, terms, new AttributeSource());
    final Object n1 = create("node");
    final String clazz = fte.getClass().getName();
    setString(n1, "text", clazz);
    add(parent, n1);
    while (fte.next() != null) {
        final Object n2 = create("node");
        setString(n2, "text", "'" + fte.term().utf8ToString() + "', docFreq=" + fte.docFreq()
                + ", totalTermFreq=" + fte.totalTermFreq());
        add(n1, n2);
    }

}

From source file:org.getopt.luke.Luke.java

License:Apache License

private void addTermsEnum(Object parent, Class<? extends Query> clz, String field, Query instance)
        throws Exception {
    Method m = clz.getDeclaredMethod("getTermsEnum", Terms.class, AttributeSource.class);
    m.setAccessible(true);//from w ww .ja v  a2 s  . c  om
    Terms terms = ar.terms(field);
    TermsEnum fte = (TermsEnum) m.invoke(instance, terms, new AttributeSource());
    Object n1 = create("node");
    String clazz = fte.getClass().getName();
    setString(n1, "text", clazz);
    add(parent, n1);
    while (fte.next() != null) {
        Object n2 = create("node");
        setString(n2, "text", "'" + fte.term().utf8ToString() + "', docFreq=" + fte.docFreq()
                + ", totalTermFreq=" + fte.totalTermFreq());
        add(n1, n2);
    }

}

From source file:org.opengrok.suggest.query.SuggesterFuzzyQuery.java

License:Open Source License

/** {@inheritDoc} */
@Override/*from w w w  . ja  v  a  2  s.c o m*/
public TermsEnum getTermsEnumForSuggestions(final Terms terms) throws IOException {
    if (terms == null) {
        return TermsEnum.EMPTY;
    }
    return getTermsEnum(terms, new AttributeSource());
}

From source file:org.opengrok.suggest.query.SuggesterPrefixQuery.java

License:Open Source License

/** {@inheritDoc} */
@Override/*from   ww w .j  a v  a2 s. c o m*/
public TermsEnum getTermsEnumForSuggestions(final Terms terms) throws IOException {
    if (terms == null) {
        return TermsEnum.EMPTY;
    }
    return super.getTermsEnum(terms, new AttributeSource());
}

From source file:org.pageseeder.flint.lucene.search.Terms.java

License:Apache License

/**
 * Loads all the fuzzy terms in the list of terms given the reader.
 *
 * @param reader Index reader to use./* ww  w  . ja va 2  s . c o  m*/
 * @param values The list of terms to load.
 * @param term   The term to use.
 *
 * @throws IOException If an error is thrown by the fuzzy term enumeration.
 */
public static void fuzzy(IndexReader reader, List<String> values, Term term, int minSimilarity)
        throws IOException {
    AttributeSource atts = new AttributeSource();
    Fields fields = MultiFields.getFields(reader);
    org.apache.lucene.index.Terms terms = fields == null ? null : fields.terms(term.field());
    if (terms == null)
        return;
    FuzzyTermsEnum fuzzy = new FuzzyTermsEnum(terms, atts, term, minSimilarity, 0, false);
    BytesRef val;
    BytesRef searched = term.bytes();
    while ((val = fuzzy.next()) != null) {
        if (!searched.bytesEquals(val))
            values.add(val.utf8ToString());
    }
}

From source file:org.pageseeder.flint.lucene.search.Terms.java

License:Apache License

/**
 * Loads all the fuzzy terms in the list of terms given the reader.
 *
 * @param reader  Index reader to use.// w  ww . j  a v  a  2s  . c o m
 * @param bucket  Where to store the terms.
 * @param term    The term to use.
 *
 * @throws IOException If an error is thrown by the fuzzy term enumeration.
 */
@Beta
public static void fuzzy(IndexReader reader, Bucket<Term> bucket, Term term, int minSimilarity)
        throws IOException {
    AttributeSource atts = new AttributeSource();
    Fields fields = MultiFields.getFields(reader);
    org.apache.lucene.index.Terms terms = fields == null ? null : fields.terms(term.field());
    if (terms == null)
        return;
    FuzzyTermsEnum fuzzy = new FuzzyTermsEnum(terms, atts, term, minSimilarity, 0, true);
    BytesRef val;
    BytesRef searched = term.bytes();
    while ((val = fuzzy.next()) != null) {
        if (!searched.bytesEquals(val)) {
            Term t = new Term(term.field(), BytesRef.deepCopyOf(val));
            bucket.add(t, reader.docFreq(t));
        }
    }
}