0

I am having some trouble with creating a search module (dictionary) that uses apache solr. The current module is connected to a solr instance from a different source that has a indexation from a postgresql database with it's own schema.

Now I'm in the process migrating all the content to nodes in Drupal and so far so good. The thing now is that I need to change the search request from the current solr to Drupal apachesolr with its standard schema. Problem is that I am relative new to how solr works, but I do understand the basic structure.

Anyone that might be able to give me a hand or point me to some kind of documentation to how to do this?

I tried to change the query search quartiles from what i could find in the schema . The only thing keep getting when i do a search is "Your search yielded no results"

Here is the cod in the callbacks.inc file unmodified

<?php

function ne_norstedts_page($types) {
  $ret = '';

  $form = drupal_get_form('ne_norstedts_search_form', $types);

  // Render search form.
  $ret .= '<div id="norstedts-search-form" class="fourcol">';
  $ret .= render($form);
  $ret .= '</div>';

  // Get search results and output them
  isset($_GET) ? extract($_GET) : '';
  if (isset($q) && isset($from) && isset($to) && isset($type)) {
    $query = array(
      'q'  => $nq,
      'fq' => 'type:norstedts AND subtype:' . $from . '-' . $to . '-' . $type,
      'start' => isset($page) ? ($page) * 10 : 0,
    );

    $result = ne_api_get_api_fetch('/search', $query);

    $title = '';
    foreach ($types as $t => $name) {
      if ($t == $type) {
        $title = $name;
        break;
      }
    }

    $ret .= theme('ne_norstedts_results', array('result' => $result['result'], 'title' => $title));
  }

  return $ret;
}

/**
 * Gets text for a single word for ajax
 */
function ne_norstedts_ajax_load_word() {
  $url = isset($_GET['url']) ? $_GET['url'] : '';
  if ($url) {
    $result = ne_api_get_api_fetch($url);
    if (isset($result['text'])) {
      echo drupal_json_encode($result['text']);
    }
  }
  exit;
}

and here is my modified version of it

<?php

function ne_dictionary_page($types) {
  $ret = '';

  $form = drupal_get_form('ne_dictionary_search_form', $types);

  // Render search form.
  $ret .= '<div id="dictionary-search-form" class="fivecol">';
  $ret .= render($form);
  $ret .= '</div>';

  // Get search results and output them
  isset($_GET) ? extract($_GET) : '';
  if (isset($q) && isset($from) && isset($to) && isset($type)) {
    $query = array(
      'q'  => $nq,
      'fq' => 'site:' . $from . '-' . $to,
      'start' => isset($page) ? ($page) * 10 : 0,
    );

    $result = apachesolr_search_search_page('/search', $query);

    $title = '';
    foreach ($types as $t => $name) {
      if ($t == $type) {
        $title = $name;
        break;
      }
    }

    $ret .= theme('ne_dictionary_results', array('result' => $result['result'], 'title' => $title));
  }

  return $ret;
}

/**
 * Gets text for a single word for ajax
 */
function ne_dictionary_ajax_load_word() {
  $url = isset($_GET['url']) ? $_GET['url'] : '';
  if ($url) {
    $result = apachesolr_search_search_page($url);
    if (isset($result['text'])) {
      echo drupal_json_encode($result['text']);
    }
  }
  exit;
}
  • I am not sure I understand your set up. Your old module was searching at an external solr instance. Now that you have all your content into drupal, you want to change your module so that it searches the drupal solr instance? – Mike Jun 27 '12 at 8:25
  • yeas that's right – Alex Welander Jun 27 '12 at 8:27
1

You dont need a module for this. Activate your solr module, index your content and the core drupal search will be replaced by the solr search. There is nothing else you need to do. From then on, every search you make using the domain.com/search/site url will be automatically directed to solr.

It is just a matter of setting the right options in the solr module.

  • that works whit out any problem i can use the solr model to search the indext content. The thing is that i need different search function on different pages in this case i am making a dictionary page that present a specified result from the indext content in solr. the plan is get it to work like this. I chose two languages we say swedish to English and then search for the word "car" what i want the search to do then is to search in the indexation for node domestication set whit Swedish-English and whit the word car in it and then present that result – Alex Welander Jun 27 '12 at 8:45
0

How about trying Apachesolr Views module, where you can create a view page and achieve your functionality. The parameters can be configured in filters.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.