Hi, I did a simple (and maybe not efficient) CCK introspection to find all fields and automatically propose them as facets/filters/indexes using the hook_apachesolr_cck_fields_alter().
Here is the code, maybe it could be included as contrib module, if you think code is right. Or maybe I could commit it and maintain it, but whatever happens I'm just don't want to write this 20 lines in every custom module I do anymore.
In all case, this is still a good and working code sample for people that need to implement this hook.
PS: rename the .module.txt file to .module
Comments
Comment #1
pounardNote: this should work with both 1.x and 2.x-dev versions.
Comment #2
robertdouglass commentedTo clarify your needs - you're writing custom search modules using the apachesolr.module, and need this functionality to be better abstracted to support your development? Looks very interesting, but please explain more.
Comment #3
pounardFor this feature request, the important thing is I do deeper CCK introspection that default one from 'apachesolr' module. I expose every field with data type I can predict.
This is only a simple helper that save me some time by trying to do automatically the same job I would have done manually if I wanted to expose some new facets or force the 'apachesolr' module to create index for these fields by implementing its hooks.
FYW (but it's not this post topic), the module I'm currently writing is a ergonomic query building UI for end-users, giving a full API to save/load/edit those built queries, and giving a small Solr query caching mecanism that avoid query construction when not modified.
It kinda looks like a view's edit form, but much more simple, built for being used a lot by end users. I known that views 3 module will allow to construct Solr queries, but I'm looking towards something a lot more simple.
EDIT: And yes, I need *a lot* of apachesolr features to be more abstracted :) The query construction object is not generic enough, I had to write my own; I'll submit it in one new issue queue when It'll be stable and tested.
I will continue to submit features requests during the next weeks.
Comment #4
robertdouglass commentedI'm looking forward to the query construction object. It's high on my list of things that need massive refactoring. I'm glad you're working on it.
Comment #5
pounardIf I read this well http://wiki.apache.org/solr/SolPHP it seems that there is a query construction API already done. It might be valuable to look at it.
EDIT: typo.
Comment #6
pounardI paste you my custom query constructor, beware, this might not fit with your needs, but you may like it (this is in early development phase) but you could overlook and see if it can help you.
Comment #7
robertdouglass commentedLet's move the query discussion to a new thread.
Comment #8
ayalon commentedHi pounard!
Thanks for this cool module! I wanted to store some cck fields in the solr index to render a better search result containig an imagefield and cck fields.
So I used your module.
Unfortunately it is not possible to store multiple values for one cck field in the index. The current API does not support this.
http://drupal.org/node/664866
This means, it is not possible to save the filepath, filemime, data description of an imagefield in the solr index.
Because of this issue I changed your module and added this behaviour for the special case "filefield".
Attached you will find my version of your module. Maybe we should start a new project for this module?
Comment #9
pounardMaybe I will, in fact this module is quite simple and has very few lines, I'd prefer to see apachesolr maintainers to adopt it and place it among with other contrib modules rather than create a new project for this, but this is totally up to them.
Because I don't have much time to give to the community these days, and it seems that those maintainers have a lot of work too, I let this module live on this issue queue until both me and them have time to discuss about this.
Comment #10
Macronomicus commentedThanks to both of you!
I am testing now.
Comment #11
Macronomicus commentedThe original code provided by pounard works fine, I do have many more of my cck fields in solr now.
I think the new addition from ayalon needs a tweak or I suppose it could be my imagefield, I dont have much time to look into it right now but it does seem interesting, if I figure something with it ill post it back.
When I tested ayalon's version and got some multivalue field errors in the dblog.
Comment #12
robertdouglass commentedYou have my attention. Don't create a new project quite yet. That may be the best way to go, but let me have a good look first. Thanks.
Comment #13
pounardNo problem, take the time you need. The code remains in this issue queue.
Comment #14
ayalon commentedI'll have a look at this. It seems that you have multiple images attached to one node.
The starting module has a typo in the filemime callback. It will never work. filemime will never be indexed.
should be
But we need a solution for multivalue imagefields. I try to fix this.
Comment #15
haxney commentedIs the use of
per-fieldreally the best way to go? I have had success writing Solr/CCK mappings (before I stumbled across this issue) as:and that worked fine. This has the advantage of updating automagically when new fields are added, without having to re-run
apachesol_rcck_apachesolr_cck_fields_alter. I'm working on modifying it to behave as I have described, and will post a patch when I've got it working.Also, using
floatfor all of the number types seems wrong. Thenumber_integertype should certainly be anintegertype andnumber_decimalmight even need to be a string (to preserve the exact value of the numeric type). I'll make these changes as well. Atdoublewould probably be fine fornumber_decimalfields.As far as multiple values per field, the solution being developed in #558160: date facet for cck field for the
datemodule is to create a separate Solr field with '_end' appended to the end of the name (for the end date). That is, if you had a multi-valued date field with start and end times calledtimes, you would have data that looked something like this:In other words, you use parallel arrays. It's not a terribly pretty way of doing it, but Solr doesn't yet support fields with compound values (though it looks like it's in the works), so this is probably the best we have for now.
It looks like the patch in #558160: date facet for cck field has a fairly general way of specifying compound fields, so it would be better to use that than to create a bunch of special cases for
filefield, since it is hardly the only field to use compound values.Comment #16
robertdouglass commentedthis is true.
Comment #17
pounard@haxney #15
Totally agree with you on this. Note that this piece of code is unfinished, I was waiting for constructive comments such as yours.
Agree too.
Comment #18
haxney commentedI've been working on merging the bits from #558160: date facet for cck field in here as well. I have my work at http://github.com/haxney/apachesolr.
I've added a
'default_index'option to CCK field definitions which sets up a default'indexing_callback'for the field type. This makes specifying types much easier when no additional processing needs to be done.The definitions for the
'nodereference'type (ignoring the'display_callback') would be:This means that the value
$node->$field_name[$x]['nid']would be indexed (for each$x, if the field accepts multiple values). This is much simpler than having each field type define its own indexing callback.Eventually (and it may be more work than it's worth), I plan to allow for
'default_index'to accept an array that looks something likeFor the example of the link module. This would mean "create two Solr fields,
${field_name}_nameand${field_name}_website, which will receivetitleandurl, respectively." There are some cases, like the link CCK field, which are compound, but do not require any special processing before being handed off to Solr. There are probably only a few instances in which this will actually be useful, but it shouldn't be too hard.Once this is stabilized (and I plan on writing some unit tests for this), it should make adding support for most of the CCK fields out there much more straightforward.
Comment #19
haxney commentedWoo! I now have CCK fields being indexed by Solr with a minimum of fuss!
Here are the fields which I now have working (in theory; I've only actually tested ca_phone, text, and email):
Once again, the code is hosted on GitHub. What would make integrating it back into the CVS repo easiest? It's more changes than would make sense as a single patch, so how should it be handled? I'm handy with Git, so I can hack up the set of commits any way that is convenient.
There is still some polishing that needs to be done, as well as documentation (since it changes how hook_apachesolr_cck_fields_alter() works), and I'll take care of those in the next few days.
Comment #20
mathieu commentedSubscribe
Comment #21
Macronomicus commentedhaxney...
I tested your version of apachesolr and while it seems to work there are no new fields being indexed.
The original post by pounard gets all those elusive cck fields to show on the filters page, in fact I didnt notice any difference when testing your version of apachesolr, does it also require pounards cck introspection module? I didnt test that combined with yours yet.
Cheers!
Comment #22
haxney commented@macrocosm
What do mean? That the fields aren't being sent to the Solr server? What part is working and what isn't working?
It has definitely worked for me in testing (though I only am testing with 4 documents, so I don't know how it does with larger sizes), and you may need to reindex. I haven't really looked at what triggers a reindexing, so I usually rely on going to
admin/settings/apachesolr/indexand checking "reindex immediately" and hitting "Re-index all content." You could also try running cron.Also, the best way to tell if the content is really being indexed is to run a simple query through the Solr admin interface and see if it includes the CCK fields (which will all be named something like "
ss_cck_field_text").I also have all the CCK fields showing up in my "enabled filters" view on
admin/settings/apachesolr/enabled-filters, so I don't know what's wrong.Make sure that you are replacing the entire apachesolr project with my new version, as it modifies
apachesolr.moduleandapachesolr.index.inc, among other core parts of the project. You can go here for a tarball of the current version of my changes.Let me know if that helps.
Comment #23
pounard@haxney
Because your code patch the core module, could you post patches here in order for us to see your modifications in a more "usal way"? I mean, I could do it my self by downloading your branch and legacy one side by side, but I could not be sure what part of the patch is really this feature (got the hunch that that's not the only stuff or behavior you modified).
Comment #24
Macronomicus commented@haxney
I did do a manual re-index which didnt seem to make a difference. I also did a full replacement with your module and ran update.php too.
I used the "enabled filters" page for a short cut to see if solr was picking up the other fields. It seems to me that while a lot of the fields are there well more than half were not. My main content type thats being indexed is a real estate mls listing and has many fields & types of fields. Seems apachesolr doesnt bring "CCK filefield field" or "CCK number_integer field" at all, and even on the "CCK text field" only about half the fields showed up. But like I said Pounards module at the top of the page brings in every one of them, with no errors that I have found.
Did you blend pounard's module into your arrangement? ..or is it a new direction?
Comment #25
Macronomicus commented@haxney
I will test your new version this weekend, thanks for posting it.
Cheers!
EDIT: I should also add that I am using the latest cck-6.x-2.x-dev since thats the only one that works with views 3.x
Comment #26
ManyNancy commentedIt's not a good idea to use the haxney fork on a production site right?
Comment #27
Macronomicus commentedWell if you can get it to work and it tests ok I dont see why not... but haxney's version is really for testing deving im guessing.
That said the post by pounard in post #1 above does automatic CCK introspection well AFAICT.
Comment #28
ayalon commentedNo it's not a good idea. We should definitly create an new module.
@haxney
Please use the module from #8 and provide some patches so we can test this f.ex. the link field indexing.
@robertDouglass
Could we create a new module for this? We have now a lot of code and because we don't have a cvs repository, the whole module code breakes in to different forks.
Comment #29
pounard@ayalon #28, yep, applying such patches is not a good idea.
Whatever you choose to do, 2.x is still in alpha release, so it's still the right time to make a better API, I think the part about CCK is still quite obscure. This does not means that this particular feature may still remains in an additional module.
Comment #30
mcarbone commentedI tested haxney's version on a sandbox installation and it worked for the text and nodereference fields I have, although the block is now rendering the nodereference options as
<a href="/node/1">Premo Haero Quia</a>instead of justPremo Haero Quiaas it was before.Comment #31
robertdouglass commentedI've committed #558160: date facet for cck field so you'll probably have to merge/re-roll. Please double check everything and then change status when I'm able to review. Thanks.
Comment #32
miraclestyle commentedSubscribe
Comment #33
carmatic commentedApacheSolr is a GREAT module, but it lacks integration of CCK Fields. In my case I have one Integer Field and one Float Field in my CCK and it gets not automatically indexed by ApacheSolr (it works on 'some' text fields though). What I'm trying to achieve is simply sort by one of my CCK fields.
Of course I downloaded the apachesolr_cck extension but both (my integer field and my float field) do not get indexed. Instead of the numeric values it always has some random text in those fields. The text seems to be from the first text field in my CCK.
Comment #34
Maikel commentedSubscribe
Comment #35
bennos commentedSubscribe
Comment #36
jpmckinney commentedDoubtful this will be integrated into 6.x-2.x
Comment #37
ManyNancy commentedSo apache solr 6.x doesn't integrate with cck at all?
Comment #38
jpmckinney commentedComment #39
jpmckinney commentedNevermind, having re-read the issue, this now seems like something that can go into 6.x.
Note that 6.x already has CCK integration for most fields on which you would want to do faceting. This patch just adds more integration.
Comment #40
jpmckinney commentedI don't see a patch. Allowing faceting on many CCK is not a good idea. Location CCK fields, for example, often have unique values, so faceting is not useful. For integer/float fields, we would want to add facet blocks that support ranged queries.
Anyway, 6.x-2.x will be unsupported soon, and 6.x-1.x is feature-frozen. 7.x has a different API. Please re-open a 7.x issue if you find Field API support in 7.x lacking. I think this should probably be its own module for 6.x.