Amith
Amith

Reputation: 116

DSE Search And Solr - Issues with whitespace in UDT search queries

I'm trying to get my DSE search query working (with Solr). However, while constructing queries with User Defined types (UDTs), I'm running into issues with whitespace character. For eg: I have a Student table and a Name type, where the Student table has a list<frozen<Name> names. Name type has say, firstname and lastname. If I do the below query, it throws an error:

Unable to execute CQL Script : no field name specified in query and no default specified via ‘df’ param.

SELECT * from Student where solr_query= '{!tuple}names.firstname:John Smith';

So I tried escaping the whitespace as below and it works just fine.

SELECT * from Student where solr_query= '{!tuple}names.firstname:John\ Smith';

But, when I use the above UDT field with an AND operator, it FAILS again.

SELECT * from Student where solr_query= 'student_id:123456 AND {!tuple}names.firstname:John\ Smith';

Unable to execute CQL Script : org.apache.solr.search.SyntaxError: Cannot parse names.firstname … Lexical error at line 1, column … Encountered: after : “”

This is the field type for first name:

<fieldType class="org.apache.solr.schema.TextField" name="DelimitedTextField">
      <analyzer>
        <tokenizer class="solr.PatternTokenizerFactory" pattern="[,\s]"/>
        <filter class="solr.LowerCaseFilterFactory"/>
      </analyzer>
    </fieldType>

As a beginner with Solr, I've been banging my head trying to make these queries work. Any help would be deeply appreciated. Thanks!

Upvotes: 0

Views: 703

Answers (2)

Amith
Amith

Reputation: 116

I was able to get this working by doing a couple of things.

  1. I created a new org.apache.solr.schema.TextField and added
    PatternTokenizerFactory tokenizer, with comma (,) as the pattern.

  2. Trimmed the white spaces at the beginning and at the end, and replaced the whitespaces within the text with '?' which matches any single character. This was ok to do in my case.

  3. I had to add braces () to the entire query.

Hence, with the updated schema.xml file and the other changes mentioned above, I have the following query working now:

SELECT * from Student where solr_query= '(student_id:123456 AND {!tuple}names.firstname:John?Smith)';

Eventhough this would match John Smith, John-Smith, or even John.Smith, this was ok in my case since we were supposed to give back these results anyway.

Upvotes: 0

Alessandro Benedetti
Alessandro Benedetti

Reputation: 1114

I am no expert at all of the DSE system you seem to be using, but taking a look to this resource[1] it seems you may be building boolean queries in a wrong way. This seems a correct approach :

+{!tuple v='father.name.firstname:Sam'} +{!tuple v='mother.name.firstname:Anne'}

Hope it helps

[1] http://docs.datastax.com/en/datastax_enterprise/4.8/datastax_enterprise/srch/srchTupleUDTqueries.html

Upvotes: 0

Related Questions