Package org.apache.lucene.search

Examples of org.apache.lucene.search.Similarity


  public void testAddDocument() throws Exception {
    Document testDoc = new Document();
    DocHelper.setupDoc(testDoc);
    Analyzer analyzer = new WhitespaceAnalyzer();
    Similarity similarity = Similarity.getDefault();
    DocumentWriter writer = new DocumentWriter(dir, analyzer, similarity, 50);
    String segName = "test";
    writer.addDocument(segName, testDoc);
    //After adding the document, we should be able to read it back in
    SegmentReader reader = SegmentReader.get(new SegmentInfo(segName, 1, dir));
View Full Code Here


      public int getPositionIncrementGap(String fieldName) {
        return 500;
      }
    };

    Similarity similarity = Similarity.getDefault();
    DocumentWriter writer = new DocumentWriter(dir, analyzer, similarity, 50);
    Document doc = new Document();
    doc.add(new Field("repeated", "repeated one", Field.Store.YES, Field.Index.TOKENIZED));
    doc.add(new Field("repeated", "repeated two", Field.Store.YES, Field.Index.TOKENIZED));
View Full Code Here

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

  // override the norms to be inverted
  Similarity s = new DefaultSimilarity() {
    public float lengthNorm(String fieldName, int numTokens) {
        return (float)numTokens;
    }
      };
  LengthNormModifier lnm = new LengthNormModifier(store, s);
View Full Code Here

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

  // override the norms to be inverted
  Similarity s = new DefaultSimilarity() {
    public float lengthNorm(String fieldName, int numTokens) {
        return (float)numTokens;
    }
      };
  LengthNormModifier lnm = new LengthNormModifier(store, s);
View Full Code Here

    public ReentrantLock getDirectoryProviderLock(DirectoryProvider<?> dp) {
      return factoryState.getDirectoryProviderData().get( dp ).getDirLock();
    }

    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

  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 entities,
      // but we have to make sure there is at least one
      if ( builders.isEmpty() ) {
View Full Code Here

    //TODO cleanup: this logic to select the Similarity is too complex, should likely be done in a previous phase
    final Map<Class<?>, EntityIndexBinder> documentBuildersIndexedEntities = factoryState.getIndexBindingForEntity();
    for ( Entry<Class<?>, EntityIndexBinder> entry : documentBuildersIndexedEntities.entrySet() ) {
      Class<?> clazz = entry.getKey();
      EntityIndexBinder entityMapping = entry.getValue();
      Similarity entitySimilarity = entityMapping.getSimilarity();
      if ( entitySimilarity == null ) {
        //might have been read from annotations, fill the missing information in the EntityIndexBinder:
        entitySimilarity = entityMapping.getDocumentBuilder().getSimilarity();
        if ( entitySimilarity != null ) {
          MutableEntityIndexBinding newMapping = new MutableEntityIndexBinding( entityMapping.getSelectionStrategy(), entitySimilarity, entityMapping.getIndexManagers() );
          newMapping.setDocumentBuilderIndexedEntity( entityMapping.getDocumentBuilder() );
          entityMapping = newMapping;
          documentBuildersIndexedEntities.put( clazz, entityMapping );
        }
      }
      IndexManager[] indexManagers = entityMapping.getIndexManagers();
      for ( IndexManager indexManager : indexManagers ) {
        Similarity indexSimilarity = indexManager.getSimilarity();
        if ( entitySimilarity != null && indexSimilarity == null ) {
          indexManager.setSimilarity( entitySimilarity );
        }
        else if ( entitySimilarity != null && ! entitySimilarity.getClass().equals( indexSimilarity.getClass() ) ) {
          throw new SearchException(
              "Multiple entities are sharing the same index but are declaring an " +
                  "inconsistent Similarity. When overriding default Similarity make sure that all types sharing a same index " +
                  "declare the same Similarity implementation."
          );
View Full Code Here

  private IndexSearcherWithPayload buildSearcher(SearchFactoryImplementor searchFactoryImplementor, Boolean forceScoring) {
    Map<Class<?>, EntityIndexBinder> builders = searchFactoryImplementor.getIndexBindingForEntity();
    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

    );

    //define the Similarity implementation:
    // warning: it can also be set by an annotation at class level
    final String similarityClassName = indexProps[0].getProperty( Environment.SIMILARITY_CLASS_PER_INDEX );
    Similarity similarityInstance = null;
    if ( similarityClassName != null ) {
      similarityInstance = ClassLoaderHelper.instanceFromName(
          Similarity.class,
          similarityClassName,
          DirectoryProviderFactory.class,
View Full Code Here

   * Specifies a custom similarity on an index
   * @param newSimilarity
   * @param manager
   */
  private void setSimilarity(Similarity newSimilarity, IndexManager manager) {
    Similarity similarity = manager.getSimilarity();
    if ( similarity != null && ! similarity.getClass().equals( newSimilarity.getClass() ) ) {
      throw new SearchException(
          "Multiple entities are sharing the same index but are declaring an " +
              "inconsistent Similarity. When overriding default Similarity make sure that all types sharing a same index " +
              "declare the same Similarity implementation."
      );
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.