Giter Club home page Giter Club logo

Comments (8)

Shazwazza avatar Shazwazza commented on July 29, 2024 1

I've never tried that before but the problems will be:

  • Deleting a document is by __NodeId so it will delete them all
  • Querying on __NodeId I suspect is expecting a single result but you will get more than one, not sure what will happen

It kind of goes against the contract of what Examine expects so I'm not really sure the consequences.

from examine.

Shazwazza avatar Shazwazza commented on July 29, 2024

Everything is based on valueSet.Id to add or update the document behind the scenes. What is the Id you are passing here? And if it is the same Id, and a new document is being added that would seem pretty strange. There's tests in the codebase here to testing updating docs which work, so does seem odd.

from examine.

jemayn avatar jemayn commented on July 29, 2024

Hmm on further testing it seems to be unrelated to v4. I get the same problem with v3.1.0.

I will try to reproduce on a fresh site and link the repo.

image

from examine.

jemayn avatar jemayn commented on July 29, 2024

I've set up a repo where I can reproduce the issue running Examine 3.1.0: https://github.com/jemayn/examine-duplicates

Steps:

  1. Build the product index, should have 4 documents:
    image
  2. Add a "new" product with a matching id to one of the existing ones but a new name by calling the test api controller at https://localhost:44358/umbraco/api/test/updatevalues
  3. Check the index, it now has 5 documents - two of them with id 1:
    image

from examine.

Shazwazza avatar Shazwazza commented on July 29, 2024

Are you using "__NodeId" as the key?

from examine.

jemayn avatar jemayn commented on July 29, 2024

I am calling it like this:

private readonly IExamineManager _examineManager;
private readonly ProductIndexValueSetBuilder _productIndexValueSetBuilder;

public TestController(IExamineManager examineManager, ProductIndexValueSetBuilder productIndexValueSetBuilder)
{
    _examineManager = examineManager;
    _productIndexValueSetBuilder = productIndexValueSetBuilder;
}

public void UpdateValues()
{
    if (!_examineManager.TryGetIndex(IndexingConstants.IndexName, out var index))
    {
        return;
    }

    var product = new Product
    {
        Id = 1,
        Name = "Name with update 1"
    };
    
    index.IndexItems(_productIndexValueSetBuilder.GetValueSets(product));
}

And the valueset builder looks like this:

public class ProductIndexValueSetBuilder : IValueSetBuilder<Product>
{
    public IEnumerable<ValueSet> GetValueSets(params Product[] products)
    {
        foreach (var product in products)
        {
            var indexValues = new Dictionary<string, object>
            {
                [UmbracoExamineFieldNames.NodeNameFieldName] = product.Name,
                ["id"] = product.Id
            };

            yield return new ValueSet(
                product.Id.ToString(),
                IndexingConstants.IndexType,
                IndexingConstants.IndexType,
                indexValues);
        }
    }
}

So I am setting the string Id param in the ValueSet constructor to product.Id.ToString() which seems to set it in the __NodeId field. I also tried adding it as a specific field, but then it gets added twice like this:
image

from examine.

Shazwazza avatar Shazwazza commented on July 29, 2024

I think its because you are overriding the field type of the key __NodeId here

https://github.com/jemayn/examine-duplicates/blob/baee007649996924b8451155c9929750712457de/Indexing/ProductIndexOptions.cs#L33

from examine.

jemayn avatar jemayn commented on July 29, 2024

Ohhh hadn't considered that not all fields need to be explicitly set.
I tried removing that line and now it works as expected! Thanks!

On a similar note, is it problematic in any way to have multiple index documents with the same id?

Say fx you had products and they had multiple language versions, would there be any benefits to doing it like this:

__NodeId: 1
nodeName: Product 1
description_da-dk: Description in Danish
description_en-gb: Description in English

Versus this:

__NodeId: 1
nodeName: Product 1
culture: da-dk
description: Description in Danish

__NodeId: 1
nodeName: Product 1
culture: en-gb
description: Description in English

from examine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.