2011-01-04 23 views
0

これは、私はちょうどこれを行うに取り掛かるするかどうかはわかりません多門クエリLucene.Net:MultiFiledQueryParserをBooleanQueryに変換するにはどうすればよいですか?

 ''# Variables used by Lucene 
     Dim reader As IndexReader = IndexReader.Open(luceneDirectory, True) 
     Dim searcher As IndexSearcher = New IndexSearcher(reader) 
     Dim parser As QueryParser = New MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_29, 
                   New String() {"title", 
                      "description", 
                      "region", 
                      "pricelow", 
                      "pricehigh", 
                      "url", 
                      "user", 
                      "location"}, 
                     New StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)) 
     Dim query As Query = parser.Parse(search.ToLower) 


     ''# We want to ensure that only relevant dates are being returned. 
     Dim nowValue = DateTools.DateToString(DateTime.Now, DateTools.Resolution.DAY) 
     Dim dateFilter = If(searchPast, Nothing, FieldCacheRangeFilter.NewStringRange("filterdate", 
                        lowerVal:=nowValue, 
                        includeLower:=True, 
                        upperVal:=Nothing, 
                        includeUpper:=False)) 


''#============================================================================ 
''# Here's where I also need to add a regionFilter where I have something like 

''# Dim regionFilter = New FieldCacheTermsFilter("region", New String() {HttpContext.Current.Request.Url.Subdomain}) 

''# This is because we must always ONLY ever return search results that are from 
''# HttpContext.Current.Request.Url.Subdomain (where Subdomain is an extension 
''# method that returns the name of the region... much like Kijiji.ca) 
''#============================================================================ 

     Dim topDocs As TopDocs = searcher.Search(query, dateFilter, 1000) 

をして、私の現在のコードです。ブーリアンクエリを実行して2番目のフィルタを含めることができるように、どうすれば変更できますか?

注:私はまだ

ユーザーのようなフィールドを検索できるようにする必要があります。username
場所:ドイツ
をなど、私が前に厳密にブールクエリを試してみましたが、私ができる

上記の検索条件は使用しないでください。どこが間違っているのか分かりません。

答えて

0

答えはこの

''# Variables used by Lucene 
    Dim reader As IndexReader = IndexReader.Open(luceneDirectory, True) 
    Dim searcher As IndexSearcher = New IndexSearcher(reader) 
    Dim parser As QueryParser = New MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_29, 
                  New String() {"title", 
                     "description", 
                     "region", 
                     "pricelow", 
                     "pricehigh", 
                     "url", 
                     "user", 
                     "location"}, 
                    New StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)) 
    Dim query As Query = parser.Parse(search.ToLower) 

    Dim nowValue = DateTools.DateToString(DateTime.Now, DateTools.Resolution.DAY) 
    Dim dateFilter = If(searchPast, Nothing, FieldCacheRangeFilter.NewStringRange("filterdate", 
                        lowerVal:=nowValue, 
                        includeLower:=True, 
                        upperVal:=Nothing, 
                        includeUpper:=False)) 


     ''# Here's where the extra filtering magic happens 
     ''# First we add the original query to the boolean query 
     ''# Then we add another "MUST" query that says that region has to = Subdomain 
     Dim bquery = New BooleanQuery 
     bquery.Add(query, BooleanClause.Occur.MUST) 
     bquery.Add(New TermQuery(New Term("region", HttpContext.Current.Request.Url.Subdomain)), BooleanClause.Occur.MUST) 

     Dim topDocs As TopDocs = searcher.Search(bquery, dateFilter, 1000) 
のように見えているかのようにそれが表示されます
関連する問題