// ----------------------------------------------------------------------- // // // 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. // // // ----------------------------------------------------------------------- namespace Lucene.Net.Analysis.TokenAttributes { using System.Diagnostics.CodeAnalysis; using Lucene.Net.Index; using Lucene.Net.Util; /// /// This attribute is requested by the /// to index the contents. It can be used to customize the byte[] encoding of terms. /// /// /// /// The expected use is to call then invoke /// for each term. /// /// /// Experimental: This is a very expert API, please /// and its implementation of this method for UTF-8 terms. /// /// /// TermToBytesRefAttribute attribute = tokenStream.GetAttribute(typeof(TermToBytesRefAttribute)); /// BytesRef bytes = attribute.BytesRef; /// /// while(attribute.IncrementToken()) /// { /// int hash attribute.FillBytesRef(); /// if (isInteresting(bytes)) /// { /// // do something with it. /// Use(new BytesRef(bytes)); /// } /// } /// /// [SuppressMessage("Microsoft.Naming", "CA1711:IdentifiersShouldNotHaveIncorrectSuffix", Justification = "The class was called Attribute in Java. It would be fun to call it Annotation. However, " + "its probably best to try to honor the correlating names when possible.")] public interface ITermToBytesRefAttribute { /// /// Gets the . The bytes are updated /// from the current term when the invoker calls . /// /// The bytes ref. BytesRef BytesRef { get; } /// /// Updates the bytes to contain /// the term's final encoding. Then it returns its hashcode. /// /// /// /// Implement the following code for performance reasons, if /// the code can calculate the has on-the-fly. If this is not the /// case, just return the 's hashcode. /// /// /// int hash = 0; /// for(int i = this.termBytes.Offset; i < this.termBytes.Offset + this.termBytes.Length; i++) /// hash = (31*hash) + this.termBytes.Bytes[i]; /// /// /// The hashcode from the 's hashcode. int FillBytesRef(); } }