Skip to main content
Known Participant
February 6, 2019
Answered

Generated index is NOT in alphabetical order

  • February 6, 2019
  • 4 replies
  • 5295 views

Dear community,

To my surprise InDesign generates incorrect indexes. Se example below, every line starting with the surname “Dahl” should of course be kept together and be listed before any name with the same base/syllable. In this case before “Dahlbom”!

What to do?

Similar problem:

Wrong alphabetical order in index

I couldn't get @Peter Chater Kahrels script to work in InDesign 14.0.1.

This topic has been closed for replies.
Correct answer Peter Kahrel

Solo -- InDesign's index sorting is indeed pretty awful much of the time, especially with name indexes. Please go to Adobe InDesign Feedback and tell Adobe about the problem and submit a request to improve index sorting (and tell them how).

In the meantime, your name sample can be sorted correctly by setting each topic's sort order to the topic's name with the separating comma+space replaced with any character that's naturally sorted before any letter. Digits do that, so let's use the zero:

if (app.documents[0].indexes.length == 0) exit();

topics = app.documents[0].indexes[0].allTopics;

for (i = topics.length-1; i >= 0; i--) {

  topics.sortOrder = topics.name.replace (', ', '0');

}

P.  (Thanks for the ping, BarbBinder​)

4 replies

Community Expert
November 23, 2020

Hi troyd71007371,

you could look into Marc Autret's IndexMatic script:

https://www.indiscripts.com/category/projects/IndexMatic

 

Regards,
Uwe Laubender

( ACP )

Known Participant
November 24, 2020

Thank you, I will look at IndexMatic. The good news is that I did follow the InDesign instructions to get the index formatting working well, and it looks OK so far. I will start with a non-fiction book at 200 pages, which will have perhaps a hundred items to index, but so far so good with InDesign. As the alphabeticizing problem was in 2019, I hope that's been fixed. Rather than code it as you folks are doing, which I haven't done yet, if any index entries are out of order, and it's not too many entries, I could manually edit it by by various means, (like entering a white space where something should be and placing a single text frame over the white space, while also placing another text frame over any resulting extra index entrys that are out of order , but I hope I don't have to.) 

Community Expert
March 17, 2020

Hi together,

in the meanwhile Peter's scripts moved to creativepro.com. So the updated script can be found at:

https://creativepro.com/files/kahrel/indesign/index_statistics.html

 

Regards,
Uwe Laubender

( ACP )

 

FWIW: No idea why this thread moved to the top of the list of InDesign discussions some days ago.

Seems, this all entirely took place in February 2019.

Known Participant
November 23, 2020

I signed up for InDesign as a book publisher to be able to use a decent index. Looks as if the InDesign index is buggy, and hard to refine the order.  Is there another program out there that has an index that actually works well, right now, without adding code on our own?

Peter KahrelCorrect answer
Community Expert
February 6, 2019

Solo -- InDesign's index sorting is indeed pretty awful much of the time, especially with name indexes. Please go to Adobe InDesign Feedback and tell Adobe about the problem and submit a request to improve index sorting (and tell them how).

In the meantime, your name sample can be sorted correctly by setting each topic's sort order to the topic's name with the separating comma+space replaced with any character that's naturally sorted before any letter. Digits do that, so let's use the zero:

if (app.documents[0].indexes.length == 0) exit();

topics = app.documents[0].indexes[0].allTopics;

for (i = topics.length-1; i >= 0; i--) {

  topics.sortOrder = topics.name.replace (', ', '0');

}

P.  (Thanks for the ping, BarbBinder​)

Solo46Author
Known Participant
February 8, 2019

Thanks Peter and Barb!

Will that script edit the index data for just the active file?

Should the script file be named .JS or .JSX?

Just to see if I understand correctly. Will "name.replace (', ', '0')" change the sort order field from:

Smith, John

to

Smith0John

?

And one more detail. I have already used manual sorting for several topics by adding text to sort order field. It would be elegant if the script first checked if any data is present in sort order field. And if so, edits that string. If not, takes topic filed string and adds it to sort order field with comma space replaced with zero.

It seems like InDesign ignores punctuation marks when sorting. I.e. sort order field name "Smith0John" or "Smith,0John" gave the same result. So maybe the script can be edited to "name.replace (', ', ',0')".

Is it possible to add more strings to be replaced with the same replace command? Names that have no known first name in my index are instead separated with colon and then followed by title. In other words, could colon + space also be added to the replace command?

I am a bit anxious, because the index takes 30 min to generate, it contains over 7'000 lines/topics.

Solo46Author
Known Participant
February 14, 2019

Great news Peter. Thanks. Your script is an elegant solution for working with large indexes!

I tested it on a large document and the new version seems to calculate correct.

I really appreciate your help in this subject.
And it's a bit of a mystery to me that these tools are note available as standard tools in InDesign 2019.


Well well, as usual it's more to this.

There where more special cases ahead so it's probably better to make a script that solves "all" index sorting problems. Previously I had some manual edited sortOrders (especially for W/V) that I wished to keep. Hence the previous care taken of topics already with sortOrder present, but it's much easier to accomplish it all in a script.

But I am beginner at scripting. My script draft only results in line 7 being noticeable affected in the document. And my addition to the script can probably be much more elegantly done.

Something is wrong, is topics.sortOrder is been overwritten for each line? A new variable might be needed or all regexes might be performed during a single replace call? But I don't know how it should be done.

if (app.documents[0].indexes.length == 0) exit(); 

topics = app.documents[0].indexes[0].allTopics; 

for (i = topics.length-1; i >= 0; i--) { 

  topics.sortOrder = topics.name.replace      (/(?-i)W/, 'V');  // Fix Swedish alphabetical order. Treat W as V

  topics.sortOrder = topics.sortOrder.replace (/(?-i)w/, 'v');  // Fix Swedish alphabetical order. Treat w as v

  topics.sortOrder = topics.sortOrder.replace (/['´]/, '');     // Exclude punctuation that InDesign sorts as normal characters

  topics.sortOrder = topics.sortOrder.replace (/[,:]\s*/, '0'); // Fix alphabetical order for names, in format "Smith, John"

And this reported as error 21: undefined is not an object.

if (app.documents[0].indexes.length == 0) exit(); 

topics = app.documents[0].indexes[0].allTopics; 

var myIndex;

for (i = topics.length-1; i >= 0; i--) { 

  myIndex = topics.name;

 

  myIndex.replace (/(?-i)W/, 'V');  // Fix Swedish alphabetical order. Treat W as V

  myIndex.replace (/(?-i)w/, 'v');  // Fix Swedish alphabetical order. Treat w as v

  myIndex.replace (/['\´]/, '');    // Exclude punctuation that InDesign sorts as normal characters

  myIndex.replace (/[,:]\s*/, '0'); // Fix alphabetical order for names, in format "Smith, John"

 

  topics.sortOrder = myIndex;

}

Barb Binder
Community Expert
February 6, 2019

Hi Solo46,

Yes, and I remember another (different) post on this within the last few months with the same issue. Since Peter Kahrel has a script that addresses this, let's see if we can get him to swing by to help. 

~Barb

~Barb at Rocky Mountain Training