Package org.apache.lucene.search.similarities

Examples of org.apache.lucene.search.similarities.Similarity


    IndexReader reader = DirectoryReader.open(FSDirectory.open(indexLocation));
    IndexSearcher searcher = new IndexSearcher(reader);

    if (similarity.equalsIgnoreCase("BM25")) {
      Similarity simBM25 = new BM25Similarity();
      searcher.setSimilarity(simBM25);
    } else if (similarity.equalsIgnoreCase("LM")) {
      NamedList<Double> paramNamedList = new NamedList<Double>();
      paramNamedList.add("mu", 2500.0);
      SolrParams params = SolrParams.toSolrParams(paramNamedList);
      LMDirichletSimilarityFactory factory = new LMDirichletSimilarityFactory();
      factory.init(params);
      Similarity simLMDir = factory.getSimilarity();
      searcher.setSimilarity(simLMDir);
    }

    QueryParser p = new QueryParser(Version.LUCENE_43, IndexStatuses.StatusField.TEXT.name, IndexStatuses.ANALYZER);
    Query query = p.parse(queryText);
View Full Code Here


    NamedList<Double> paramNamedList = new NamedList<Double>();
    paramNamedList.add("mu", 2500.0);
    SolrParams params = SolrParams.toSolrParams(paramNamedList);
    LMDirichletSimilarityFactory factory = new LMDirichletSimilarityFactory();
    factory.init(params);
    Similarity simLMDir = factory.getSimilarity();
    searcher.setSimilarity(simLMDir);
  }
View Full Code Here

    NamedList<Double> paramNamedList = new NamedList<Double>();
    paramNamedList.add("mu", 2500.0);
    SolrParams params = SolrParams.toSolrParams(paramNamedList);
    LMDirichletSimilarityFactory factory = new LMDirichletSimilarityFactory();
    factory.init(params);
    Similarity simLMDir = factory.getSimilarity();
    searcher.setSimilarity(simLMDir);
  }
View Full Code Here

  public void runQueries() throws IOException {
    IndexReader reader = DirectoryReader.open(FSDirectory.open(new File(pathToIndex)));
    searcher = new IndexSearcher(reader);

    if (similarity.equalsIgnoreCase("bm25")) {
      Similarity simBM25 = new BM25Similarity();
      searcher.setSimilarity(simBM25);
    } else if (similarity.equalsIgnoreCase("lm")) {
      NamedList<Double> paramNamedList = new NamedList<Double>();
      paramNamedList.add("mu", 2500.0);
      SolrParams params = SolrParams.toSolrParams(paramNamedList);
      LMDirichletSimilarityFactory factory = new LMDirichletSimilarityFactory();
      factory.init(params);
      Similarity simLMDir = factory.getSimilarity();
      searcher.setSimilarity(simLMDir);
    }

    Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_41);
View Full Code Here

    IndexReader reader = DirectoryReader.open(FSDirectory.open(indexLocation));
    IndexSearcher searcher = new IndexSearcher(reader);

    if (similarity.equalsIgnoreCase("BM25")) {
      Similarity simBM25 = new BM25Similarity();
      searcher.setSimilarity(simBM25);
    } else if (similarity.equalsIgnoreCase("LM")) {
      NamedList<Double> paramNamedList = new NamedList<Double>();
      paramNamedList.add("mu", 2500.0);
      SolrParams params = SolrParams.toSolrParams(paramNamedList);
      LMDirichletSimilarityFactory factory = new LMDirichletSimilarityFactory();
      factory.init(params);
      Similarity simLMDir = factory.getSimilarity();
      searcher.setSimilarity(simLMDir);
    }

    out.println("Using similarity: " + searcher.getSimilarity().toString());
View Full Code Here

      SearchConfiguration cfg,
      WorkerBuildContext context
  ) {
    String indexName = getIndexName( entity, cfg );
    Properties[] indexProperties = getIndexProperties( cfg, indexName );
    Similarity similarity = createSimilarity( indexName, cfg, indexProperties[0], entity );
    boolean isDynamicSharding = isShardingDynamic( indexProperties[0] );

    IndexManager[] indexManagers = new IndexManager[0];
    if ( !isDynamicSharding ) {
      indexManagers = createIndexManagers(
View Full Code Here

    return interceptor;
  }

  private Similarity createSimilarity(String directoryProviderName, SearchConfiguration cfg, Properties indexProperties, XClass clazz) {
    // first check on class level
    Similarity classLevelSimilarity = null;

    // TODO - the processing of the @Similarity annotation is temporary here. The annotation should be removed in Search 5 (HF)
    List<XClass> hierarchyClasses = ReflectionHelper.createXClassHierarchy( clazz );
    Class<?> similarityClass = null;
    for ( XClass hierarchyClass : hierarchyClasses ) {
      org.hibernate.search.annotations.Similarity similarityAnnotation = hierarchyClass.getAnnotation( org.hibernate.search.annotations.Similarity.class );
      if ( similarityAnnotation != null ) {
        Class<?> tmpSimilarityClass = similarityAnnotation.impl();
        if ( similarityClass != null && !similarityClass.equals( tmpSimilarityClass ) ) {
          throw log.getMultipleInconsistentSimilaritiesInClassHierarchyException( clazz.getName() );
        }
        else {
          similarityClass = tmpSimilarityClass;
        }
        classLevelSimilarity = ClassLoaderHelper.instanceFromClass(
            Similarity.class,
            similarityClass,
            "Similarity class for index " + directoryProviderName
        );
      }
    }

    // now we check the config
    Similarity configLevelSimilarity = null;
    String similarityClassName = indexProperties.getProperty( Environment.SIMILARITY_CLASS_PER_INDEX );
    if ( similarityClassName != null ) {
      configLevelSimilarity = ClassLoaderHelper.instanceFromName(
          Similarity.class,
          similarityClassName,
          DirectoryProviderFactory.class.getClassLoader(),
          "Similarity class for index " + directoryProviderName
      );
    }

    if ( classLevelSimilarity != null && configLevelSimilarity != null ) {
      throw log.getInconsistentSimilaritySettingBetweenAnnotationsAndConfigPropertiesException(
          classLevelSimilarity.getClass().getName(),
          configLevelSimilarity.getClass().getCanonicalName()
      );
    }
    else if ( classLevelSimilarity != null ) {
      return classLevelSimilarity;
    }
View Full Code Here

  private LazyQueryState buildSearcher(SearchFactoryImplementor searchFactoryImplementor, Boolean forceScoring) {
    Map<Class<?>, EntityIndexBinding> builders = searchFactoryImplementor.getIndexBindings();
    List<IndexManager> targetedIndexes = new ArrayList<IndexManager>();
    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 entities,
      // but we have to make sure there is at least one
      if ( builders.isEmpty() ) {
View Full Code Here

    this.indexName = indexManager.getIndexName();
    LuceneIndexingParameters luceneParameters = indexManager.getIndexingParameters();
    this.indexParameters = luceneParameters.getIndexParameters();
    this.directoryProvider = indexManager.getDirectoryProvider();
    luceneParameters.applyToWriter( writerConfig );
    Similarity similarity = indexManager.getSimilarity();
    if ( similarity != null ) {
      writerConfig.setSimilarity( similarity );
    }
    writerConfig.setOpenMode( OpenMode.APPEND ); //More efficient to open
  }
View Full Code Here

      SearchConfiguration cfg,
      WorkerBuildContext buildContext
  ) {
    String indexName = getIndexName( entity, cfg );
    Properties[] indexProperties = getIndexProperties( cfg, indexName );
    Similarity similarity = createSimilarity( indexName, cfg, indexProperties[0], entity, buildContext );
    boolean isDynamicSharding = isShardingDynamic( indexProperties[0], buildContext );

    IndexManager[] indexManagers = new IndexManager[0];
    if ( !isDynamicSharding ) {
      indexManagers = createIndexManagers(
View Full Code Here

TOP

Related Classes of org.apache.lucene.search.similarities.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.