1
votes

I'm trying to get Solr to sort by Title, but I'm having no luck.

In my Schema I have the "title" field as text_general for searching, and then a "title_sort" field as a string for sorting. I've created a copyField that should be taking the "title" text_general field and putting it into the "title_sort" field as a string.

<fields>
  <field name="title" type="text_general" indexed="true" stored="true"/>
  <field name="title_sort" type="string" indexed="true" stored="false" />    
</fields>

<copyField source="title" dest="title_sort" />

When I run the sort query "title_sort desc" this is what I get back

title: Don’t Mind If I Do
title: Men Don't Run Marathons
title: Danny

Can a copyField not convert a text_general field into a string?

1
Can you please share your query that you are using for sort.. - Sanjay Dutt
I'm a bit new to Solr, so let me know if this is what you're looking asking. When I query through the Solr admin panel, this is the URL string: localhost:8080/solr/collection1/select?q=*%3A*&sort=title_sort+desc&wt=json&indent=true - Nick Finney
Have you reindexed after adding the copyField instruction? (Solr will not go through all documents and update secondary fields) Set the title_sort field as stored and verify that you're getting the correct information there as well. Any copyField instruction happens before any fields are processed, so the type of the field doesn't affect the copyField instruction. - MatsLindh
Thanks @MatsLindh that was exactly it. I'd been reloading the schema in the CoreAdmin panel, thinking that would make the changes. After deleting all the data, restarting solr and re-importing the data, it worked perfectly. Thanks dude! - Nick Finney

1 Answers

0
votes

Solved with the help of @MatsLindh.

I'd been reloading the schema in the CoreAdmin panel, thinking that would make the changes. I had to reindex after adding the copyField instruction, as Solr will not go through all the documents and update secondary fields.