Exemplo n.º 1
0
  @Override
  public Document document(int docid) throws IOException {
    if (_subReaders != null) {
      int readerIndex = readerIndex(docid, _starts, _subReaders.length);
      BoboIndexReader subReader = _subReaders[readerIndex];
      return subReader.document(docid - _starts[readerIndex]);
    } else {
      Document doc = super.document(docid);
      Collection<FacetHandler<?>> facetHandlers = _facetHandlerMap.values();
      for (FacetHandler<?> facetHandler : facetHandlers) {
        String[] vals = facetHandler.getFieldValues(this, docid);
        if (vals != null) {
          String[] values = doc.getValues(facetHandler.getName());
          Set<String> storedVals = new HashSet<String>(Arrays.asList(values));

          for (String val : vals) {
            storedVals.add(val);
          }
          doc.removeField(facetHandler.getName());

          for (String val : storedVals) {
            doc.add(
                new Field(facetHandler.getName(), val, Field.Store.NO, Field.Index.NOT_ANALYZED));
          }
        }
      }
      return doc;
    }
  }
Exemplo n.º 2
0
  private void loadFacetHandler(
      String name, Set<String> loaded, Set<String> visited, WorkArea workArea) throws IOException {
    FacetHandler<?> facetHandler = _facetHandlerMap.get(name);
    if (facetHandler != null && !loaded.contains(name)) {
      visited.add(name);
      Set<String> dependsOn = facetHandler.getDependsOn();
      if (dependsOn.size() > 0) {
        Iterator<String> iter = dependsOn.iterator();
        while (iter.hasNext()) {
          String f = iter.next();
          if (name.equals(f)) continue;
          if (!loaded.contains(f)) {
            if (visited.contains(f)) {
              throw new IOException(
                  "Facet handler dependency cycle detected, facet handler: "
                      + name
                      + " not loaded");
            }
            loadFacetHandler(f, loaded, visited, workArea);
          }
          if (!loaded.contains(f)) {
            throw new IOException("unable to load facet handler: " + f);
          }
          facetHandler.putDependedFacetHandler(_facetHandlerMap.get(f));
        }
      }

      long start = System.currentTimeMillis();
      facetHandler.loadFacetData(this, workArea);
      long end = System.currentTimeMillis();
      if (logger.isDebugEnabled()) {
        StringBuffer buf = new StringBuffer();
        buf.append("facetHandler loaded: ")
            .append(name)
            .append(", took: ")
            .append(end - start)
            .append(" ms");
        logger.debug(buf.toString());
      }
      loaded.add(name);
    }
  }
Exemplo n.º 3
0
  protected void initialize(Collection<FacetHandler<?>> facetHandlers) throws IOException {
    if (facetHandlers == null) // try to load from index
    {
      Directory idxDir = directory();
      if (idxDir != null && idxDir instanceof FSDirectory) {
        FSDirectory fsDir = (FSDirectory) idxDir;
        File file = fsDir.getFile();

        if (new File(file, SPRING_CONFIG).exists()) {
          facetHandlers = loadFromIndex(file, _workArea);
        } else {
          facetHandlers = new ArrayList<FacetHandler<?>>();
        }
      } else {
        facetHandlers = new ArrayList<FacetHandler<?>>();
      }
    }

    _facetHandlers = facetHandlers;
    _facetHandlerMap = new HashMap<String, FacetHandler<?>>();
    for (FacetHandler<?> facetHandler : facetHandlers) {
      _facetHandlerMap.put(facetHandler.getName(), facetHandler);
    }
  }