Package org.apache.lucene.search

Examples of org.apache.lucene.search.Similarity


  private void fillSimilarityMapping() {
    final Map<Class<?>, DocumentBuilderIndexedEntity<?>> documentBuildersIndexedEntities = factoryState.getDocumentBuildersIndexedEntities();
    for ( DirectoryProviderData directoryConfiguration : factoryState.getDirectoryProviderData().values() ) {
      for ( Class<?> indexedType : directoryConfiguration.getClasses() ) {
        DocumentBuilderIndexedEntity<?> documentBuilder = documentBuildersIndexedEntities.get( indexedType );
        Similarity similarity = documentBuilder.getSimilarity();
        Similarity prevSimilarity = directoryConfiguration.getSimilarity();
        if ( prevSimilarity != null && !prevSimilarity.getClass().equals( similarity.getClass() ) ) {
          throw new SearchException(
              "Multiple entities are sharing the same index but are declaring an " +
                  "inconsistent Similarity. When overrriding default Similarity make sure that all types sharing a same index " +
                  "declare the same Similarity implementation."
          );
View Full Code Here


    public void releaseService(Class<? extends ServiceProvider<?>> provider) {
      factoryState.getServiceManager().releaseService( provider );
    }

    public Similarity getSimilarity(DirectoryProvider<?> provider) {
      Similarity similarity = factoryState.getDirectoryProviderData().get( provider ).getSimilarity();
      if ( similarity == null ) {
        throw new SearchException( "Assertion error: a similarity should be defined for each provider" );
      }
      return similarity;
    }
View Full Code Here

   *
   * @return returns the default similarity class.
   */
  private Similarity initSimilarity(SearchConfiguration cfg) {
    String similarityClassName = cfg.getProperty( Environment.SIMILARITY_CLASS );
    Similarity defaultSimilarity;
    if ( StringHelper.isEmpty( similarityClassName ) ) {
      defaultSimilarity = Similarity.getDefault();
    }
    else {
      defaultSimilarity = ClassLoaderHelper.instanceFromName(
          Similarity.class, similarityClassName, ConfigContext.class, "default similarity"
      );
    }
    log.debug( "Using default similarity implementation: {}", defaultSimilarity.getClass().getName() );
    return defaultSimilarity;
  }
View Full Code Here

    batchBackend.initialize( batchBackendConfiguration, progressMonitor, this );
    return batchBackend;
  }

  public Similarity getSimilarity(DirectoryProvider<?> provider) {
    Similarity similarity = dirProviderData.get( provider ).getSimilarity();
    if ( similarity == null ) {
      throw new SearchException( "Assertion error: a similarity should be defined for each provider" );
    }
    return similarity;
  }
View Full Code Here

  private IndexSearcherWithPayload buildSearcher(SearchFactoryImplementor searchFactoryImplementor, Boolean forceScoring) {
    Map<Class<?>, DocumentBuilderIndexedEntity<?>> builders = searchFactoryImplementor.getDocumentBuildersIndexedEntities();
    List<DirectoryProvider> targetedDirectories = new ArrayList<DirectoryProvider>();
    Set<String> idFieldNames = new HashSet<String>();

    Similarity searcherSimilarity = null;
    //TODO check if caching this work for the last n list of indexedTargetedEntities makes a perf boost
    if ( indexedTargetedEntities.size() == 0 ) {
      // empty indexedTargetedEntities array means search over all indexed enities,
      // but we have to make sure there is at least one
      if ( builders.isEmpty() ) {
View Full Code Here

  public void testSpanScorerZeroSloppyFreq() throws Exception {
    boolean ordered = true;
    int slop = 1;

    final Similarity sim = new DefaultSimilarity() {
      @Override
      public float sloppyFreq(int distance) {
        return 0.0f;
      }
    };
View Full Code Here

      //System.out.println(msg);
      lastScore = scores[i];
  }

  // override the norms to be inverted
  Similarity s = new DefaultSimilarity() {
            @Override
            public float computeNorm(String fieldName, FieldInvertState state) {
              return state.getBoost() * (discountOverlaps ? state.getLength() - state.getNumOverlap() : state.getLength());
            }
          };
View Full Code Here

    private String cachedFieldName;
    private Similarity cachedSimilarity;
   
    public byte[] norms(String fieldName) {
      byte[] norms = cachedNorms;
      Similarity sim = getSimilarity();
      if (fieldName != cachedFieldName || sim != cachedSimilarity) { // not cached?
        Info info = getInfo(fieldName);
        int numTokens = info != null ? info.numTokens : 0;
        int numOverlapTokens = info != null ? info.numOverlapTokens : 0;
        float boost = info != null ? info.getBoost() : 1.0f;
        FieldInvertState invertState = new FieldInvertState(0, numTokens, numOverlapTokens, 0, boost);
        float n = sim.computeNorm(fieldName, invertState);
        byte norm = Similarity.encodeNorm(n);
        norms = new byte[] {norm};
       
        // cache it for future reuse
        cachedNorms = norms;
View Full Code Here

    private Similarity cachedSimilarity;
   
    @Override
    public byte[] norms(String fieldName) {
      byte[] norms = cachedNorms;
      Similarity sim = getSimilarity();
      if (fieldName != cachedFieldName || sim != cachedSimilarity) { // not cached?
        Info info = getInfo(fieldName);
        int numTokens = info != null ? info.numTokens : 0;
        int numOverlapTokens = info != null ? info.numOverlapTokens : 0;
        float boost = info != null ? info.getBoost() : 1.0f;
        FieldInvertState invertState = new FieldInvertState(0, numTokens, numOverlapTokens, 0, boost);
        float n = sim.computeNorm(fieldName, invertState);
        byte norm = sim.encodeNormValue(n);
        norms = new byte[] {norm};
       
        // cache it for future reuse
        cachedNorms = norms;
        cachedFieldName = fieldName;
View Full Code Here

          testName = "reader re-use after disk full";
        }

        dir.setMaxSizeInBytes(thisDiskFree);
        dir.setRandomIOExceptionRate(rate);
        Similarity sim = new DefaultSimilarity();
        try {
          if (0 == x) {
            int docId = 12;
            for(int i=0;i<13;i++) {
              reader.deleteDocument(docId);
              reader.setNorm(docId, "content", sim.encodeNormValue(2.0f));
              docId += 12;
            }
          }
          reader.close();
          success = true;
View Full Code Here

TOP

Related Classes of org.apache.lucene.search.Similarity

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.