How to define CustomAnalyzer through C# code when creating Azure Search Index - azure-cognitive-search

I saw the note from here: https://learn.microsoft.com/en-us/rest/api/searchservice/custom-analyzers-in-azure-search
that: Custom analyzers that you create are not exposed in the Azure portal. The only way to add a custom analyzer is through code that makes calls to the API when defining an index.
Currently I am using the following C# code to create the Azure search index:
var definition = new Microsoft.Azure.Search.Models.Index()
{
Name = "test-index",
Fields = new List<Field>
{
new Field("field1", Microsoft.Azure.Search.Models.DataType.String) { IsKey = false, IsSearchable = false, IsFilterable = false, IsSortable = false, IsFacetable = false, IsRetrievable = true }
}
}
searchClient.Indexes.CreateOrUpdate(myIndex);
Is there a way that I can add some code in here such as:
var analyzer = new CustomAnalyzer();
analyzer.Tokenizer = TokenizerName.Keyword;
analyzer.TokenFilters.Add(TokenFilterName.Lowercase);
and then add this custom analyzer in my code above somewhere to let "field1" use my defined analyzer?

Yes, you can add custom analyzers through the SDK, here are some examples:
https://github.com/Azure/azure-sdk-for-net/blob/master/sdk/search/Microsoft.Azure.Search/tests/Tests/CustomAnalyzerTests.cs

Related

Mui-datatables custom search

how do I add a custom search in mui-datatables which can be used for data fetched from API. can u please provide me a working example? I tried using
customSearch: (searchQuery, currentRow, columns) => {
let isFound = false;
currentRow.forEach(col => {
if (col.toString().indexOf(searchQuery) >= 0) {
isFound = true;
}
});
return isFound;
},
in options.
note: in console, I got react_devtools_backend.js:6 Server-side filtering is enabled, hence custom search will be ignored.
You're probably looking for something like this:
https://github.com/gregnb/mui-datatables/blob/master/examples/serverside-filters/index.js
Or this (debounceSearchRender plugin):
https://github.com/gregnb/mui-datatables/blob/master/examples/large-data-set/index.js
Your backend is going to return the results, so your custom search needs to be defined in the server.

Filter multiple lists using Fuse js at the same time

I have 3 lists generated via API. I want to filter these lists at the same time using Fuse js. I checked the documentation and could not find the solution for filtering multiple lists.
I don't know how to pass 3 different lists as a parameter to the Fuse method.
this.state = {
a: [],
b: [],
c: [],
}
filterVal = (e) =>{
let searchOptions = {
keys:['name'], //name is common key across all 3 lists
includeMatches: true
}
var fuse = new Fuse(a,b,c, searchOptions); //not sure how pass 3 lists here
var filteredResult = fuse.search(e.target.value); //passed the user input value
}
You can merge list like:
var fuse = new Fuse([...a, ...b, ...c] , searchOptions)

Visual Relations using Winium automating a WPF app

Using other automation tools for Windows Apps, such as LeanFT, there is a way to specify a visual relation. For example, if I identified a label, I could then say look for the text box to the right of it.
Is there a way to do this in Winium?
Here is a sample of what the code looks like in LeanFT
var projectButton = baseOR.PlatformWindow.ProjectList.BrowseProjects.Describe<IButton>(new ButtonDescription
{
FullType = "button",
Text = node,
Index = 0
});
return baseOR.PlatformWindow.ProjectList.BrowseProjects.Describe<IButton>(new ButtonDescription
{
FullType = "button",
Vri =
{
new VisualRelation
{
TestObject = projectButton,
HorizontalRelation = HorizontalVisualRelation.LeftAndInline,
}
}
});
As you can see, we are essentially identifying one element, and then using that as the TestObject in the VisualRelation to identify something else.

Angularize SharePoint Client Side Taxonomy Picker

The Patterns and Practices team has released a client side taxonomy picker for use when integrating with SharePoint. It works well, but uses jQuery and my SharePoint App is built in Angular... which seems to be a growing trend. I would like to leverage the client side taxonomy picker in Angular and was unsure of how best to achieve this. Here is a link to the component: https://github.com/OfficeDev/PnP/tree/dev/Components/Core.TaxonomyPicker
I am thinking it would be a directive, or is there a non-directive manner to replace (aka, how does Angular manage a replace/initialization) as they are doing here:
HTML:
<input type="hidden" id="taxPickerGeography" />
jQuery Function that gets the Current Context and creates the Taxonomy Picker
$(document).ready(function () {
var context;
context = SP.ClientContext.get_current();
$('#taxPickerGeography').taxpicker({
isMulti: false,
allowFillIn: false,
termSetId: '89206cf2-bfe9-4613-9575-2ff5444d1999'
}, context);
});
I don't need the script loading components as illustrated in the example provided by the PnP team, as I have these already embedded in my App.
Given the challenges of making a "responsive" Managed Metadata field, I built the following using the JavaScript Object Model to retrieve terms and then push them for use in an Array. This includes retrieving Synonyms.
// Query Term Store and get terms for use in Managed Metadata picker stored in an array named "termsArray".
var termsArray = [];
function execOperation() {
// Current Context
var context = SP.ClientContext.get_current();
// Current Taxonomy Session
var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(context);
// Term Stores
var termStores = taxSession.get_termStores();
// Name of the Term Store from which to get the Terms. Note, that if you receive the following error "Specified argument was out of the range of valid values. Parameter name: index", you may need to check the term store name under Term Store Management to ensure it was not changed by Microsoft
var termStore = termStores.getByName("TermStoreName");
// GUID of Term Set from which to get the Terms
var termSet = termStore.getTermSet("TermSetGUIDHere");
var terms = termSet.getAllTerms();
context.load(terms);
context.executeQueryAsync(function () {
var termEnumerator = terms.getEnumerator();
while (termEnumerator.moveNext()) {
var currentTerm = termEnumerator.get_current();
var guid = currentTerm.get_id();
var guidString = guid.toString();
var termLabel = currentTerm.get_name();
// Get labels (synonyms) for each term and push values to array
getLabels(guid, guidString, termLabel);
}
// Set $scope to terms array
$scope.$apply(function () {
$scope.termsArray = termsArray;
});
}, function (sender, args) {
console.log(args.get_message());
});
// Get labels (synonyms) for each term and push values to array
function getLabels(termguid, guidString, termLabel) {
var clientContext = SP.ClientContext.get_current();
var taxSession = SP.Taxonomy.TaxonomySession.getTaxonomySession(clientContext);
var termStores = taxSession.get_termStores();
// The name of the term store. Note, that if you receive the following error "Specified argument was out of the range of valid values. Parameter name: index", you may need to check the term store name under Term Store Management to ensure it was not changed by Microsoft
var termStore = termStores.getByName("TermStoreName");
// GUID of Term Set from which to get the Terms
var termSet = termStore.getTermSet("TermSetGUIDHere");
var term = termSet.getTerm(termguid);
var labelColl = term.getAllLabels(1033);
clientContext.load(labelColl);
clientContext.executeQueryAsync(function () {
var labelEnumerator = labelColl.getEnumerator();
var synonyms = "";
while (labelEnumerator.moveNext()) {
var label = labelEnumerator.get_current();
var value = label.get_value();
synonyms += value + " | ";
}
termsArray.push({
termName: termLabel,
termGUID: guidString,
termSynonyms: synonyms
});
}, function (sender, args) {
console.log(args.get_message());
});
}
};
// Execute function
execOperation();

How to define a Backbone.Collection to be a property but not an attribute of a Backbone.Model?

Say I have a web application which allows to filter a set of items and say that I'm using backbone.js in the web frontend.
Quite naturally I ended up creating a Filter which extends Backbone.Model and a SearchResultList extending Backbone.Collection. The Filter has some attributes like searchTerm, dataFrom, dateTo... Filter also has a method called applyFilter. Filter.applyFilter should call searchResultList.fetch, thus updating/filtering the search results.
The question is, how to best initialize searchResultList as a property of Filter instead of being an attribute in Backbone terms?
I would not like to create the SearchResultList in Filter.initialize as SearchResultList is not necessarily "owned" by Filter.
For now I ended up passing the searchResultList object as an option to Filter.initialize, but that feels a little bit awkward to me.
I doubt that it is a good idea to let Filter.applyFilter call SearchResultList.fetch. However, there needs to be a method of Filter which when called triggers a new request somehow. (Listening to change events of Filter is not an option either as the user is supposed to change filter options in multiple steps and decides to apply the filter manually via a button click)
I have a Collection for performing searches. Most of my collections extend this Search Collection.
It has an object in it holding parameters for searching. The user of the collection can call setSearchParam, and I have a method buildSearchString that will build the search part of the URL to call (I use the Matrix parameters in my REST urls).
window.SearchCollection = Backbone.Collection.extend({
initialize : function() {
this.params = {}; // holds parameters for searching
},
// Set a search param
setSearchParam: function(param, value) {
if (typeof value === 'undefined') return;
if (typeof this.params === 'undefined') this.params = {};
this.params[param] = value;
},
setSearchParams : function(paramMap) {
_.extend(this.params, paramMap);
},
// Build Matrix params for search. This could just as easily be a standard URL string
buildSearchString: function() {
var search = [];
var i = 0;
for (var key in this.params) {
var value = this.params[key];
if (utils.isEmpty(value)) continue;
search[i++] = ";";
search[i++] = key;
search[i++] = "=";
search[i++] = value;
}
return search.join('');
}
});
Then when I create a collection, I extend it:
window.BookingCollection = window.SearchCollection.extend({
model: Booking,
url: function(){
var urlString = BASE_REST_URL + "bookings/";
// Build the matrix params for the REST URL
urlString += this.buildSearchString();
return urlString;
}
});
Then, a user of this collection can use it like so:
var bookings = new BookingCollection();
bookings.setSearchParam("name", "hello");

Resources