Examples of Searcher


Examples of org.apache.lucene.search.Searcher

    LuceneIndexLocation synonymLocation = LuceneIndexLocation
        .getIndexLocation(new CRConfigUtil(autoConf, "synonymlocation"));
   
   
    IndexAccessor ia = synonymLocation.getAccessor();
    Searcher synonymSearcher = ia.getPrioritizedSearcher();
    IndexReader synonymReader = ia.getReader(false);
   
   
    try {
      HashSet<String> searchedTerms = new HashSet<String>();
     
      //get all searched Terms out of query
      for (int i = 0; i < searchedAttributes.length; i++) {
        String subquery = query;
        while (subquery.indexOf(searchedAttributes[i] + ":") > 0) {
          subquery = subquery.substring(subquery.indexOf(searchedAttributes[i] + ":") + searchedAttributes[i].length() + 1);
          int substringUntil = -1;
          int pos1 = subquery.indexOf(")");
          int pos2 = subquery.indexOf(" ");
          if (pos1 != -1) {
            substringUntil = pos1;
          }
          if (pos2 != -1) {
            substringUntil = pos2;
          }
          if (pos1 != -1 && pos2 != -1) {
            if (pos1 <= pos2) {
              substringUntil = pos1;
            }
            else {
              substringUntil = pos2;
            }
          }
          if (substringUntil == -1) {
            substringUntil = subquery.length();
          }
          String addtoSet = subquery.substring(0, substringUntil).replaceAll("\\*", "").replaceAll("\\(", "").replaceAll("\\)", "");
          searchedTerms.add(addtoSet);
          subquery = subquery.substring(substringUntil);
        }
       
      }
     
      //create the query-String for synonym-Index with all searchedTerms
      Iterator<String> it = searchedTerms.iterator();
      String queryString = "";
      while (it.hasNext()) {
        queryString = queryString + "Deskriptor:" + it.next() + " ";
      }
      Query querySynonym;
      try {
        querySynonym = super.parse(queryString);
      } catch (ParseException e) {
        e.printStackTrace();
        log.debug("Error while parsing query for accessing the synonym Index.", e);
        return query;
      }
     
      //get all Synonyms from SynonymIndex and add them to searchQuery
      log.debug("Synonym Query String: " + querySynonym.toString());
      TopDocs docs = synonymSearcher.search(querySynonym, MAX_SYNONYMS);
      log.debug("total found synonyms: " + docs.totalHits)
      for (ScoreDoc doc : docs.scoreDocs) {
        Document d = synonymReader.document(doc.doc);
        for (int i = 0; i < searchedAttributes.length; i++) {
          query = query + " OR " + searchedAttributes[i] + ":" + d.get("Synonym");
View Full Code Here

Examples of org.apache.lucene.search.Searcher

    if (autocompletereopenupdate || useAutocompleteIndexExtension) {
      checkForUpdate();
    }

    IndexAccessor ia = autocompleteLocation.getAccessor();
    Searcher autoCompleteSearcher = ia.getPrioritizedSearcher();
    IndexReader autoCompleteReader = ia.getReader(false);
    try {
      Query query = new TermQuery(new Term(GRAMMED_WORDS_FIELD, term));
      Sort sort = new Sort(new SortField(COUNT_FIELD, SortField.LONG, true));
      TopDocs docs = autoCompleteSearcher.search(query, null, 5, sort);
      int id = 1;
      for (ScoreDoc doc : docs.scoreDocs) {
        CRResolvableBean bean = new CRResolvableBean(id++);
        Document d = autoCompleteReader.document(doc.doc);
        bean.set(SOURCE_WORD_FIELD, d.get(SOURCE_WORD_FIELD));
View Full Code Here

Examples of org.apache.lucene.search.Searcher

    Path localDir = new Path(getUnitTestdir(getName()), "index_" +
      Integer.toString(new Random().nextInt()));
    this.fs.copyToLocalFile(new Path(INDEX_DIR), localDir);
    FileSystem localfs = FileSystem.getLocal(conf);
    Path [] indexDirs = localfs.listPaths(new Path [] {localDir});
    Searcher searcher = null;
    HScannerInterface scanner = null;
    try {
      if (indexDirs.length == 1) {
        searcher = new IndexSearcher((new File(indexDirs[0].
          toUri())).getAbsolutePath());
      } else if (indexDirs.length > 1) {
        Searchable[] searchers = new Searchable[indexDirs.length];
        for (int i = 0; i < indexDirs.length; i++) {
          searchers[i] = new IndexSearcher((new File(indexDirs[i].
            toUri()).getAbsolutePath()));
        }
        searcher = new MultiSearcher(searchers);
      } else {
        throw new IOException("no index directory found");
      }

      HTable table = new HTable(conf, new Text(TABLE_NAME));
      scanner = table.obtainScanner(columns, HConstants.EMPTY_START_ROW);

      HStoreKey key = new HStoreKey();
      TreeMap<Text, byte[]> results = new TreeMap<Text, byte[]>();

      IndexConfiguration indexConf = new IndexConfiguration();
      String content = conf.get("hbase.index.conf");
      if (content != null) {
        indexConf.addFromXML(content);
      }
      String rowkeyName = indexConf.getRowkeyName();

      int count = 0;
      while (scanner.next(key, results)) {
        String value = key.getRow().toString();
        LOG.debug("Scanned over " + key.getRow());
        Term term = new Term(rowkeyName, value);
        int hitCount = searcher.search(new TermQuery(term)).length();
        assertEquals("check row " + value, 1, hitCount);
        count++;
      }
      LOG.debug("Searcher.maxDoc: " + searcher.maxDoc());
      LOG.debug("IndexReader.numDocs: " + ((IndexSearcher)searcher).getIndexReader().numDocs());     
      int maxDoc = ((IndexSearcher)searcher).getIndexReader().numDocs();
      assertEquals("check number of rows", maxDoc, count);
    } finally {
      if (null != searcher)
        searcher.close();
      if (null != scanner)
        scanner.close();
    }
  }
View Full Code Here

Examples of org.apache.lucene.search.Searcher

  private void verify(Configuration c) throws IOException {
    Path localDir = new Path(this.testDir, "index_" +
      Integer.toString(new Random().nextInt()));
    this.fs.copyToLocalFile(new Path(INDEX_DIR), localDir);
    Path [] indexDirs = this.localFs.listPaths(new Path [] {localDir});
    Searcher searcher = null;
    HScannerInterface scanner = null;
    try {
      if (indexDirs.length == 1) {
        searcher = new IndexSearcher((new File(indexDirs[0].
          toUri())).getAbsolutePath());
      } else if (indexDirs.length > 1) {
        Searchable[] searchers = new Searchable[indexDirs.length];
        for (int i = 0; i < indexDirs.length; i++) {
          searchers[i] = new IndexSearcher((new File(indexDirs[i].
            toUri()).getAbsolutePath()));
        }
        searcher = new MultiSearcher(searchers);
      } else {
        throw new IOException("no index directory found");
      }

      HTable table = new HTable(c, new Text(TABLE_NAME));
      Text[] columns = { TEXT_INPUT_COLUMN, TEXT_OUTPUT_COLUMN };
      scanner = table.obtainScanner(columns, HConstants.EMPTY_START_ROW);

      HStoreKey key = new HStoreKey();
      TreeMap<Text, byte[]> results = new TreeMap<Text, byte[]>();

      IndexConfiguration indexConf = new IndexConfiguration();
      String content = c.get("hbase.index.conf");
      if (content != null) {
        indexConf.addFromXML(content);
      }
      String rowkeyName = indexConf.getRowkeyName();

      int count = 0;
      while (scanner.next(key, results)) {
        String value = key.getRow().toString();
        Term term = new Term(rowkeyName, value);
        int hitCount = searcher.search(new TermQuery(term)).length();
        assertEquals("check row " + value, 1, hitCount);
        count++;
      }
      int maxDoc = searcher.maxDoc();
      assertEquals("check number of rows", count, maxDoc);
    } finally {
      if (null != searcher)
        searcher.close();
      if (null != scanner)
        scanner.close();
    }
  }
View Full Code Here

Examples of org.apache.lucene.search.Searcher

            return aDocs;
        }

        private static String[] queryImpl(String aLanguageStr, String aIndexStr, String aQueryStr, boolean bCaptionOnly) throws Exception {
            IndexReader reader = IndexReader.open(aIndexStr);
            Searcher searcher = new IndexSearcher(reader);
            Analyzer analyzer = aLanguageStr.equals("ja") ? (Analyzer)new CJKAnalyzer() : (Analyzer)new StandardAnalyzer();

            String aField;
            if (bCaptionOnly) {
                aField = "caption";
            } else {
                aField = "content";
            }

            Query aQuery;
            if (aQueryStr.endsWith("*")) {
                aQuery = new WildcardQuery(new Term(aField, aQueryStr));
            } else {
                aQuery = new TermQuery(new Term(aField, aQueryStr));
            }

            // Perform search
            Hits aHits = searcher.search(aQuery);
            int nHitCount = aHits.length();

            String aDocs[] = new String[nHitCount];
            for (int iHit = 0; iHit < nHitCount; iHit++) {
                Document aDoc = aHits.doc(iHit);
View Full Code Here

Examples of org.apache.lucene.search.Searcher

    Path localDir = new Path(getUnitTestdir(getName()), "index_" +
      Integer.toString(new Random().nextInt()));
    this.fs.copyToLocalFile(new Path(INDEX_DIR), localDir);
    FileSystem localfs = FileSystem.getLocal(conf);
    FileStatus [] indexDirs = localfs.listStatus(localDir);
    Searcher searcher = null;
    Scanner scanner = null;
    try {
      if (indexDirs.length == 1) {
        searcher = new IndexSearcher((new File(indexDirs[0].getPath().
          toUri())).getAbsolutePath());
      } else if (indexDirs.length > 1) {
        Searchable[] searchers = new Searchable[indexDirs.length];
        for (int i = 0; i < indexDirs.length; i++) {
          searchers[i] = new IndexSearcher((new File(indexDirs[i].getPath().
            toUri()).getAbsolutePath()));
        }
        searcher = new MultiSearcher(searchers);
      } else {
        throw new IOException("no index directory found");
      }

      HTable table = new HTable(conf, TABLE_NAME);
      scanner = table.getScanner(columns, HConstants.EMPTY_START_ROW);

      IndexConfiguration indexConf = new IndexConfiguration();
      String content = conf.get("hbase.index.conf");
      if (content != null) {
        indexConf.addFromXML(content);
      }
      String rowkeyName = indexConf.getRowkeyName();

      int count = 0;
      for (RowResult r : scanner) {
        String value = Bytes.toString(r.getRow());
        Term term = new Term(rowkeyName, value);
        int hitCount = searcher.search(new TermQuery(term)).length();
        assertEquals("check row " + value, 1, hitCount);
        count++;
      }
      LOG.debug("Searcher.maxDoc: " + searcher.maxDoc());
      LOG.debug("IndexReader.numDocs: " + ((IndexSearcher)searcher).getIndexReader().numDocs());     
      int maxDoc = ((IndexSearcher)searcher).getIndexReader().numDocs();
      assertEquals("check number of rows", maxDoc, count);
    } finally {
      if (null != searcher)
        searcher.close();
      if (null != scanner)
        scanner.close();
    }
  }
View Full Code Here

Examples of org.apache.mahout.knn.search.Searcher

      radius.add(furthest);
    }
    log.warn("Reference data stored");
    log.warn("Starting add with speedup of {}", numDataVectors / (dimension * 2.0 * depth * 4.0));

    Searcher sut = new FastProjectionSearch(new SquaredEuclideanDistanceMeasure(), dimension * 2, depth * 4);
    sut.addAllMatrixSlicesAsWeightedVectors(data);
    log.warn("Added data with speedup of {}", numDataVectors / (dimension * 2.0 * depth * 4.0));

    long t0 = System.nanoTime();
    for (MatrixSlice query : queries) {
      List<WeightedThing<Vector>> r = sut.search(query.vector(), depth);
      Set<Integer> x = Sets.newHashSet();
      for (WeightedThing<Vector> vector : r) {
        x.add(((WeightedVector)vector.getValue()).getIndex());
      }
      double overlap = Sets.intersection(reference.get(query.index()), x).size() / (double) depth;
View Full Code Here

Examples of org.apache.mahout.math.neighborhood.Searcher

   * @param distanceMeasure distance measure to use
   * @return the confusion matrix
   */
  public static Matrix getConfusionMatrix(List<? extends Vector> rowCentroids, List<? extends  Vector> columnCentroids,
                                          Iterable<? extends Vector> datapoints, DistanceMeasure distanceMeasure) {
    Searcher rowSearcher = new BruteSearch(distanceMeasure);
    rowSearcher.addAll(rowCentroids);
    Searcher columnSearcher = new BruteSearch(distanceMeasure);
    columnSearcher.addAll(columnCentroids);

    int numRows = rowCentroids.size();
    int numCols = columnCentroids.size();
    Matrix confusionMatrix = new DenseMatrix(numRows, numCols);

    for (Vector vector : datapoints) {
      WeightedThing<Vector> closestRowCentroid = rowSearcher.search(vector, 1).get(0);
      WeightedThing<Vector> closestColumnCentroid = columnSearcher.search(vector, 1).get(0);
      int row = ((Centroid) closestRowCentroid.getValue()).getIndex();
      int column = ((Centroid) closestColumnCentroid.getValue()).getIndex();
      double vectorWeight;
      if (vector instanceof WeightedVector) {
        vectorWeight = ((WeightedVector) vector).getWeight();
View Full Code Here

Examples of org.apache.xindice.core.query.ftsearch.Searcher

            int ctxtNode = xctxt.getCurrentNode();
            Node node = xctxt.getDTM(ctxtNode).getNode(ctxtNode);
            NodeListImpl list = new NodeListImpl(null);
            list.add(node);

            Searcher searcher = new Searcher(list, analyzer);
            NodeSet nodes = searcher.search(query);

            return nodes.hasMoreNodes() ? XBoolean.S_TRUE : XBoolean.S_FALSE;
        } catch (ParseException e) {
            throw new TransformerException("Error in text query", e);
        }
View Full Code Here

Examples of org.sonatype.nexus.index.Searcher

      throws Exception
  {
    SearchNGIndexPlexusResource resource = new SearchNGIndexPlexusResource(Lists.<Searcher>newArrayList());
    Map<String, String> terms = new HashMap<String, String>(4);
    terms.put("q", "!");
    Searcher searcher = mock(Searcher.class);
    when(searcher.canHandle(Mockito.any(Map.class))).thenReturn(true);

    when(
        searcher.flatIteratorSearch(Mockito.any(Map.class), anyString(), anyInt(), anyInt(), anyInt(),
            anyBoolean(), Mockito.any(SearchType.class), Mockito.any(List.class)))
        // emulate current indexer search behavior, illegal query results in IllegalArgEx with the ParseEx as cause
        .thenThrow(new IllegalArgumentException(new ParseException("mock")));

    try {
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.