tags:

views:

51

answers:

1

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
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
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
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
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
you can change the analyzer in the configuration file Searchable.groovy
Aaron Saunders
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
You have to put a "\" before the hypen in the query for it to work
Aaron Saunders
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
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
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
Same 0 results with or without escape \
Micor
As a comparison, running: Location.search("motors", analyzer: 'whitespace'), debug: search.DefaultSearchMethod query: [+motors +(alias:Location)], [1] hits, took [0] millis
Micor
You only need one "\". You are using too many
Aaron Saunders
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
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
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
Thank you for the time you spent going back and forth, it was very useful.
Micor