internal static bool IsConditionless(ITermsQuery q) => q.Field.IsConditionless() ||
 (q.Terms == null ||
  !q.Terms.HasAny() ||
  q.Terms.All(t => t == null ||
              ((t as string)?.IsNullOrEmpty()).GetValueOrDefault(false))
 )
 &&
 (q.TermsLookup == null ||
  q.TermsLookup.Id == null ||
  q.TermsLookup.Path.IsConditionless() ||
  q.TermsLookup.Index == null
 );
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var         filter = new TermsQueryDescriptor <object, object>();
            ITermsQuery f      = filter;

            if (reader.TokenType != JsonToken.StartObject)
            {
                return(null);
            }

            var depth = reader.Depth;

            while (reader.Read() && reader.Depth >= depth && reader.Value != null)
            {
                var property = reader.Value as string;
                switch (property)
                {
                case "disable_coord":
                    reader.Read();
                    f.DisableCoord = reader.Value as bool?;
                    break;

                case "minimum_should_match":
                    reader.Read();
                    var min = serializer.Deserialize <MinimumShouldMatch>(reader);
                    f.MinimumShouldMatch = min;
                    break;

                case "boost":
                    reader.Read();
                    f.Boost = reader.Value as double?;
                    break;

                case "_name":
                    f.Name = reader.ReadAsString();
                    break;

                default:
                    f.Field = property;
                    //reader.Read();
                    ReadTerms(f, reader, serializer);
                    //reader.Read();
                    break;
                }
            }
            return(filter);
        }
Example #3
0
        private void ReadTerms(ITermsQuery termsQuery, JsonReader reader, JsonSerializer serializer)
        {
            reader.Read();
            if (reader.TokenType == JsonToken.StartObject)
            {
                var ef    = new FieldLookup();
                var depth = reader.Depth;
                while (reader.Read() && reader.Depth >= depth && reader.Value != null)
                {
                    var property = reader.Value as string;
                    switch (property)
                    {
                    case "id":
                        reader.Read();
                        var id = serializer.Deserialize <Id>(reader);
                        ef.Id = id;
                        break;

                    case "index":
                        reader.Read();
                        ef.Index = reader.Value as string;
                        break;

                    case "type":
                        reader.Read();
                        ef.Type = reader.Value as string;
                        break;

                    case "path":
                        reader.Read();
                        ef.Path = reader.Value as string;
                        break;

                    case "routing":
                        reader.Read();
                        ef.Routing = reader.Value as string;
                        break;
                    }
                }
                termsQuery.TermsLookup = ef;
            }
            else if (reader.TokenType == JsonToken.StartArray)
            {
                var values = JArray.Load(reader).Values <object>();
                termsQuery.Terms = values;
            }
        }
		private void ReadTerms(ITermsQuery termsQuery, JsonReader reader, JsonSerializer serializer)
		{
			reader.Read();
			if (reader.TokenType == JsonToken.StartObject)
			{
				var ef = new FieldLookup();
				var depth = reader.Depth;
				while (reader.Read() && reader.Depth >= depth && reader.Value != null)
				{
					var property = reader.Value as string;
					switch (property)
					{
						case "id":
							reader.Read();
							var id = serializer.Deserialize<Id>(reader);
							ef.Id = id;
							break;
						case "index":
							reader.Read();
							ef.Index = reader.Value as string;
							break;
						case "type":
							reader.Read();
							ef.Type = reader.Value as string;
							break;
						case "path":
							reader.Read();
							ef.Path = reader.Value as string;
							break;
						case "routing":
							reader.Read();
							ef.Routing = reader.Value as string;
							break;
					}
				}
				termsQuery.TermsLookup = ef;
			}
			else if (reader.TokenType == JsonToken.StartArray)
			{
				var values = JArray.Load(reader).Values<object>();
				termsQuery.Terms = values;
			}
		}
Example #5
0
        private void ReadTerms(ITermsQuery termsQuery, JsonReader reader)
        {
            reader.Read();
            if (reader.TokenType == JsonToken.StartObject)
            {
                var ef    = new ExternalFieldDeclaration();
                var depth = reader.Depth;
                while (reader.Read() && reader.Depth >= depth && reader.Value != null)
                {
                    var property = reader.Value as string;
                    switch (property)
                    {
                    case "id":
                        reader.Read();
                        ef.Id = reader.Value as string;
                        break;

                    case "index":
                        reader.Read();
                        ef.Index = reader.Value as string;
                        break;

                    case "type":
                        reader.Read();
                        ef.Type = reader.Value as string;
                        break;

                    case "path":
                        reader.Read();
                        ef.Path = reader.Value as string;
                        break;
                    }
                }
                termsQuery.ExternalField = ef;
            }
            else if (reader.TokenType == JsonToken.StartArray)
            {
                var values = JArray.Load(reader).Values <string>();
                termsQuery.Terms = values;
            }
        }
/*        private void loadItems()
 *      {
 *          string request = "ItemQueryRq";
 *          connectToQB();
 *          int count = getCount(request);
 *          IMsgSetResponse responseMsgSet = processRequestFromQB(buildItemQueryRq(new string[] { "FullName" }, null));
 *          string[,] retVal = parseItemQueryRs(responseMsgSet, count, 1);
 *          disconnectFromQB();
 *          string[] itemList = getItemFullNames(retVal);
 *          fillComboBox(comboBox_Item1, itemList);
 *          fillComboBox(comboBox_Item2, itemList);
 *          fillComboBox(comboBox_Item3, itemList);
 *          fillComboBox(comboBox_Item4, itemList);
 *          fillComboBox(comboBox_Item5, itemList);
 *      }
 *
 *      private string[] getItemFullNames(string[,] retVal)
 *      {
 *          //retVal[countOfRows, arraySize]
 *          //arraySize is 3 for FullName, Desc, Price but in this case 1 for FullName only
 *          int countOfRows = retVal.GetUpperBound(0);
 *          string[] itemList = new string[countOfRows];
 *          for (int i = 0; i < countOfRows; i++)
 *          {
 *              itemList[i] = retVal[i, 0];
 *          }
 *          return itemList;
 *      }
 *
 *      private void loadTerms()
 *      {
 *          string request = "TermsQueryRq";
 *          connectToQB();
 *          int count = getCount(request);
 *          IMsgSetResponse responseMsgSet = processRequestFromQB(buildTermsQueryRq());
 *          string[] termsList = parseTermsQueryRs(responseMsgSet, count);
 *          disconnectFromQB();
 *          fillComboBox(this.comboBox_Terms, termsList);
 *      }
 *
 *      private void loadSalesTaxCodes()
 *      {
 *          string request = "SalesTaxCodeQueryRq";
 *          connectToQB();
 *          int count = getCount(request);
 *          IMsgSetResponse responseMsgSet = processRequestFromQB(buildSalesTaxCodeQueryRq());
 *          string[] salesTaxCodeList = parseSalesTaxCodeQueryRs(responseMsgSet, count);
 *          disconnectFromQB();
 *          fillComboBox(this.comboBox_Tax1, salesTaxCodeList);
 *          fillComboBox(this.comboBox_Tax2, salesTaxCodeList);
 *          fillComboBox(this.comboBox_Tax3, salesTaxCodeList);
 *          fillComboBox(this.comboBox_Tax4, salesTaxCodeList);
 *          fillComboBox(this.comboBox_Tax5, salesTaxCodeList);
 *      }
 *
 *      private void loadCustomerMsg()
 *      {
 *          string request = "CustomerMsgQueryRq";
 *          connectToQB();
 *          int count = getCount(request);
 *          IMsgSetResponse responseMsgSet = processRequestFromQB(buildCustomerMsgQueryRq(new string[] { "Name" }, null));
 *          string[] customerMsgList = parseCustomerMsgQueryRs(responseMsgSet, count);
 *          disconnectFromQB();
 *          fillComboBox(comboBox_CustomerMessage, customerMsgList);
 *      }
 *
 *      private string getBillShipTo(string customerName, string billOrShip)
 *      {
 *          connectToQB();
 *          IMsgSetResponse responseMsgSet = processRequestFromQB(buildCustomerQueryRq(new string[] { billOrShip }, customerName));
 *          string[] billShipTo = parseCustomerQueryRs(responseMsgSet, 1);
 *          if (billShipTo[0] == null) billShipTo[0] = "";
 *          disconnectFromQB();
 *          return billShipTo[0];
 *      }
 *
 *      private string getCurrencyCode(string customerName)
 *      {
 *          connectToQB();
 *          IMsgSetResponse responseMsgSet = processRequestFromQB(buildCustomerQueryRq(new string[] { "CurrencyRef" }, customerName));
 *          string[] currencyCode = parseCustomerQueryRs(responseMsgSet, 1);
 *          disconnectFromQB();
 *          return currencyCode[0];
 *      }
 *
 *      private string getExchangeRate(string currencyName)
 *      {
 *          connectToQB();
 *          IMsgSetResponse responseMsgSet = processRequestFromQB(buildCurrencyQueryRq(currencyName));
 *          string[] exrate = parseCurrencyQueryRs(responseMsgSet, 1);
 *          disconnectFromQB();
 *          if (exrate[0] == null || exrate[0] == "") exrate[0] = "1.0";
 *          return exrate[0];
 *      }
 *
 *      // REQUEST BUILDING
 *      private IMsgSetRequest buildPreferencesQueryRq(string[] includeRetElement, string fullName)
 *      {
 *          IMsgSetRequest requestMsgSet = sessionManager.getMsgSetRequest();
 *          requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;
 *          IPreferencesQuery prefQuery = requestMsgSet.AppendPreferencesQueryRq();
 *          for (int x = 0; x < includeRetElement.Length; x++)
 *          {
 *              prefQuery.IncludeRetElementList.Add(includeRetElement[x]);
 *          }
 *          return requestMsgSet;
 *      }
 */
        private IMsgSetRequest buildDataCountQuery(string request)
        {
            IMsgSetRequest requestMsgSet = sessionManager.getMsgSetRequest();

            requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue;
            switch (request)
            {
            case "CustomerQueryRq":
                ICustomerQuery custQuery = requestMsgSet.AppendCustomerQueryRq();
                custQuery.metaData.SetValue(ENmetaData.mdMetaDataOnly);
                break;

            case "ItemQueryRq":
                IItemQuery itemQuery = requestMsgSet.AppendItemQueryRq();
                itemQuery.metaData.SetValue(ENmetaData.mdMetaDataOnly);
                break;

            case "TermsQueryRq":
                ITermsQuery termsQuery = requestMsgSet.AppendTermsQueryRq();
                termsQuery.metaData.SetValue(ENmetaData.mdMetaDataOnly);
                break;

            case "SalesTaxCodeQueryRq":
                ISalesTaxCodeQuery salesTaxQuery = requestMsgSet.AppendSalesTaxCodeQueryRq();
                salesTaxQuery.metaData.SetValue(ENmetaData.mdMetaDataOnly);
                break;

            case "CustomerMsgQueryRq":
                ICustomerMsgQuery custMsgQuery = requestMsgSet.AppendCustomerMsgQueryRq();
                custMsgQuery.metaData.SetValue(ENmetaData.mdMetaDataOnly);
                break;

            default:
                break;
            }
            return(requestMsgSet);
        }
Example #7
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var         filter = new TermsQuery();
            ITermsQuery f      = filter;

            if (reader.TokenType != JsonToken.StartObject)
            {
                return(null);
            }

            var depth = reader.Depth;

            while (reader.Read() && reader.Depth >= depth && reader.Value != null)
            {
                var property = reader.Value as string;
                switch (property)
                {
                case "boost":
                    reader.Read();
                    f.Boost = reader.Value as double?;
                    break;

                case "_name":
                    f.Name = reader.ReadAsString();
                    break;

                default:
                    f.Field = property;
                    //reader.Read();
                    ReadTerms(f, reader, serializer);
                    //reader.Read();
                    break;
                }
            }
            return(filter);
        }
 public virtual void Visit(ITermsQuery query)
 {
     Write("terms");
 }
Example #9
0
 public virtual void Visit(ITermsQuery query)
 {
 }
Example #10
0
 public virtual void Visit(ITermsQuery query)
 {
     Write("terms");
 }
 public virtual void Visit(ITermsQuery customFiltersScore)
 {
 }
		private void ReadTerms(ITermsQuery termsQuery, JsonReader reader)
		{
			reader.Read();
			if (reader.TokenType == JsonToken.StartObject)
			{
				var ef = new ExternalFieldDeclaration();
				var depth = reader.Depth;
				while (reader.Read() && reader.Depth >= depth && reader.Value != null)
				{
					var property = reader.Value as string;
					switch (property)
					{
						case "id":
							reader.Read();
							ef.Id = reader.Value as string;
							break;
						case "index":
							reader.Read();
							ef.Index = reader.Value as string;
							break;
						case "type":
							reader.Read();
							ef.Type = reader.Value as string;
							break;
						case "path":
							reader.Read();
							ef.Path = reader.Value as string;
							break;
					}
				}
				termsQuery.ExternalField = ef;
			}
			else if (reader.TokenType == JsonToken.StartArray)
			{
				var values = JArray.Load(reader).Values<string>();
				termsQuery.Terms = values;
			}
		}
		public virtual void Visit(ITermsQuery query) { }
		public virtual void Visit(ITermsQuery customFiltersScore)
		{
		}