Package org.apache.lucene.index

Examples of org.apache.lucene.index.MultiReader


    {
      Hits hits = null;

      try
      {
        MultiReader       reader = null;
        ParallelMultiSearcher   searcher = null;

        List           searchers = new ArrayList();
        List           readers = new ArrayList();
        Collection         bots = BotsRunner.getRepInstance().getBots();
        Iterator         iter = bots.iterator();

        while (iter.hasNext())
        {
          Bot bot = (Bot)iter.next();

          Iterator channels_it = bot.getJoinedChannels().iterator();
          while (channels_it.hasNext())
          {
            Channel     channel = ((Channel)channels_it.next());
            StringBuffer   key = new StringBuffer();
            key
              .append(Config.getRepInstance().getString("LUCENE_DIR"))
              .append(File.separator)
              .append(bot.getName())
              .append("-")
              .append(bot.getServer().getServerName())
              .append("-")
              .append(channel.getName().substring(1));
           
            if (submission.getChannel() == null ||
              submission.getChannel().equals(""))
            {
              IndexReader   r = IndexReader.open(key.toString());
              IndexSearcher   s = new IndexSearcher(r);

              searchers.add(s);
              readers.add(r);
            }
            else
            {
              String submissionChannel = submission.getChannel().substring(submission.getChannel().indexOf("#"));
              if (channel.getName().equals(submissionChannel))
              {
                IndexReader   r = IndexReader.open(key.toString());
                IndexSearcher   s = new IndexSearcher(r);

                searchers.add(s);
                readers.add(r);
              }
            }
          }
        }

        IndexSearcher[] searcherArray = (IndexSearcher[])searchers.toArray(new IndexSearcher[0]);
        IndexReader[]   readerArray = (IndexReader[])readers.toArray(new IndexReader[0]);

        searcher = new ParallelMultiSearcher(searcherArray);
        reader = new MultiReader(readerArray);

        SortField dateSort = new SortField("momentDateSort", SortField.AUTO, true);
        SortField timeSort = new SortField("momentTimeSort", SortField.AUTO, false);

        hits = searcher.search(query, new Sort(new SortField[] { dateSort, timeSort }));

        // only highlight in the message
        Query           keywordQuery = search_tool.getKeywordQuery();
        Highlighter       highlighter = null;
        if (keywordQuery != null)
        {
          Query         rewritten_query =  keywordQuery.rewrite(reader);
          SimpleHTMLFormatter formatter = new SimpleHTMLFormatter("<span class=\"highlighted\">", "</span>");
         
          highlighter = new Highlighter(formatter, new QueryScorer(rewritten_query));
        }

        for (int i = offset; i < LIMIT + offset; i++)
        {
          if (i >= hits.length())
          {
            // handle partial full pages
            break;
          }

          Document doc = hits.doc(i);

          // pull in our values
          String   nickname = doc.getField("nickname").stringValue();
          String   message = doc.getField("message").stringValue();
          String   channelname = doc.getField("channel").stringValue();
          String   botname = doc.getField("botname").stringValue();
          String   servername = doc.getField("servername").stringValue();
          Date   moment = DateField.stringToDate(doc.getField("moment").stringValue());
          String   day = mOutputDateFormat.format(moment);
          String   time = mOutputTimeFormat.format(moment);
          String   outputday = mDateFormat.format(moment);

          // stolen directly from ChannelLog
          String nickcolor = (String)mNickColors.get(nickname);
          if (null == nickcolor)
          {
            nickcolor = ChannelLog.NICK_COLORS[mColorCounter++%ChannelLog.NICK_COLORS.length];
            mNickColors.put(nickname, nickcolor);
          }
          mTemplate.setValue("bgcolor", nickcolor);

          channelname = "#" + channelname;

          // output a header if we're no longer in our little
          // section of the world, i.e. date, server, channel, or
          // bot changed
          if (mCurrentDate == null || !mCurrentDate.equals(day) ||
            mCurrentServername == null || !mCurrentServername.equals(servername) ||
            mCurrentBotname == null || !mCurrentBotname.equals(botname) ||
            mCurrentChannelname == null || !mCurrentChannelname.equals(channelname))
          {
            mTemplate.setValue("day", day);
            mTemplate.setValue("botname", botname);
            mTemplate.setValue("servername", servername);
            mTemplate.setValue("channelname", channelname);

            try
            {
              SearchBean bean = new SearchBean();
              bean.setKeyword(submission.getKeyword());
              bean.setChannel(botname + " - " + channelname);
              bean.setDate(INPUT_DATE_FORMAT_SHORT.format(mDateFormat.parse(outputday)));

              setNamedOutputBean("SearchBean", bean);
            }
            catch (ParseException e)
            {
              Logger
                .getLogger("com.uwyn.drone.webui.elements.pub")
                .severe(ExceptionUtils.getExceptionStackTrace(e));
            }

            setOutput("day", outputday);
            setOutput("channelname", channelname);
            setOutput("botname", botname);
            setExitQuery(mTemplate, "show_channel_log", null, null);

            mTemplate.setBlock("day_header", "day_header");

            mCurrentDate = day;
            mCurrentServername = servername;
            mCurrentBotname = botname;
            mCurrentChannelname = channelname;
          }
          else
          {
            mTemplate.setValue("day_header", "");
          }

          // output the message
          mTemplate.setValue("time", time);

          // translate the \u0001ACTION command which corresponds to
          // /me so that the user's nickname is used instead
          StringBuffer message_buf = new StringBuffer();
          if (message.startsWith(ChannelLog.IRC_ACTION))
          {
            message_buf
              .append(nickname)
              .append(message.substring(ChannelLog.IRC_ACTION.length()));
          }
          else
          {
            message_buf.append(message);
          }

          String encoded_message = encodeHtml(message_buf.toString());

          if (highlighter != null)
          {
            TokenStream tokenStream = new StandardAnalyzer().tokenStream("message", new StringReader(encoded_message));
            String highlighted = highlighter.getBestFragments(tokenStream, encoded_message, 25, "...");

            if (!highlighted.equals(""))
            {
              encoded_message = highlighted;
            }
          }
         
          encoded_message = ChannelLog.convertUrl(encoded_message, ChannelLog.URL_HIGHLIGHT);

          Matcher email_matcher = ChannelLog.EMAIL_HIGHLIGHT.matcher(encoded_message);
          encoded_message = email_matcher.replaceAll("<a href=\"mailto:$1\">$1</a>");

          mTemplate.setValue("nickname", nickname);
          mTemplate.setValue("message", encoded_message);

          mTemplate.appendBlock("messages", "message");
        }

        searcher.close();
        reader.close();
      }
      catch (IOException e)
      {
        Logger
          .getLogger("com.uwyn.drone.webui.elements.pub")
View Full Code Here


        //System.out.println("SingleSearcher");
        mIndexSearcher = indexSearcherManagers[0].getIndexSearcher();
        mAnalyzer = indexSearcherManagers[0].getAnalyzer();
        mIndexName = indexConfigs[0].getName();
        IndexReader[] readerArray = {indexSearcherManagers[0].getIndexReader()};
        mMultiReader = new MultiReader(readerArray);

      } else {
        // Collect all IndexSearchers and instantiate a MultiSearcher
        IndexSearcher[] searchers = new IndexSearcher[indexConfigs.length];
        IndexReader[] readerArray = new IndexReader[indexConfigs.length];
        for (int j = 0; j < indexSearcherManagers.length; j++) {
          searchers[j] = indexSearcherManagers[j].getIndexSearcher();
          readerArray[j] = indexSearcherManagers[j].getIndexReader();
        }
        try {
          mIndexSearcher = new MultiSearcher(searchers);
          mMultiReader = new MultiReader(readerArray);
          // get the 'first' analyzer (in fact it is a random choice)
          // All indexes has to be build with the same analyzer
          mAnalyzer = indexSearcherManagers[0].getAnalyzer();
          mIndexName = "multiindex";
View Full Code Here

      }
    }
    if (idxReaders != null && idxReaders.size() > 0) {
      IndexReader[] readers = idxReaders
          .toArray(new IndexReader[idxReaders.size()]);
      return new MultiReader(readers);
    }
    return null;
  }
View Full Code Here

    isNewReader = isNewReader || (readerMap.size() != 0);
    if (!isNewReader){
      return this;
    }
    else{
      MultiReader newMreader = new MultiReader(currentReaders.toArray(new BoboIndexReader[currentReaders.size()]),false);
      BoboIndexReader newReader = BoboIndexReader.getInstanceAsSubReader(newMreader,this._facetHandlers,this._runtimeFacetHandlerFactories);
      newReader._dir = _dir;
      return newReader;
    }
  }
View Full Code Here

                            Collection<FacetHandler<?>> facetHandlers,
                            Collection<RuntimeFacetHandlerFactory<?,?>> facetHandlerFactories,
                            WorkArea workArea,
                            boolean useSubReaders) throws IOException
  {
    super(useSubReaders ? new MultiReader(createSubReaders(reader, workArea), false) : reader);
    if(useSubReaders)
    {
      _dir = reader.directory();
      BoboIndexReader[] subReaders = (BoboIndexReader[])in.getSequentialSubReaders();
      if(subReaders != null && subReaders.length > 0)
View Full Code Here

    // we can't put deleted docs before the nested reader, because
    // it will throw off the docIds
    IndexReader[] readers = new IndexReader[] {
      edge < 0 ? r : IndexReader.open(makeEmptyIndex(0), true),
      IndexReader.open(makeEmptyIndex(0), true),
      new MultiReader(new IndexReader[] {
        IndexReader.open(makeEmptyIndex(edge < 0 ? 4 : 0), true),
        IndexReader.open(makeEmptyIndex(0), true),
        0 == edge ? r : IndexReader.open(makeEmptyIndex(0), true)
      }),
      IndexReader.open(makeEmptyIndex(0 < edge ? 0 : 7), true),
      IndexReader.open(makeEmptyIndex(0), true),
      new MultiReader(new IndexReader[] {
        IndexReader.open(makeEmptyIndex(0 < edge ? 0 : 5), true),
        IndexReader.open(makeEmptyIndex(0), true),
        0 < edge ? r : IndexReader.open(makeEmptyIndex(0), true)
      })
    };
    IndexSearcher out = new IndexSearcher(new MultiReader(readers));
    out.setSimilarity(s.getSimilarity());
    return out;
  }
View Full Code Here

    w2.addDocument(doc);
    IndexReader reader2 = w2.getReader();
    w2.close();
   
    TermsFilter tf = new TermsFilter(new Term(fieldName, "content1"));
    MultiReader multi = new MultiReader(reader1, reader2);
    for (AtomicReaderContext context : multi.leaves()) {
      DocIdSet docIdSet = tf.getDocIdSet(context, context.reader().getLiveDocs());
      if (context.reader().docFreq(new Term(fieldName, "content1")) == 0) {
        assertNull(docIdSet);
      } else {
        FixedBitSet bits = (FixedBitSet) docIdSet;
        assertTrue("Must be >= 0", bits.cardinality() >= 0);     
      }
    }
    multi.close();
    reader1.close();
    reader2.close();
    rd1.close();
    rd2.close();
  }
View Full Code Here

          }
          if(r.length==1)
          {
            reader=  r[0];
          }else{
            reader=new MultiReader(r,true);
          }
        }
       
        if(dir==null)
        {
View Full Code Here

    addDocument(writer2, "<f123456>");

    final IndexReader ir1 = writer.getReader();
    final IndexReader ir2 = writer2.getReader();

    final MultiReader mr = new MultiReader(ir1, ir2);
    final IndexSearcher searcher = newSearcher(mr);
    final FuzzyQuery fq = new FuzzyQuery(new Term(DEFAULT_TEST_FIELD, "z123456"), 1, 0, 2, false);
    final TopDocs docs = searcher.search(fq, 2);
    assertEquals(5, docs.totalHits); // 5 docs, from the a and b's

    mr.close();
    ir2.close();
    writer2.close();
    directory2.close();
  }
View Full Code Here

    iw2.close();
   
    QueryParser qp = new QueryParser(TEST_VERSION_CURRENT, "field", new MockAnalyzer(random));
    qp.setMultiTermRewriteMethod(MultiTermQuery.SCORING_BOOLEAN_QUERY_REWRITE);
   
    MultiReader multireader = new MultiReader(reader1, reader2);
    IndexSearcher searcher = newSearcher(multireader);
    assertEquals(0, searcher.search(qp.parse("+foo -ba*"), 10).totalHits);
    searcher.close();
   
    final ExecutorService es = Executors.newCachedThreadPool();
    searcher = new IndexSearcher(multireader, es);
    if (VERBOSE)
      System.out.println("rewritten form: " + searcher.rewrite(qp.parse("+foo -ba*")));
    assertEquals(0, searcher.search(qp.parse("+foo -ba*"), 10).totalHits);
    es.shutdown();
    es.awaitTermination(1, TimeUnit.SECONDS);

    multireader.close();
    reader1.close();
    reader2.close();
    dir1.close();
    dir2.close();
  }
View Full Code Here

TOP

Related Classes of org.apache.lucene.index.MultiReader

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.