I am using 0.5.5.1 grails searchable plugin. Search works on most of my objects and fields. However, I have a class with String id and it consists of a Number Dash Number like 1-1, 1-2, .. and so on. I cannot search this object by id. My guess its due to dash in it, it might be ignored by searchable analyzer? Not sure.. Any ideas, suggestions?
+1
A:
i would first suggest that you download Luke http://code.google.com/p/luke/ and take a look at what exactly is going into the index.
The default index location is
"${user.home}/.grails/projects/${app.name}/searchable-index/${grails.env}"
it is quite possible that the dashes are getting removed when the index is being created based on the analyzer you are using to created the index.
I also believe you might need to do some character escaping when executing the query of the dash is included in the index
Aaron Saunders
2010-08-09 19:48:54
Thanks for your response. I downloaded luke and my index does show the id being indexed correctly with 1-1. I am trying escaping the -, does not seem to work for now... still testing
Micor
2010-08-09 20:56:58
what does the query look like? what i usually do is get the query working in Luke first then go back to my code and correct the problem.
Aaron Saunders
2010-08-09 21:25:41
I suspect you are using the StandardAnalyzer, if you use the WhitespaceAnalyzer and create your query like thisstop\-gapwith the backslash, it will stay in the query
Aaron Saunders
2010-08-09 21:34:19
Running query in Luke directly for: 1-1 using: org.apache.lucene.analysis.standard.StandardAnalyzer or org.apache.lucene.analysis.WhitespaceAnalyzer returns results but not with org.apache.lucene.analysis.SimpleAnalyzer... Weird because I believe by default Grails plugin is using Standard as well
Micor
2010-08-09 21:57:06
you can change the analyzer in the configuration file Searchable.groovy
Aaron Saunders
2010-08-09 22:14:04
Tried that, I put:compassSettings = ['compass.engine.analyzer.whitespace.type': 'org.apache.lucene.analysis.WhitespaceAnalyzer']and searching with Parent.search(params.q,analyzer: 'whitespace')still not returning the results for 1-1 while searching by other fields returns results
Micor
2010-08-09 22:17:43
You have to put a "\" before the hypen in the query for it to work
Aaron Saunders
2010-08-09 22:55:30
I do but it still does not return the results, something is really off with my setup as I dont see my new entries being indexed. Only those that are there on start up...
Micor
2010-08-09 23:30:26
Let's do one at a time,Force a complete rebuild of your index to get the new index based on the new configuration.Call indexAll action on searchableController then retry test
Aaron Saunders
2010-08-09 23:54:52
Run indexAll, results compass.CompassGpsUtils Finished Searchable Plugin bulk index, 884 ms. Running:1. Location.search("1\\\\-1", analyzer: 'whitespace'), debug: search.DefaultSearchMethod query: [+1\-1 +(alias:Location)], [0] hits, took [1] millis2. Location.search("1-1", analyzer: 'whitespace'), debug: search.DefaultSearchMethod query: [+1-1 +(alias:Location)], [0] hits, took [1] millis
Micor
2010-08-10 00:25:40
Same 0 results with or without escape \
Micor
2010-08-10 00:26:16
As a comparison, running: Location.search("motors", analyzer: 'whitespace'), debug: search.DefaultSearchMethod query: [+motors +(alias:Location)], [1] hits, took [0] millis
Micor
2010-08-10 00:27:45
You only need one "\". You are using too many
Aaron Saunders
2010-08-10 02:21:26
You are looking at Location.search, the \ there needs to be escaped, you will see that actual debug statement shows only one \ in +1\-1
Micor
2010-08-10 02:53:32
Hmm getting somewhere, its only the ID field that is not being searched with a dash in it. If I put a dash in another field and search for it, I will get the results back.. This has to be something within the plugin...
Micor
2010-08-10 03:23:16
i just re-read your question and I would suggest creating a field with a different name than "id" to solve you problem.also...please accept the answer if you found it useful
Aaron Saunders
2010-08-10 19:44:02
Thank you for the time you spent going back and forth, it was very useful.
Micor
2010-08-10 21:17:00