2011-03-08 82 views
0

I指数这样的布尔字段:问题布尔字段

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

没有成功。任何想法可能是错的?

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

谢谢!

基督教

回答

1

看来,如果我用记号化来索引它的工作原理。

基督教

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));