Nếu bạn đang sử dụng SolrSharp, nó không hỗ trợ truy vấn phủ định.
Bạn cần thay đổi QueryParameter.cs (Tạo một tham số mới)
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; }
}
Và trong lớp QueryParameterCollection.cs, ToString() ghi đè lên, trông nếu tham số âm là đúng
arQ[x] = (qp.NegativeQuery ? "-(" : "(") + qp.ToString() + ")" + (qp.Boost != 1 ? "^" + qp.Boost.ToString() : "");
Khi bạn gọi trình tạo tham số, nếu đó là giá trị âm. thay đổi đơn giản các propertie
List<QueryParameter> QueryParameters = new List<QueryParameter>();
QueryParameters.Add(new QueryParameter("PartnerList", "[* TO *]", ParameterJoin.AND, true));
Nguồn
2012-09-11 14:38:12
Mặc dù trang SolrQuerySyntax nói -id: [* TO *], chỉ -id: ["" TO *] làm việc cho tôi trên trang 1.4. –
Không '? Q = -id: *' hoạt động không? – user2043553
@ user2043553 Không, nếu bạn '? Q = -id: *' bạn nhận được 'Không thể phân tích cú pháp' -q: * ':' * 'hoặc'? ' không được phép làm ký tự đầu tiên trong WildcardQuery' –