Azure / azure-sdk-for-js

This repository is for active development of the Azure SDK for JavaScript (NodeJS & Browser). For consumers of the SDK we recommend visiting our public developer docs at https://docs.microsoft.com/javascript/azure/ or our versioned developer docs at https://azure.github.io/azure-sdk-for-js.
MIT License
2.08k stars 1.2k forks source link

Create Index does not preserve the "analyzer" property. #15465

Closed scott-alvis closed 3 years ago

scott-alvis commented 3 years ago

Describe the bug I altered the example below adding analyzer: "en.microsoft" to the description field of the index object. When I viewed the index in the portal the analyzer was not set on description field.

Example Code https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/search/search-documents/samples/javascript/src/indexes/createIndex.js

To Reproduce Steps to reproduce the behavior:

  1. Add the analyzer: "en.microsoft" the the example code above. Either review the results of the api call or view the index in the portal.

Expected behavior Analyzer property should be set.

Screenshots

Changes to the example code:

Screen Shot 2021-05-28 at 3 09 31 PM

Index being sent to the api:

Screen Shot 2021-05-28 at 2 22 00 PM

Results from the api call (analyzer is set to null):

Screen Shot 2021-05-28 at 2 22 43 PM

Additional context I've also used the same index and posted it via postman and analyzer is properly set.

After some additional debugging I believe the function below is the culprit.

function convertFieldsToGenerated(fields) {
    return fields.map((field) => {
        var _a, _b, _c, _d;
        if (isComplexField(field)) {
            return field;
        }
        else {
            const { hidden } = field, restField = tslib.__rest(field, ["hidden"]);
            const retrievable = typeof hidden === "boolean" ? !hidden : hidden;
            return Object.assign(Object.assign({}, restField), { retrievable, 
                // modify API defaults to use less storage for simple types
                searchable: (_a = field.searchable) !== null && _a !== void 0 ? _a : false, filterable: (_b = field.filterable) !== null && _b !== void 0 ? _b : false, facetable: (_c = field.facetable) !== null && _c !== void 0 ? _c : false, sortable: (_d = field.sortable) !== null && _d !== void 0 ? _d : false, analyzer: field.analyzerName, searchAnalyzer: field.searchAnalyzerName, indexAnalyzer: field.indexAnalyzerName, synonymMaps: field.synonymMapNames });
        }
    });
}
analyzer: field.analyzerName

The field object does not have an 'analyzerName' property.

I believe the code should be:

analyzer: field.analyzer
Screen Shot 2021-05-28 at 3 01 07 PM

Additional Notes If you change the property name to analyzerName: "en.microsoft" it works as expected but every where in the documentation the field is called analyzer.

The analyzer property works as expected on properties inside a Collection(Edm.ComplexType).

sarangan12 commented 3 years ago

Thanks @scott-alvis. I will check and update the code for the July release. The code merge should be completed this week.

sarangan12 commented 3 years ago

@scott-alvis I have checked your code and suggestion. Here is what I have found:

  1. You are trying to call createIndex method of the SearchIndexClient class. The method call could be found here.
  2. Now, this operation gets the SearchIndex object as the parameter. This object is defined here.
  3. This SearchIndex object has the fields property of type SearchField array. This SearchField object is defined here
  4. This SearchField object has SimpleField object which is defined here as:
    export interface SimpleField {
    name: string;
    type: SearchFieldDataType;
    key?: boolean;
    hidden?: boolean;
    searchable?: boolean;
    filterable?: boolean;
    sortable?: boolean;
    facetable?: boolean;
    analyzerName?: LexicalAnalyzerName;
    ...........
    ...........

As you can see, the SimpleField has the property analyzerName and not analyzer. So, In your example (mentioned in the issue description), you should have set the property as analyzerName and it would have worked correctly.

Please let me know if you still face any more issues. Thanks

scott-alvis commented 3 years ago

Then may I suggested updating the quick start below as it suggests using an index-definition.json file which uses analyzer which is not preserved when the index is created.

https://docs.microsoft.com/en-us/azure/search/search-get-started-javascript

sarangan12 commented 3 years ago

@scott-alvis Thanks for pointing this documentation. I am working with the docs team and will fix the documentation soon

sarangan12 commented 3 years ago

I am still coordinating with Derek to update the docs. Otherwise, no work is pending on this issue. I will track the docs upgrade and close this issue. Until closing, I am moving this issue to August release.

sarangan12 commented 3 years ago

The documentation has been updated. Closing this issue