Examples of Hits


Examples of org.apache.lucene.search.Hits

  if (ranks == null) return ("");
 
  try
  {
   //*-- submit the question to the search engine and fetch the hits
   Hits hits = getHits(question);
   if (hits == null) throw new IOException("Could not find any hits for question " + question);
  
   //*-- build the list of answers
   DbTools dbt = Constants.getDbt();
   dbt.openDB(Constants.EXT_FILES_DB, true, false); //*-- read only access
  
   Explanation explanation;
   LOOP: for (int i = 0; i < hits.length(); i++)
   {
     //*-- limit explanations for the top 100 hits
     if (i > 100) break LOOP; boolean foundHit = false;
   
     //*-- check if the hit rank matches the passed rank
     for (int j = 0; j < ranks.length; j++) if (ranks[j] == i) foundHit = true;
     if (!foundHit) continue LOOP;
    
     retv.append("Document: " + i + Constants.NEWLINE);
     explanation = is.explain(query, hits.id(i))
     Document doc = hits.doc(i);
     String key = doc.get("key");
     DatabaseEntry data = new DatabaseEntry();
     if (!dbt.fetch(key, data)) continue LOOP;

     //*-- extract the text
     IndexableDoc idoc = new IndexableDoc();
     idoc = (IndexableDoc) idoc.getBdbBinding().entryToObject(data);
     String line= idoc.getContents().toString();
     if (line.length() > 1000) line = line.substring(0, 999);
 
     retv.append(" Score: " + hits.score(i) + " TEXT: " + line + Constants.NEWLINE);
     retv.append(explanation.toString());
     retv.append("------------------------------------------------------------------");
     retv.append(Constants.NEWLINE); retv.append(Constants.NEWLINE);
   }
  } //*-- end of try
View Full Code Here

Examples of org.apache.lucene.search.Hits

public Hits getHits(String str)
{ return getHits(str, false); }
public Hits getHits(String str, boolean filter)
{
  Hits hits = null; bgramAnalyzer.setExtractEntities(false);
  try
  {
   QueryParser qp = new QueryParser("contents", bgramAnalyzer );
   if (filter) str = str.replaceAll("[^a-zA-Z0-9\"']", " ");
   query = qp.parse(str);
View Full Code Here

Examples of org.apache.lucene.search.Hits

                                analyzer);
    } catch (ParseException pe) {
      // TODO: wrap into own exception for more independence of lucene
      throw new QueryParseException(pe);
    }
    Hits hits = searcher.search(query);
    nrOfHits = hits.length();
    logger.info("Query returned " + nrOfHits + " hits.");
    List<ItemResult> results = new ArrayList<ItemResult>();
    for (int i = 0; i < hits.length() && i < maxResults; i++) {
      Document doc = hits.doc(i);
      long channelId = Long.parseLong(doc.get(ItemFieldConstants.CHANNEL_ID));
      ChannelIF channel = channels.getById(channelId);
      if (channel == null) {
        throw new UnretrievableException("channel " + channelId);
      }
      // TODO: could this be done in another fashion or using a context?
      long itemId = Long.parseLong(doc.get(ItemFieldConstants.ITEM_ID));
      ItemIF item = channel.getItem(itemId);
      if (item == null) {
        throw new UnretrievableException("item " + itemId);
      }
      results.add(new ItemResult(item, hits.score(i)));
    }
    searcher.close();
    return results;
  }
View Full Code Here

Examples of org.apache.lucene.search.Hits

      } else {
        aRetArr = null;
      }
    } else {
      if (DebugFile.trace) DebugFile.writeln("IndexSearcher.search("+oQry.toString()+")");
      Hits oHitSet = oSearch.search(oQry);
      int iHitCount = oHitSet.length();
      if (DebugFile.trace) DebugFile.writeln("hit count is "+String.valueOf(iHitCount));
      if (iHitCount>0) {
        aRetArr = new MailRecord[iHitCount];
        for (int h=0; h<iHitCount; h++) {
          Document oDoc = oHitSet.doc(h);
          if (DebugFile.trace) DebugFile.writeln("found "+oDoc.get("guid")+" "+oDoc.get("title")+" created by "+" "+oDoc.get("author")+" at date "+oDoc.get("created"));
          String[] aAbstract = Gadgets.split(oDoc.get("abstract"), '¨');
          aRetArr[h] = new MailRecord(aAbstract[0], aAbstract[1], aAbstract[2],
                                      aAbstract[3], aAbstract[4], aAbstract[5],
                                      oDoc.get("container"));
View Full Code Here

Examples of org.apache.lucene.search.Hits

      System.out.println(query);
      Searcher searcher = new IndexSearcher(ramDir);
      query = query.rewrite(reader);
      System.out.println(query);
      System.out.println("Searching for: " + query.toString(FIELD_NAME));
      Hits hits = searcher.search(query);
     
      BoldFormatter formatter = new BoldFormatter();
      Highlighter highlighter =new Highlighter(formatter,new QueryScorer(query));
      highlighter.setTextFragmenter(new SimpleFragmenter(50));
      for (int i = 0; i < hits.length(); i++)
      {
        String text = hits.doc(i).get(FIELD_NAME);
        int maxNumFragmentsRequired = 5;
        String fragmentSeparator = "...";
        TermPositionVector tpv = (TermPositionVector)reader.getTermFreqVector(hits.id(i),FIELD_NAME);
        TokenStream tokenStream=TokenSources.getTokenStream(tpv);
        /*
        TokenStream tokenStream2=
          (new StandardAnalyzer())
          //XFactory.getWriterAnalyzer()
View Full Code Here

Examples of org.apache.lucene.search.Hits

        {
            // Create a multi-searcher for looking up the information.
            searcher = new MultiSearcher( searchables );

            // Perform the search.
            Hits hits = null;
            if ( filter != null )
            {
                hits = searcher.search( specificQuery, filter );
            }
            else
            {
                hits = searcher.search( specificQuery );
            }

            int hitCount = hits.length();    
           
            // Now process the limits.
            results.setLimits( limits );
            results.setTotalHits( hitCount );

            int fetchCount = limits.getPageSize();
            int offset = ( limits.getSelectedPage() * limits.getPageSize() );

            if ( limits.getSelectedPage() == SearchResultLimits.ALL_PAGES )
            {
                fetchCount = hitCount;
                offset = 0;
            }

            // Goto offset.
            if ( offset < hitCount )
            {
                // only process if the offset is within the hit count.
                for ( int i = 0; i < fetchCount; i++ )
                {
                    // Stop fetching if we are past the total # of available hits.
                    if ( offset + i >= hitCount )
                    {
                        break;
                    }

                    try
                    {
                        Document doc = hits.doc( offset + i );
                        LuceneRepositoryContentRecord record = converter.convert( doc );
                        results.addHit( record );
                    }
                    catch ( java.text.ParseException e )
                    {
View Full Code Here

Examples of org.apache.lucene.search.Hits

                                            (CachingMultiReader) parentReader};
            reader = new CombinedIndexReader(readers);
        }

        IndexSearcher searcher = new IndexSearcher(reader);
        Hits hits;
        if (sortFields.length > 0) {
            hits = searcher.search(query, new Sort(sortFields));
        } else {
            hits = searcher.search(query);
        }
View Full Code Here

Examples of org.apache.lucene.search.Hits

   * @return the search results
   */
  private List doSearch(Query query,HitExtractor extractor,Filter filter,Sort sort) {
    Searcher searcher=SearcherFactoryUtils.getSearcher(getSearcherFactory());
    try {
      Hits hits=null;
      if( filter!=null && sort!=null ) {
        hits=searcher.search(query,filter,sort);
      } else if( filter!=null ) {
        hits=searcher.search(query,filter);
      } else if( sort!=null ) {
View Full Code Here

Examples of org.apache.lucene.search.Hits

    IndexReader reader=IndexReaderFactoryUtils.getIndexReader(indexFactory);
    IndexSearcher searcher=new IndexSearcher(reader);
    Term identifierTerm=identifier.getIdentifier();
    Document updatedDocument=null;
    try {
      Hits hits=searcher.search(new TermQuery(identifierTerm));
      checkHitsForUpdate(hits);
      updatedDocument=documentModifier.updateDocument(hits.doc(0));
    } catch(IOException ex) {
      throw new LuceneIndexAccessException("Error during updating a document.",ex);
    } finally {
      SearcherFactoryUtils.releaseSearcher(searcher);
      IndexReaderFactoryUtils.releaseIndexReader(indexFactory,reader);
View Full Code Here

Examples of org.apache.lucene.search.Hits

    IndexReader reader=IndexReaderFactoryUtils.getIndexReader(indexFactory);
    IndexSearcher searcher=new IndexSearcher(reader);
    Term identifierTerm=identifier.getIdentifier();
    List updatedDocuments=null;
    try {
      Hits hits=searcher.search(new TermQuery(identifierTerm));
      updatedDocuments=documentsModifier.updateDocuments(hits);
    } catch(IOException ex) {
      throw new LuceneIndexAccessException("Error during updating a document.",ex);
    } finally {
      SearcherFactoryUtils.releaseSearcher(searcher);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.