Package net.sourceforge.pebble.search

Examples of net.sourceforge.pebble.search.SearchHit


public class SearchHitByDateComparatorTest extends SingleBlogTestCase {

  public void testCompare() {
    Comparator comp = new SearchHitByDateComparator();

    SearchHit h1 = new SearchHit(null, "", "", "", "", new Date(321), 1.0F);
    SearchHit h2 = new SearchHit(null, "", "", "", "", new Date(123), 1.0F);

    assertTrue(comp.compare(h1, h1) == 0);
    assertTrue(comp.compare(h1, h2) != 0);
    assertTrue(comp.compare(h1, h2) < 0);
    assertTrue(comp.compare(h2, h1) > 0);
View Full Code Here


public class SearchHitByScoreComparatorTest extends SingleBlogTestCase {

  public void testCompare() {
    Comparator comp = new SearchHitByScoreComparator();

    SearchHit h1 = new SearchHit(null, "", "", "", "", new Date(123), 0.5F);
    SearchHit h2 = new SearchHit(null, "", "", "", "", new Date(321), 0.3F);

    assertTrue(comp.compare(h1, h1) == 0);
    assertTrue(comp.compare(h1, h2) != 0);
    assertTrue(comp.compare(h1, h2) < 0);
    assertTrue(comp.compare(h2, h1) > 0);
View Full Code Here

        Query query = QueryParser.parse(queryString, "blogEntry", getAnalyzer());
        Hits hits = searcher.search(query);

        for (int i = 0; i < hits.length(); i++) {
          Document doc = hits.doc(i);
          SearchHit result = new SearchHit(
              blog,
              doc.get("id"),
              doc.get("permalink"),
              doc.get("title"),
              doc.get("truncatedBody"),
View Full Code Here

        Query query = QueryParser.parse(queryString, "blogEntry", getAnalyzer());
        Hits hits = searcher.search(query);

        for (int i = 0; i < hits.length(); i++) {
          Document doc = hits.doc(i);
          SearchHit result = new SearchHit(
              blog,
              doc.get("id"),
              doc.get("permalink"),
              doc.get("title"),
              doc.get("subtitle"),
View Full Code Here

public class SearchHitByDateComparatorTest extends SingleBlogTestCase {

  public void testCompare() {
    Comparator comp = new SearchHitByDateComparator();

    SearchHit h1 = new SearchHit(null, "", "", "", "", "", new Date(321), 1.0F);
    SearchHit h2 = new SearchHit(null, "", "", "", "", "", new Date(123), 1.0F);

    assertTrue(comp.compare(h1, h1) == 0);
    assertTrue(comp.compare(h1, h2) != 0);
    assertTrue(comp.compare(h1, h2) < 0);
    assertTrue(comp.compare(h2, h1) > 0);
View Full Code Here

public class SearchHitByScoreComparatorTest extends SingleBlogTestCase {

  public void testCompare() {
    Comparator comp = new SearchHitByScoreComparator();

    SearchHit h1 = new SearchHit(null, "", "", "", "", "", new Date(123), 0.5F);
    SearchHit h2 = new SearchHit(null, "", "", "", "", "", new Date(321), 0.3F);

    assertTrue(comp.compare(h1, h1) == 0);
    assertTrue(comp.compare(h1, h2) != 0);
    assertTrue(comp.compare(h1, h2) < 0);
    assertTrue(comp.compare(h2, h1) > 0);
View Full Code Here

   * @param o2  object 2
   * @return  -n, 0 or +n if the score represented by the second hit is less than,
   *          the same as or greater than the first, respectively
   */
  public int compare(Object o1, Object o2) {
    SearchHit h1 = (SearchHit)o1;
    SearchHit h2 = (SearchHit)o2;

    int comparison = Float.compare(h2.getScore(), h1.getScore());
    if (comparison == 0) {
      return h2.getDate().compareTo(h1.getDate());
    } else {
      return comparison;
    }
  }
View Full Code Here

   * @param o2  object 2
   * @return  -n, 0 or +n if the score represented by the second hit is less than,
   *          the same as or greater than the first, respectively
   */
  public int compare(Object o1, Object o2) {
    SearchHit h1 = (SearchHit)o1;
    SearchHit h2 = (SearchHit)o2;

    return h2.getDate().compareTo(h1.getDate());
  }
View Full Code Here

      SearchResults results = blog.getSearchIndex().search(query);

      if (results.getNumberOfHits() == 1) {
        // if there is only one hit, redirect the user to it without the
        // search results page
        SearchHit hit = (SearchHit)results.getHits().get(0);
        return new RedirectView(hit.getPermalink());
      } else {
        // show all results on the search results page
        String sort = request.getParameter("sort");
        if (sort != null && sort.equalsIgnoreCase("date")) {
          results.sortByDateDescending();
View Full Code Here

TOP

Related Classes of net.sourceforge.pebble.search.SearchHit

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.