布尔字段的问题

时间:2011-03-08 16:18:23

标签: lucene.net nhibernate.search

我索引一个布尔字段,如下所示:

[Field(Index.UnTokenized, Store = Store.No)]
public virtual bool P { get; set; }

我的查询代码如下所示:

public IList<MappedSequence> Query(string term, out int total, int page, int pageSize)
{
    if (term.ToString().Equals("") == false)
    {
    var parser = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_29, new[] { "Query" }, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29));
    Query query = parser.Parse(term);

    IFullTextSession session = Search.CreateFullTextSession(this.Session);
    IQuery fullTextQuery = session.CreateFullTextQuery(query, new[] { typeof(MappedSequence) });
    total = fullTextQuery.List<MappedSequence>().Count();
    return fullTextQuery.List<MappedSequence>().Skip((page - 1) * pageSize).Take(pageSize).ToList<MappedSequence>();
    }
    else
    {
    total = 0;
    return null;
    }
}

这适用于其他索引字段,但不适用于布尔字段。我尝试了各种各样的术语:

"P:\"TRUE\""
"P:\"1\""

没有成功。什么想法可能是错的?

BTW是否有更有效的方法来确定总数?

谢谢!

基督教

2 个答案:

答案 0 :(得分:1)

如果我使用Tokenized进行索引,它似乎可以工作。

基督教

答案 1 :(得分:0)

我有同样的问题,但在Lucene.Net 3.0中,语法是&#34; ANALYZED&#34;

doc.Add(new Field("IsPrivate", objectName.IsPrivate.ToString(), Field.Store.YES, Field.Index.ANALYZED));

而不是&#34; NOT_ANALYZED&#34;:

doc.Add(new Field("IsPrivate", objectName.IsPrivate.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
相关问题