You can probably get the number of page references as follows:
>I would like to treat egg at page 1, then chicken at page 2, and egg at page 3.
That's more like a table of contents than an index.
Thant you for answering.
Yes, I know I can do that, but that's not what I am looking for.
I need something who would take myStory and returns all the topics who were found (and who have a page reference).
No, no, it's an index!
(My english is maybe bad, I'm sorry, I'm french and I'm not very good in english...)
Aha -- you want to find topics/page references for a story? That's a bit more complicatedbecause topics are children of the index, and the index is a child of the document. So there's no direct link between topics/page references and stories. So what you would need to do is to get all page references, get each one's parent story (using sourceText), compare it with your story, and if the two stories are the same, put the page reference's parent topic somewhere, e.g. in an array.
Given a reference story MyStory, this script
// Collect all page references
PRefs = app.documents.indexes.topics.everyItem().pageReferences.everyItem().getElements();
StoryTopics = ;
for (i = 0; i < PRefs.length; i++)
// PRefs[i].sourceText is an InsertionPoint
if (PRefs[i].sourceText.parentStory == MyStory)
places all topics that occur in myStory in the array StoryTopics. You could represent your topics/stories in several different ways, your choice depends on what you want to do with your data.
Thank you for your answer.
It was exactly what I was looking for!