Open riasvdv opened 5 years ago
I just started making indices for this!
Can i do this now or dot you have to do some code changes?
Just saw the other issue in this repo..
Should all be possible, just not documented everything yet!
Doesn't seem to work. if i use ->site('*')
it still only indexes the default site.
But saw a new issue came in now: #98
Yeah, it will be fixed when #99 is merged, a little oversight I had when rewriting
How would this work? If I have an entry that is enabled for two sites, it only pushes one record to Algolia. I even tried passing in a unique objectID
$indices[] = ScoutIndex::create(CRAFT_ENVIRONMENT . '_Search')
->elementType(Entry::class)
->criteria(function (EntryQuery $query) {
return $query->section([
'news',
'pressReleases',
'pages',
'resources',
'events',
])
->siteId([
Craft::$app->sites->getSiteByHandle('en')->id,
Craft::$app->sites->getSiteByHandle('es')->id,
]);
})
->transformer(function (Entry $entry) {
return [
'objectID' => implode('_', [
$entry->id,
$entry->site->handle,
]),
'title' => $entry->title,
'url' => $entry->url,
];
});
@davist11 can you test with this branch? Should be fixed.
"rias/craft-scout": "dev-97-multisite-single-index as 2.3.2",
You've got the right idea with including your site in you objectID. The issue stems from when before Craft allowed for querying multiple sites in a single query.
Unrelated: you could just pass site(['en', 'es'])
in yoru query, instead of getting the ids yourself.
Hmm, is that branch name correct?
[UnexpectedValueException]
Could not parse version constraint 97-multisite-single-index as 2.3.2: Invalid version string "97-multisite-single-
index" in "97-multisite-single-index as 2.3.2", the alias source must be an exact version, if it is a branch name y
ou should prefix it with dev-
Unrelated: you could just pass site(['en', 'es']) in yoru query, instead of getting the ids yourself.
Niiiice thanks
whoops - use dev-97-multisite-single-index
Hmm, I'm still not seeing the spanish version getting created in Algolia. Dunno if the new distinct stuff I've added would have impacted that at all. Here's my index
$indices[] = ScoutIndex::create(CRAFT_ENVIRONMENT . '_Search')
->elementType(Entry::class)
->criteria(function (EntryQuery $query) {
return $query->section([
'news',
'pressReleases',
'pages',
'resources',
'events',
])
->site([
'en',
'es'
]);
})
->transformer(function (Entry $entry) {
return [
'objectID' => implode('_', [
$entry->id,
$entry->site->handle,
]),
'title' => $entry->title,
'url' => $entry->url,
'summary' => self::_formatSummary($entry),
'postDate' => self::_formatDate($entry->postDate),
'expirationDate' => self::_formatDate($entry->expiryDate),
'dateUpdated' => self::_formatDate($entry->dateUpdated),
'type' => self::_formatType($entry),
'eyebrow' => self::_formatEyebrow($entry->section->name),
'content' => self::_formatPageBlocks($entry->pageBlocks),
];
})
->splitElementsOn([
'content',
])
->indexSettings(IndexSettings::create()
->hitsPerPage(10)
->attributeForDistinct('distinctID')
->distinct(true)
->attributesForFaceting([
'type',
'distinctID',
])
->replicas([
CRAFT_ENVIRONMENT . '_Search_dateAsc',
CRAFT_ENVIRONMENT . '_Search_dateDesc',
])
);
@davist11 weird…I'm using your $indices and it's working for me…
As a sanity check, can you go to your plugins page and make sure it looks like:
Dunno if the new distinct stuff I've added would have impacted that at all
Hmm could be…what are you trying to do there? As it is, your transformer doesn't define a distinctID
, so references to it aren't going to work. In fact they're probably just seeing it always as null
and not indexing. Since all elements will have unique objectIDs, you shouldn't need any of the distinct stuff, if you're just want a 1-1 match of entry to algolia object.
As a sanity check, can you go to your plugins page and make sure it looks like
Confirmed
As it is, your transformer doesn't define a distinctID
That value automatically gets added (per the Scout documentation and what I'm seeing in Algolia records). I tried removing the distinct stuff and still not seeing the spanish version.
Is every entry (from each site) being passed separately to the transformer?
Is every entry (from each site) being passed separately to the transformer?
Yes - everything from the criteria gets passed to the transformer, so unless you have a unique parm on your criteria, you'll get back the elements from each site.
That value automatically gets added (per the Scout documentation and what I'm seeing in Algolia records).
derp – right you are.
If it's possible to share your composer files and db, that'd be helpful. Or even sync to a project.yaml file…
If that's an option, send em to tim@timkelty.com.
Sent, thanks!
What is the status for this issue?
Is this available in the main branch?
->site('*')
in criteriaobjectID
from transformer