I want to search a particular node-type alone.Actually apache solr filter out the search result based on the node-type. But my requirement is to search a particular node-type only.

Comments

drunken monkey’s picture

I think the easiest way to allow just searches for nodes of a particular type would be to edit apachesolr_search_search() in apachesolr_search.module to always append " AND type:story" (with "story" replaced by the type in question, of course).

But a better way would probably be to not even index nodes with the wrong type in the first place. Just change "if ($node->nid) {" to "if ($node->nid && $node->type == 'story') {" in ApacheSolrUpdate:update_index() and reindex the site, that should suffice.

JacobSingh’s picture

What about for a first iteration if we just provide a text field on the settings page where an admin can specify a fragment of a query which gets appended to each query?

anbarasan.r’s picture

Thanks for your immediate reply I will try it and revert back to you.

robertdouglass’s picture

@JacobSingh: I like your idea and it is similar to a use case that I have to meet very soon. The advantage to your idea over what drunken monkey suggested is that we can remove that part of the query before displaying things in the results. We wouldn't want to always have -type:story in the breadcrumb, for example, so we need to remove that before rendering anything. The good news is that the query object is built in a way to handle this. See Solr_Base_Query::add_field(), remove_field(), has_field().

anbarasan.r’s picture

The Apache solr search module having the filter operation for the author and title only.If suppose we need the Advanced search option in our site we need to have some more filter field, for this kind of requirement i think we need to build that existing XML with those additional fields, So how can i build the existing XML with some additional field?Where i need to change the code?

drunken monkey’s picture

I don't know exactly, what you mean. The module has defined facet blocks to filter by author, type and taxonomy terms, but the basical search functionality is available for all other fields defined in the schema.xml as well (except for body, which is merged into the text field). For example, "comment_count:0" finds all nodes without comments.
But this is rather off topic, so please file another issue for additional questions.

mattlc’s picture

Just add parameter to your search string on the fly like this :

$searchString=$searchString.' type:'.$nodeType

Then, you just need to implement a callback function which calls :

apachesolr_search_search($op = 'search', $keys = $searchString);

hope this will help.

JacobSingh’s picture

We really need to implement this generically so people don't have the module.

There are plans to implement this via a "save this search as a search form" function. Where you can do a search for type = story and then save that as a new search box / form so the criteria is pre-filled when the users searches.

The best way to do this is not to hack it as mattc suggests (which will totally work), but implement hook_apachesolr_modify_query(). See the source in apachesolr_search for how to implement it. apachesolr_nodeaccess also implements it.

If this works, please close this issue.

pwolanin’s picture

Status: Active » Closed (fixed)