blacklight solr config facet fields - ruby-on-rails

We have a website that we are building running ruby 2.0, rails 4.0.1, blacklight 5.1.0, Apache solr 4.2 with sunspot solr gem for ruby.
We currently have the full solr index with products. If we search * we are able to see all the products. If we try and search a category this does not work.
We are stuck at this point and are not sure how to get the facets to work.
Can anyone lead us in the right direction here as any research we have done has turned up no results.
Solrconfig.xml - http://pastebin.com/RkCS1GUT
scheme.xml - http://pastebin.com/Cffu2Q3r
These files above are modified from the original blacklight example. The material field is currently the one we are using to try and search.
Thanks

If you look at the product data, you have the category in some field. Examine your logs to see what query Blacklight is producing. Obviously it is not targeting the same field. Then move the data or adjust the Blacklight config.
To define facet fields in Blacklight, do something like this (in initializer or in a given Controller):
configure_blacklight do |config|
config.default_solr_params = {
:'q.alt' => "*:*",
:defType => 'dismax',
:facet => true,
}
config.add_facet_field 'objectType_facet', :label => 'Object Type'
config.add_facet_field 'content_type_facet', :label => 'Content Type'
end
The field names and labels will vary for your data, of course.

Related

Using Atlas Search with Mongoid on Rails

I am trying to get full text search with Atlas to work in my Rails app. I have set up the index following this tutorial in their docs. When I test the query in a vacuum it seems to work as expected, I'm able to query my database and get the results I would expect, but it seems like the documentation around how to do this in Mongoid is lacking. I have found this documentation for running text search in Mongoid, but it explicitly calls out that it isn't Atlas Search.
Has anybody successfully implemented an Atlas Search index/query using Mongoid (or otherwise in a Rails app) and, if so, could you please point me towards the relevant docs.
Alright - after some experimentation with this I have found that the following code will work with the current version of mongoid:
TableName.collection.aggregate([{
'$search' => {
'index' => 'index_name',
'text' => {
'query' => 'some string to search',
'path' => {
'wildcard' => '*'
}
}
}
}])

Rails: Datagrid enum filter does not work when multiple or checkboxes options are true

I have a form that is using Datagrid for searching on a single table. The filters and searching work as expected, including this one:
filter(:location, :enum, :select => :locations)
However, when I try to make that filter show up as checkboxes, like so...
filter(:location, :enum, :select => :locations, :checkboxes => true)
...the checkboxes show up but the filter no longer works, and it returns the result set as though I never checked any of the checkboxes at all. This same unexpected behavior also happens when I try to use the :multiple option. According to the Datagrid gem documentation I don't see any other requirements for making a filter work with checkboxes or multiple select options.
When viewing the requests on my local server, I noticed that the location filter is not being added to the SQL query when :multiple or :checkboxes is set to true, but the values ARE being passed in the query string, like so (indicated by FBR and FBZ):
http://localhost:3000/searches/index?utf8=✓&searches_grid[name]=Foo&searches_grid[location][]=FBR&searches_grid[location][]=FBZ&commit=Search#searchAnchor
Here's what the working example (no multiples and no checkboxes) looks like:
http://localhost:3000/searches/index?utf8=✓&searches_grid[name]=Foo&searches_grid[location]=FBR&commit=Search#searchAnchor
I'm not sure if Datagrid is having trouble rendering parameters that are sent as arrays, or if there's some kind of issue with my versions of Rails/Ruby/etc, or what's going on. If anyone has any suggestions or workarounds I would greatly appreciate them, and if not I will try submitting a Gitlab issue for the gem.
I am using Datagrid 1.5.4, Rails 5.0.3, and Ruby 2.3.1p112.
After hours of dissecting everything in my code, I noticed that the location parameters of the search_params action in my controller was missing the square brackets to allow it to contain multiple values:
params.require(:searches_grid).permit(
:name,
...more params...
:order,
:descending,
location: [] # <-- Had to add brackets here
)
Now it's working as expected.

Sunspot and Solr: Google-like "site:" in search

I'm fairly new to Sunspot and Solr.
I'd like to implement something similar to the Google site: phrase in searches, so that when I search for
something
I get all records related to "something". However, if they search
something site:example.com
It only displays results where the site attribute is example.com.
At the moment I've got:
searchable do
text :full_text
text :title, :boost => 5
text :excerpt
end
Do I need to index the site attribute? How would I implement the above idea?
No. Just make sure you gsub your params[:query] in your controller. Extract the value next to site: and add a where close to match the site. You'll be left with something.

Can I ignore certain fields that are too long in Hirb?

I am using Hirb in my Rails console to try to display mongoid records in a nicer looking table, but the _id, created_at, and updated_at fields take too much space and, even though I really have one meaning field, name, when I do a Project.first it returns a rather disintegrated table:
Is there any chance that there's a way to 'ignore' or 'hide' certain fields?
When you open up hirb, run this:
table projects, :fields => [:name]
Then Project.all and enjoy! ;-)
Also see this: Hirb - Irb On The Good Stuff.
UPDATE:
"Hirb also supports a yaml configuration file (config/hirb.yml or ~/.hirb.yml)"
---
:output:
Project:
:options:
:fields:
- name

How to add conditions to thinking-sphinx search?

I've recently installed thinking-sphinx on my ruby on rails app. As first sight, everything works great, I can search words and it will find them. Now, when I try to add some filters(such as, for example, provinces, categories, etc) using:
MyModel.search 'hello' :conditions => 'category_id=1' for example, it will throw me the following exception:
searchd error (status: 1): invalid or
truncated request
I've been reading some docs on the thinking-sphinx plugin, and I guess I have to do something else than this syntax.
To summarize: until the moment, I just installed the windows service, then I defined a index in one model, and then i tried to search. Again, I succeeded while searching without conditions, but failed while searching with.
Any help will be appreciated.
Thanks,
Brian
Assuming your model has category_id:
MyModel.search 'hello', :with => {:category_id => 1}
:conditions is for full text searching specific attributes, :with is for filtering search results.
More info here: http://freelancing-gods.com/posts/a_concise_guide_to_using_thinking_sphinx

Resources