This might not be the whole solution, but this is how I've been dealing with searching csvs and not having "1" match "10". Maybe there's a better way, but this is what I've got for the time being. You could probably expand on this and preprocess your node lists into something that is easier to search on. Maybe, on ApplicationStarted, for each node, combine both the list1 and list2 into a single list for searching. That might simplify things.
On ApplicationStarted, we remove all of the blank space and then convert all of the commas to spaces.
public class UmbracoEvents : ApplicationEventHandler
{
protected override void ApplicationStarted(UmbracoApplicationBase umbracoApplication, ApplicationContext applicationContext)
{
ExamineManager.Instance.IndexProviderCollection["MyCustomIndexer"].GatheringNodeData += OnGatheringNodeData;
}
protected void OnGatheringNodeData(object sender, IndexingNodeDataEventArgs e)
{
// make nodes searchable
if (e.Fields.ContainsKey("nodes"))
{
var nodes = HttpUtility.HtmlDecode(e.Fields["nodes"].ToLower(CultureInfo.InvariantCulture));
e.Fields["nodes"] = nodes;
// remove all spaces in each node id list
// convert commas between items into blank space for the Whitespace Analyzer
e.Fields["searchNodes"] = e.Fields["nodes"].Replace(" ", "").Replace(',', ' ');
}
}
}
Then we use the WhitespaceAnalyzer in the /config/ExamineSettings.config file.
Examine query
I'm having a bit of trouble creating an examine query
My index stores two lists of id (comma separated).
I want to compare these lists with other two lists and get the nodes that have more matches
Example:
search1 = "1,20, 50" search2 = "5"
Index
node1 { list1 = "55,90", list2 = "1"} node2 { list1 = "50,90", list2 = "1"} node3 { list1 = "1,20,90", list2 = "5"}
Desidered result
node3 //3 matches node2 //1 match
obviously search term "1" shold not match "10"
Do you have any ideas?
Thank you
This might not be the whole solution, but this is how I've been dealing with searching csvs and not having "1" match "10". Maybe there's a better way, but this is what I've got for the time being. You could probably expand on this and preprocess your node lists into something that is easier to search on. Maybe, on ApplicationStarted, for each node, combine both the list1 and list2 into a single list for searching. That might simplify things.
On ApplicationStarted, we remove all of the blank space and then convert all of the commas to spaces.
Then we use the WhitespaceAnalyzer in the
/config/ExamineSettings.config
file.Then, when we search, we do something similar with the search text. We strip out the blank space, and convert the commas into spaces.
Hope there aren't too many errors in this. I did a lot of copy pasting and editing into this editor, and might have broken something.
Thank you for you answer.
I had noticed I've made an error: the values in in the index are actually stored as space separeted, not with comma.
It seems that the following code is working, but I want to further test it when I will have more data.
is working on a reply...