Developer forum

Forum » Development » Searching for integers in index

Searching for integers in index

Anders Ebdrup
Reply

Hi Dw,

 

When searching for integers in the index there seems to be a problem with the case of the prefixed "P" in the RangeCriteria. When I make a custom query I have to use "p" to get the desired result. I am using v8.2.3.0

 

By the way it would be great to be able to see the actual Lucene query for debugging and testing purposes.

 

Best regards, Anders


Replies

 
Morten Bengtson
Reply

Hi Anders,

 

I assume that you are building some kind of custom search functionality by using the Dynamicweb.Searching API.

 

When you create an instance of RangeCriteria you need to make sure that the arguments you provide are of the correct type - e.g. integers and not just strings. You can do that by using Dynamicweb.Input.RequestInteger("SomeQueryStringParameter") or Dynamicweb.Input.FormatInteger(someStringValue) 

 

For debugging I believe that you can call the Compile method on your SearchQuery (or criteria) and it should return the actual Lucene query as a string.

 

 
Morten Bengtson
Reply

Hi Anders,

 

I assume that you are building some kind of custom search functionality by using the Dynamicweb.Searching API.

 

When you create an instance of RangeCriteria you need to make sure that the arguments you provide are of the correct type - e.g. integers and not just strings. You can do that by using Dynamicweb.Input.RequestInteger("SomeQueryStringParameter") or Dynamicweb.Input.FormatInteger(someStringValue) 

 

For debugging I believe that you can call the Compile method on your SearchQuery (or criteria) and it should return the actual Lucene query as a string.

 

 
Anders Ebdrup
Reply

Hi Morten

 

Thank you for your answer.

 

I am building a custom search functionality with the API, and I am pretty sure that I am using the right data types :-)

I know that I can call the "Compile" method,  but I would very much like to see the total query for all "filters" for debugging and testing purpose for better being able to see if the problem is in my code or in the standard :-)

 

Best regards

 
Morten Bengtson
Reply

I mentioned the data types because the RangeCriteria takes objects as parameters and is behaves differently based on what the actual type is.

 

It is a bit unclear in what context you are working.

 
Morten Bengtson
Reply

Another approach is to implement your own logging for the index search by implementing a class that inherits from Dynamicweb.Searching.Management.Logging.LogProvider.

 

 
Anders Ebdrup
Reply

Hi Morten

 

This is a piece of my code:

        public override SearchQueryElement ComposeQuery()
        {
            if (!string.IsNullOrWhiteSpace(Request("type-danish", true)) && !string.IsNullOrWhiteSpace(Request("type-foreign", true)))
            {
                return new CriteriaGroup(new RangeCriteria("productfield_field14", (int)SubscriptionType.Danish, (int)SubscriptionType.Danish, true), CriteriaSeparator.Or, new RangeCriteria("productfield_field14", (int)SubscriptionType.Foreign, (int)SubscriptionType.Foreign, true));
            }
            else if (!string.IsNullOrWhiteSpace(Request("type-danish", true)))
            {
                return new RangeCriteria("productfield_field14", (int)SubscriptionType.Danish, (int)SubscriptionType.Danish, true);
            }
            else
            {
                return new RangeCriteria("productfield_field14", (int)SubscriptionType.Foreign, (int)SubscriptionType.Foreign, true);
            }
        }

And the compiled query looks like: "productfield_field14:[P00000000000000000001 TO P00000000000000000001]", but when querying the index I do not get any results. Only if my query looks like: "productfield_field14:[p00000000000000000001 TO p00000000000000000001]".

 

The notifier "Dynamicweb.Notifications.eCommerce.SearchFilters.AfterComposeQuery" only seems to include the current filter and not the full query.

 

Is there a standard LogProvider for the index or do I have to create my own??

 

Best regards, Anders

 

 
Morten Bengtson
Reply
This post has been marked as an answer

Yeah, sorry about that. I realized that it was only the filter query after posting my last answer.

 

After some more digging I found out that you can actually see the index queries by appending dbstat=1 to the query string :)

The debug info looks like this (depending on your query of course):

 

Search index (Query # 1)
Query text: +isactive:true +(+groupshierarchy:220 +isactive:true +languageid:lang6)

 

Votes for this answer: 1
 
Anders Ebdrup
Reply

Wow! Thanks for the tip, that will definitely make my day much easier!

 

Thank you, Morten!

 

As a bonus info the "compiled" query is not equal to the actual query after trying the dbstat trick:

 

productfield_field14:[P00000000000000000002 TO P00000000000000000002]

 

vs

 

productfield_field14:[p00000000000000000002 TO p00000000000000000002]

 
Morten Bengtson
Reply

I have no explanation for that weird casing problem, but are you sure that you should even be using the RangeCriteria for this? You are not searching for a range but a specific value. Maybe you should try using Criteria instead?

 
Anders Ebdrup
Reply

Oh, this is just an example as I have to use the RangeCriteria for the enum values :-) But you are right, it does not make must sense for my query.

 

You must be logged in to post in the forum