Examine: Removing escaped characters and wildcards
I've been attempting to create a examine ICriteria that uses path, however no matter what I try I cant get it to keep either wildcards or escaped '-'
string path = "-1,1012,1020*";
I have added trailing wildcards to the index, still doesnt work.
I've manually forced the Lucene syntax it doesnt work, Hell I've made the search even look for the nodeTypeAlias and wont return results.
I'm trying to have the search look at articles, under a certain section, with a certain set of tags, I have resolved the tags as a field in the index but it wont accept anything I send to it.
Its not the comma's thats an issue, its the "-" and the "*"
Escaping the minus due to it meaning Not in lucene means adding a backslash, but backslash hyphen isnt a C# escape configuration so the escape the backslash for lucene you need another backslash but then when the raw query is put into the ICriteria the escaping backslash for the hyphen is still there.
Alternatively using String builder I was able to leave just 1 backslash to escape the hyphen but then when it was put into the ICriteria it would strip both the hyphen and the asterisk wild card.
I found that theres no way for a raw query to take those needed characters so I've had to run 4 seperate index searches.
I may be completely misunderstanding, but with the path seperated only by spaces in a SearchablePath field, then it's just a question of searching the index with the SearchablePath field containing the id of the section you want to limit to...
So if you want to limit your search to the section with id 1012
then it is enough that the SearchablePath field contains 1012, the spaces enable you to find the id anywhere in the path string, without having to do anything clever with wildcards!
eg
var searchTerm = "fish";
var sectionId = 1012;
var searcher = ExamineManager.Instance.SearchProviderCollection["myIndexSearcher"];
var criteria = searcher.CreateSearchCriteria();
Examine.SearchCriteria.IBooleanOperation filter = null;
filter = criteria.GroupedOr(new string[] { "nodeName", "bodyText", "title" }, searchTerm);
// filter by section
filter.And().Field("searchablePath", sectionId);
var results = searcher.Search(filter.Compile());
but as I say, may be misunderstanding what your after.
Hi marc, The issue has absolutely nothing to do with the commas.
As I previously stated Its not the comma's thats an issue, its the "-" and the "*" characters that are being removed as my initial message outlined.
There is no reason to add an additional index for an already existing field wen the only requirement is that 2 additional characters are being stripped by lucene even when following proper syntax of escaping and wildcards.
Hey guys, So the reason I need to have the full path string is because I'm not querying their direct parent, rather root node with a section where the content types sit, almost all of them dont have a direct parent for me to query without triplicating the resolves.
Thanks tom,
I've resolved using String builder to concat the query and place into a IBoolean object rather than an ICriteria Object.
I've now run into an issue with the Range function not being able to use negative inputs.
I am pretty sure that, removal of escaped characters depends on Searcher configuration, I.e, when I user "ExternalSearcher" I had similar issue, but then when I moved to "InternalSearcher" didn`t had this issue any more.
Examine: Removing escaped characters and wildcards
I've been attempting to create a examine ICriteria that uses path, however no matter what I try I cant get it to keep either wildcards or escaped '-'
string path = "-1,1012,1020*";
I have added trailing wildcards to the index, still doesnt work.
I've manually forced the Lucene syntax it doesnt work, Hell I've made the search even look for the nodeTypeAlias and wont return results.
I'm trying to have the search look at articles, under a certain section, with a certain set of tags, I have resolved the tags as a field in the index but it wont accept anything I send to it.
Hi Ryan
Have you tried adding an additional property to the index which is the path without the comma's ?
eg
-1 1012 1020
You can read more in this quite old but still quite relevant blogpost from @attackmonkey...
http://www.attackmonkey.co.uk/blog/2011/12/limiting-an-examine-search-to-the-current-site
regards
Marc
Its not the comma's thats an issue, its the "-" and the "*"
Escaping the minus due to it meaning Not in lucene means adding a backslash, but backslash hyphen isnt a C# escape configuration so the escape the backslash for lucene you need another backslash but then when the raw query is put into the ICriteria the escaping backslash for the hyphen is still there.
Alternatively using String builder I was able to leave just 1 backslash to escape the hyphen but then when it was put into the ICriteria it would strip both the hyphen and the asterisk wild card.
I found that theres no way for a raw query to take those needed characters so I've had to run 4 seperate index searches.
Hi Ryan
I may be completely misunderstanding, but with the path seperated only by spaces in a SearchablePath field, then it's just a question of searching the index with the SearchablePath field containing the id of the section you want to limit to...
So if you want to limit your search to the section with id 1012
then it is enough that the SearchablePath field contains 1012, the spaces enable you to find the id anywhere in the path string, without having to do anything clever with wildcards!
eg
but as I say, may be misunderstanding what your after.
regards
Marc
Hi marc, The issue has absolutely nothing to do with the commas.
As I previously stated Its not the comma's thats an issue, its the "-" and the "*" characters that are being removed as my initial message outlined.
There is no reason to add an additional index for an already existing field wen the only requirement is that 2 additional characters are being stripped by lucene even when following proper syntax of escaping and wildcards.
Ryan,
For path queries i have always inject in new field without , then done query on the parent not full path. So you have
I have done
string path = "1020";
and it works for me so i only get all docs that have parent 1020
Regards
Ismail
Hi Ryan
This may be of help: https://github.com/umbraco/Umbraco-CMS/blob/dev-v7/src/Umbraco.Web/PublishedContentExtensions.cs#L426
Thanks,
Tom
Hey guys, So the reason I need to have the full path string is because I'm not querying their direct parent, rather root node with a section where the content types sit, almost all of them dont have a direct parent for me to query without triplicating the resolves.
Thanks tom,
I've resolved using String builder to concat the query and place into a IBoolean object rather than an ICriteria Object.
I've now run into an issue with the Range function not being able to use negative inputs.
Find: -25.4564813
Double min: -26.564648; Double max: -23.464648; Range("Latitude", min, max, true, true)
Returns none but: Double min: 26.564648; Double max: 23.464648; Range("Latitude", min, max, true, true)
Returns the right results with using the polar opposite range
I am pretty sure that, removal of escaped characters depends on Searcher configuration, I.e, when I user "ExternalSearcher" I had similar issue, but then when I moved to "InternalSearcher" didn`t had this issue any more.
is working on a reply...