How to query SOLR for empty fields?

前端 未结 7 997
无人共我
无人共我 2020-12-04 08:02

I have a large solr index, and I have noticed some fields are not updated correctly (the index is dynamic).

This has resulted in some fields having an empty \"id\" f

相关标签:
7条回答
  • 2020-12-04 08:30

    you can do it with filter query q=*:*&fq=-id:*

    0 讨论(0)
  • 2020-12-04 08:40

    Try this:

    ?q=-id:["" TO *]
    
    0 讨论(0)
  • 2020-12-04 08:48

    One caveat! If you want to compose this via OR or AND you cannot use it in this form:

    -myfield:*
    

    but you must use

    (*:* NOT myfield:*)
    

    This form is perfectly composable. Apparently SOLR will expand the first form to the second, but only when it is a top node. Hope this saves you some time!

    0 讨论(0)
  • 2020-12-04 08:48

    You can also use it like this.

    fq=!id:['' TO *]
    
    0 讨论(0)
  • 2020-12-04 08:52

    If you are using SolrSharp, it does not support negative queries.

    You need to change QueryParameter.cs (Create a new parameter)

    private bool _negativeQuery = false;
    
    public QueryParameter(string field, string value, ParameterJoin parameterJoin = ParameterJoin.AND, bool negativeQuery = false)
    {
        this._field = field;
        this._value = value.Trim();
        this._parameterJoin = parameterJoin;
        this._negativeQuery = negativeQuery;
    }
    
    public bool NegativeQuery
    {
        get { return _negativeQuery; }
        set { _negativeQuery = value; }
    }
    

    And in QueryParameterCollection.cs class, the ToString() override, looks if the Negative parameter is true

    arQ[x] = (qp.NegativeQuery ? "-(" : "(") + qp.ToString() + ")" + (qp.Boost != 1 ? "^" + qp.Boost.ToString() : "");
    

    When you call the parameter creator, if it's a negative value. Simple change the propertie

    List<QueryParameter> QueryParameters = new List<QueryParameter>();
    QueryParameters.Add(new QueryParameter("PartnerList", "[* TO *]", ParameterJoin.AND, true));
    
    0 讨论(0)
  • 2020-12-04 08:55

    According to SolrQuerySyntax, you can use q=-id:[* TO *].

    0 讨论(0)
提交回复
热议问题