English 中文(简体)
• 如何在卢塞内使用多领域频率和过滤器
原标题:How to use multifieldquery and filters in Lucene.net

我想对地皮进行多场实地搜索。 净指数,但根据其中一个领域过滤结果。 这里指的是我目前所做的工作:

为了对领域进行索引编制,定义如下:

doc.Add(new Field("id", id.ToString(), Field.Store.YES, Field.Index.UN_TOKENIZED));
doc.Add(new Field("title", title, Field.Store.NO, Field.Index.TOKENIZED));
doc.Add(new Field("summary", summary, Field.Store.NO, Field.Index.TOKENIZED, Field.TermVector.YES));
doc.Add(new Field("description", description, Field.Store.NO, Field.Index.TOKENIZED, Field.TermVector.YES));
doc.Add(new Field("distribution", distribution, Field.Store.NO, Field.Index.UN_TOKENIZED));

在我进行搜查时,我做了以下工作:

MultiFieldQueryParser parser = new MultiFieldQueryParser(new string[]{"title", "summary", "description"}, analyzer);
parser.SetDefaultOperator(QueryParser.Operator.AND);
Query query = parser.Parse(text);

BooleanQuery bq = new BooleanQuery();
TermQuery tq = new TermQuery(new Term("distribution", distribution));
bq.Add(tq, BooleanClause.Occur.MUST);
Filter filter = new QueryFilter(bq);

Hits hits = searcher.Search(query, filter);

然而,结果总是0次。

我做了什么错误?

问题回答

我认为,我现在有一个解决办法。 我放弃了QueryFilter的使用,并且正在使用一个包裹,以限制多领域的成果。 因此,《刑法》将探讨这样的问题:

MultiFieldQueryParser parser = new MultiFieldQueryParser(new string[]{"title", "summary", "description"}, analyzer); 
parser.SetDefaultOperator(QueryParser.Operator.AND); 
Query query = parser.Parse(text); 

BooleanQuery bq = new BooleanQuery(); 
TermQuery tq = new TermQuery(new Term("distribution", distribution)); 
bq.Add(tq, BooleanClause.Occur.MUST); 
bq.Add(query, BooleanClause.Occur.MUST)

Hits hits = searcher.Search(bq); 




相关问题
How do I reset or override IE CSS filters?

I m using the proprietry MS filter property to try and create a non ugly equivalent to css3 text-shadow and box-shadow; I was actually doing really well until I hit this problem. It looks like when ...

PHP filter string input, cut off all newlines, 1 chars

I m writing in PHP! There s a user string input, and I want to cut off all newlines,1 chars that are more than 1 in a row (avoid <br /><br />...). example: I am a SPaMmEr! would ...

The Fastest DataStructure to Filter with in C#

Currently we are filtering and sorting data with a datatable. /// <summary> /// Filters the data table and returns a new data table with only the filtered rows. /// </summary>...

How to dynamically update a ListView on Android [closed]

On Android, how can I a ListView that filters based on user input, where the items shown are updated dynamically based on the TextView value? I m looking for something like this: -------------------...

Handling no results for docmd.applyfilter

I have an Access app where I use search functionality. I have a TextBox and a Search Button on the form, and it does a wildcard search of whatever the user enters in the TextBox, and displays the ...

Best method to scale DropShadows in AS3?

I m creating a flash application that makes use of both the dropShadow filter and scaling of various sprites. And therein lies the problem: This filter supports Stage scaling. However, it does ...

热门标签