Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/260.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使用Lucene.net中的自定义令牌过滤器从令牌中删除逗号_C#_.net_Visual Studio 2010_Lucene_Lucene.net - Fatal编程技术网

C# 如何使用Lucene.net中的自定义令牌过滤器从令牌中删除逗号

C# 如何使用Lucene.net中的自定义令牌过滤器从令牌中删除逗号,c#,.net,visual-studio-2010,lucene,lucene.net,C#,.net,Visual Studio 2010,Lucene,Lucene.net,我有一个自定义的tokenfilter设置来解析关键字,例如 oracle,java,sybase,vb.net etc. 进入 它工作正常,但是其中一个测试文档有以下文本 ,oracle java,sybase,unix 我想把前面的逗号从 ,oracle 使用下面的代码 public override bool IncrementToken() { if (!input.IncrementToken()) return fals

我有一个自定义的tokenfilter设置来解析关键字,例如

oracle,java,sybase,vb.net etc. 
进入

它工作正常,但是其中一个测试文档有以下文本

,oracle java,sybase,unix
我想把前面的逗号从

,oracle
使用下面的代码

    public override bool IncrementToken()
    {
        if (!input.IncrementToken())
            return false;


        char[] buffer = termAtt.TermBuffer();
        int bufferLength = termAtt.TermLength();

...
        else if (bufferLength > 1 && buffer[0] == ',')
        {
            // strip the starting , off !
            offsetAtt.SetOffset(offsetAtt.StartOffset + 1, offsetAtt.EndOffset);
        // where offsetAtt = AddAttribute<IOffsetAttribute>();
        }
        ...

        return true;

    }
public override bool IncrementToken()
{
如果(!input.IncrementToken())
返回false;
char[]buffer=termAtt.TermBuffer();
int bufferLength=termAtt.TermLength();
...
else if(bufferLength>1&&buffer[0]==',')
{
//脱掉起跑线,脱掉!
offsetAtt.SetOffset(offsetAtt.StartOffset+1,offsetAtt.EndOffset);
//其中offsetAtt=AddAttribute();
}
...
返回true;
}
但是,这不会删除逗号

有没有关于如何使这项工作的帮助


感谢

Lucene中的令牌基于属性工作,即令牌的每个属性(如文本值、偏移量等)都是一个属性

令牌的文本值与令牌TermAttribute.class关联

更改偏移量和其他属性后,可能还需要自行更改文本,可能需要使用以下代码段

private final TermAttribute termAtt; // instance variable

termAtt = addAttribute(TermAttribute.class); // initialization in constructor 

....


 else if (bufferLength > 1 && buffer[0] == ',')
        {

            // strip the starting , off !
            offsetAtt.SetOffset(offsetAtt.StartOffset + 1, offsetAtt.EndOffset);

        // update the termAtt
            termAtt.setTermBuffer("sub-content of the buffer");

        }

....
让我知道它是否有效

private final TermAttribute termAtt; // instance variable

termAtt = addAttribute(TermAttribute.class); // initialization in constructor 

....


 else if (bufferLength > 1 && buffer[0] == ',')
        {

            // strip the starting , off !
            offsetAtt.SetOffset(offsetAtt.StartOffset + 1, offsetAtt.EndOffset);

        // update the termAtt
            termAtt.setTermBuffer("sub-content of the buffer");

        }

....