使用多标准查询和localparams查询Solr(Solr.net)

时间:2012-12-06 15:19:17

标签: solr filtering tagging solrnet

我正在尝试这样做:

http://solr:8080/solr/select/?q=name_make:[make]+name_model:[model]&rows=10000&wt=json&fq={!tag=dt}name_model:[model]&facet=on&facet.field={!ex=dt}name_model&facet.sort=count&facet.field.mincount=1

使用solr.net - 我有这个:

var multipleQuery = new SolrMultipleCriteriaQuery(queryList, "AND");
var Facets = new FacetParameters();

Facets.Queries.Add(new SolrFacetFieldQuery(new LocalParams{{"ex", "dt"}} +"name_model") { MinCount = 1, Sort = true});

 List<ISolrQuery> filter = new List<ISolrQuery>();
 filter.Add(new LocalParams { { "tag", "dt" }, { "mincount", "1" } } + Query.Field("name_model").Is(NameModel));

var result = solr.Query(multipleQuery, new QueryOptions
                                                  {
                                                      FilterQueries = filter,
                                                      Rows = rows,
                                                      Facet = facets, 
                                                      Start = index
                                                  });

我期待像

这样的东西
  • make 1 [] 101
  • make 2 [] 144
  • 制作3 [x] 232
  • make 2 [] 32

但只能获得

  • 制作3 [x] 232

从我的追踪中我看到了

  • Solr q(name_make:[make] AND name_model:[model] AND price:[0 TO 250000] AND year_registration:[0 TO 10000000])0,023619 0,000006
  • Solr fq {!tag = dt mincount = 1} name_model:A3

我错过了一件作品,还是走错了路?

2 个答案:

答案 0 :(得分:0)

在原始查询中(在顶部),您有q=name_make:[make]+name_model:[model],而在name_make:[make] **AND** name_model:[model]以下,您的默认运营商可能会遇到问题。您可以使用SolrNet使用'+'运算符而不是&amp;&amp;。

来保留它

.. new SolrQuery("name_make:[make]") + new SolrQuery("name_model:[model]")

..将返回给您:name_make:[make] name_model:[model]

在哪里..

new SolrQuery("name_make:[make]") && new SolrQuery("name_model:[model]")

..将返回给您:name_make:[make] AND name_model:[model]

不确定是不是这样,但是为了以防万一。

答案 1 :(得分:0)

Please try to pass the string arraty that contains multiple field names and search text in the below method. I will return the solrnet query for search with multiple filed name with OR condition.

public ISolrQuery BuildQuery(string[] SearchFields, string SearchText)
    {

        AbstractSolrQuery firstQuery = new SolrQueryByField(parameters.SearchFields[0], SearchText) { Quoted = false };
        for (var i = 1; i < SearchFields.Length; i++)
        {
            firstQuery = firstQuery || new SolrQueryByField(SearchFields[i], SearchText) { Quoted = false };
        }

        return firstQuery;
    }