0

我像这样索引一个布尔字段:

[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\""

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

顺便说一句,有没有更有效的方法来确定总数?

谢谢!

基督教

4

2 回答 2

1

看来,如果我使用 Tokenized 进行索引,它就可以工作。

基督教

于 2011-03-15T08:43:55.970 回答
0

我有同样的问题,但在 Lucene.Net 3.0 中,语法是“ANALYZED”

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

与“NOT_ANALYZED”相反:

doc.Add(new Field("IsPrivate", objectName.IsPrivate.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
于 2014-10-09T11:08:06.370 回答