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)


        ''# 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番目のフィルターを含めることができるように変更するにはどうすればよいですか?

注:次のようなフィールドで検索できるようにする必要があります

ユーザー:ユーザー名
場所:ドイツ
など

以前に厳密にブールクエリを試しましたが、上記の検索用語を使用できませんでした。どこが間違っていたのかわからない。

4

1 に答える 1

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)
于 2011-01-04T06:01:04.050 に答える