2012-10-24 20 views
0

我使用Lucene點網絡版本2.9並構建我的查詢如下(GetQuery方法)。我可以使用具有相同查詢的Luke工具從相同索引中獲得結果。但不通過dotnet API。不確定是否是Lucene.net中的錯誤?或者我的錯誤。索引是用標準分析器完成的,並分析了我正在搜索的所有字段。Lucene布爾查詢不工作在網點

注:它與盧克的指數相同。我使用.NET的Lucene 2.94不是Java的Lucene庫

是正在與盧克工具查詢是這樣的:

+(內容:北極星的位置:北極星)+分機:/ PDF/XLS/DOC/DOCX

這是不正常的C#代碼:

private static BooleanQuery GetQuery(string term, string exts) 
    { 
     string[] fields = { MetaKeys.Content, MetaKeys.Location }; 
     MultiFieldQueryParser parser = new MultiFieldQueryParser(fields, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)); 

     Query multiFieldQuery = parser.Parse(term); 
     TermQuery extQuery = new TermQuery(new Term(MetaKeys.Ext, exts)); 

     BooleanQuery combinedQuery = new BooleanQuery(); 
     combinedQuery.Add(multiFieldQuery, BooleanClause.Occur.MUST); 
     if (extQuery != null) 
     { 
      combinedQuery.Add(extQuery, BooleanClause.Occur.MUST); 
     } 

     return combinedQuery; 
    } 

它被用作以下

 string exts = "/pdf/xls/doc/docx"; 
     BooleanQuery combinedQuery = GetQuery(term, exts); 

     TopDocs docs = indexSearch.Search(combinedQuery, to); 

     //resulting in 0 Hits 

請注意那些關閉了我以前的問題的人:給你的原始海報一個機會(至少24小時)糾正它,然後再打開問題。

+0

你可以在返回行放一個斷點,看看這個查詢看起來像什麼嗎? – Bobson

+0

查詢看起來是這樣的: +(內容:polaris位置:polaris)+ ext:/ pdf/xls/doc/docx 它在Luke內部正常工作 – Overture

+0

這很好的證實。不幸的是,我沒有任何其他想法。抱歉。 – Bobson

回答

0

也許你會發現this適用:它的工作原理,如果你需要任何額外的建議,你可以問我,我在這裏活躍! :)

基本上,它描述了很多與你正在做的事情相同的事情,但是它展示了你在這裏沒有做的一些事情;即使用構造的MultiFieldQueryParser對象解析輸入搜索詞並使用BooleanQuery將它們添加在一起。