Accents in Criteria Spring Data MongoDB (1.10.9) - spring-data-mongodb

How can I get it insensitive to accents:
List<Criteria> andCriteria = new ArrayList<>();
if (StringUtils.isNoneBlank(dtoFilter.getNombre())) {
andCriteria.add(Criteria.where("nombre").regex(dtoFilter.getNombre(), "i"));
}
For example, if I search for Oscar, that I look for both Óscar and Oscar

Related

DotNet Core Azure Search SDK - filtering results

We are trying to implement Filter functionality into Azure (Cognitive) Search. I was hoping to find some nice SDK methods that hide all the ugly parts, but so far the only example I found looks like this (source):
SearchParameters parameters = new SearchParameters()
{
Filter = String.Format("groupIds/any(p:search.in(p, '{0}'))", string.Join(",", groups.Select(g => g.ToString()))),
Select = new[] { "application essays" }
};
I was wondering, whether I am missing some docs. Or maybe it is on the roadmap?
Check out our new Azure.Search.Documents SDK we released last month. It does have OData filter helps as you can find here:
int stars = 4;
SearchOptions options = new SearchOptions
{
// Filter to only Rating greater than or equal our preference
Filter = SearchFilter.Create($"Rating ge {stars}"),
Size = 5, // Take only 5 results
OrderBy = { "Rating desc" } // Sort by Rating from high to low
};
It'll escape string parameters correctly. The OData $filter syntax still requires raw input, but the type helpers in the formattable string should make your situation easier: you don't have to worry about escaping values yourself.

Azure Search - basic search in Czech language

I have an index created in Azure Search service where I have several string fields marked as searchable using Czech - Lucene analyzer. In Czech language we use some accented characters and it is common that people replace accented characters with non-accented when typing. Therefore, for example "Václav" (name) has the same meaning as "Vaclav". In my index, I have few documents with word "Václav" and none with word "Vaclav".
As much as I'd expect that Azure Search would return all documents containing word "Václav" when I search for "Vaclav", it is not the case. I'm wondering if I have to parse the query somehow before sending to the search engine.
I ran my tests both thru Azure Portal (setting API version to 2015-02-28-Preview) and thru my code using the very latest SDK Microsoft.Azure.Search 1.1.1.
By default Lucene and Microsoft analyzers for the Czech language don't ignore diacritics. The easiest way to achieve what you want is to use standardasciifolding.lucene analyzer instead. Alternatively, you could build a custom analyzer to add the ASCII folding token filter to the standard analysis chain for Czech. For example:
{
"name":"example",
"fields":[
{
"name":"id",
"type":"Edm.String",
"key":true
},
{
"name":"text",
"type":"Edm.String",
"searchable":true,
"retrievable":true,
"analyzer":"my_czech_analyzer"
}
],
"analyzers":[
{
"name":"my_czech_analyzer",
"#odata.type":"#Microsoft.Azure.Search.CustomAnalyzer",
"tokenizer":"standard",
"tokenFilters":[
"lowercase",
"czech_stop_filter",
"czech_stemmer",
"asciifolding"
]
}
],
"tokenFilters":[
{
"name":"czech_stop_filter",
"#odata.type":"#Microsoft.Azure.Search.StopTokenFilter",
"stopwords_list":"_czech_"
},
{
"name":"czech_stemmer",
"#odata.type":"#Microsoft.Azure.Search.StemmerTokenFilter",
"language":"czech"
}
]
}
We realize that the experience is not optimal now. We’re working to make customizations like this easier.
Let me know if this answers your question

Spring Data MongoDB - Criteria API OrOperator is not working properly

I'm facing Spring Data MongoDB Criteria API orOperator problem.
Here's query result for irregular verbs: (Terminal output)
> db.verb.find({'v2':'wrote'});
{ "_id" : ObjectId("5161a8adba8c6390849da453"), "v1" : "write", "v2" : "wrote", "v3" : "written" }
And I query verbs by their v1 or v2 values using Spring Data MongoDB Criteria API:
Criteria criteriaV1 = Criteria.where("v1").is(verb);
Criteria criteriaV2 = Criteria.where("v2").is(verb);
Query query = new Query(criteriaV1.orOperator(criteriaV2));
List<Verb> verbList = mongoTemplate.find(query, Verb.class)
But unfortunately verbList doesn't have any item.
As far as I remember in order to use orOperator you should do:
Query query = new Query(new Criteria().orOperator(criteriaV1,criteriaV2));
We need explicitly specify a new criteria with OR condition - try with below example
Criteria criteria = Criteria.where("field1").is(val1).
.andOperator(new Criteria().orOperator(Criteria.where("field2").is(filterVal),
Criteria.where("field3").is(filterVal)));

Solrnet equivalent for frange in a facet query for Distance

I have implemented Spatial Search and need to generate facets for ranges or 'buckets' of distance in Solr: the following link helped me here - http://wiki.apache.org/solr/SpatialSearch#How_to_facet_by_distance
I found the solution to the following question
Faceting on distance in solr- how to generate links that search withing a given range of distance helpful.
I am using Solrnet to generate Solr queries from my .NET based site. I cant find a link that would help me to generate a frange part (italicized) of the query as below. Please help in pointing me to the code to generate this using solrnet.
&q=:&sfield=store&pt=45.15,-93.85**&facet.query={!frange l=0 u=5}geodist()&facet.query={!frange l=5.001 u=3000}geodist()**.
I am assuming that you are already using ExtraParams to set the sField & pt parameters. You should be able to add the facet.query parameters to this as well.
var results = solr.Query(SolrQuery.All, new QueryOptions
{
ExtraParams = new Dictionary<string, string> {
{ "sfield", "store" } ,
{ "pt", "45.15,-93.85" }
{ "facet.query", "{!frange l=0 u=5}geodist()" } ,
{ "facet.query", "{!frange l=5.001 u=3000}geodist()" } ,
}
});
return results;
Additionally, you might be able to use SolrFacetQuery combined with LocalParams to build the facet queries. Check the following links for some examples:
https://code.google.com/p/solrnet/wiki/Facets
How to add Spatial Solr to a Solrnet query
Update:
As stated in the comments, the use of the ExtraParams does not work because it is a dictionary object and as a result does not allow for multiple facet.query parameters. However, I was able to use the Facet Queries as described in the SolrNet Facet Wiki page linked above to create the following:
var facet1 = new SolrFacetQuery(new SolrQuery("{!frange l=0 u=5}geodist()}"));
var facet2 = new SolrFacetQuery(new SolrQuery("{!frange l=5.001 u=3000}geodist()}"));
var results = solr.Query(SolrQuery.All, new QueryOptions
{
ExtraParams = new Dictionary<string, string>
{
{"sfield", "store"},
{"pt", "45.15,-93.85"}
},
Facet = new FacetParameters
{
Queries = new[]
{
facet1, facet2
}
}
});
return results;

Solr and facet search

Does facet searching come built in when you setup your schema or do you have to do some things to set this up?
Does it basically work out of the box on all the fields that you have setup to be sortable?
then you just use the fq query syntax and it will return the facet xml along with the search results?
Is there a nice article on this that helped you first time around?
Yes, you can facet any indexed field out of the box. However it might not give you the results you expect until you configure faceting fields according to your data types.
Faceting is enabled and used through the facet.* parameters, not fq. fq is used when the user selects a facet value.
Some good Solr tutorials:
http://lucene.apache.org/solr/tutorial.html
http://www.lucidimagination.com/Community/Hear-from-the-Experts/Podcasts-and-Videos/Solr-Tutorial
Yes, Simply add &facet=true&facet.field={fieldname} to your request Url.
Here is another tutorial:Faceting
The below code in C#, by using SolrNet package.
The Facet you can do it on the fields stored in SOLR, make sure its string and doesn't have space for better results. The mincount is for limiting the minimum number to get listed in facet.
QueryOptions options = new QueryOptions
{
Facet = new FacetParameters
{
Queries = new ISolrFacetQuery[]
{
new SolrFacetFieldQuery("field1"),
new SolrFacetFieldQuery("field2")
},
MinCount = 20
}
};
And the below code to get the results, query - is the search entered in front end.
var result = solr.Query(query, options);
Faceting from Apache solr reference guide.
SolrNet package from Nuget Packages in C# provides a simple way of achieving this. The documentation helps. Here's an example,
public async Task SolrFaceting()
{
Console.WriteLine("facets");
var facetQuery = await _solr.QueryAsync(SolrQuery.All, new QueryOptions
{
Rows = 0,
Facet = new FacetParameters
{
Queries = new[]
{
new SolrFacetFieldQuery("FieldName1"),
new SolrFacetFieldQuery("FieldName2"),
new SolrFacetFieldQuery("FieldName3"),
new SolrFacetFieldQuery("FieldName4"),
},
Limit = 10
}
});
foreach (var facet in facetQuery.FacetFields["FieldName1"]) {
Console.WriteLine("{0}: {1}", facet.Key, facet.Value);
}
foreach (var facet in facetQuery.FacetFields["FieldName2"]) {
Console.WriteLine("{0}: {1}", facet.Key, facet.Value);
}
foreach (var facet in facetQuery.FacetFields["FieldName3"]) {
Console.WriteLine("{0}: {1}", facet.Key, facet.Value);
}
foreach (var facet in facetQuery.FacetFields["FieldName4"]) {
Console.WriteLine("{0}: {1}", facet.Key, facet.Value);
}
}

Resources