Search in sources :

Example 6 with PerFieldSimilarityWrapper

use of org.apache.lucene.search.similarities.PerFieldSimilarityWrapper in project lucene-solr by apache.

the class TestSimilarityProvider method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    directory = newDirectory();
    PerFieldSimilarityWrapper sim = new ExampleSimilarityProvider();
    IndexWriterConfig iwc = newIndexWriterConfig(new MockAnalyzer(random())).setSimilarity(sim);
    RandomIndexWriter iw = new RandomIndexWriter(random(), directory, iwc);
    Document doc = new Document();
    Field field = newTextField("foo", "", Field.Store.NO);
    doc.add(field);
    Field field2 = newTextField("bar", "", Field.Store.NO);
    doc.add(field2);
    field.setStringValue("quick brown fox");
    field2.setStringValue("quick brown fox");
    iw.addDocument(doc);
    field.setStringValue("jumps over lazy brown dog");
    field2.setStringValue("jumps over lazy brown dog");
    iw.addDocument(doc);
    reader = iw.getReader();
    iw.close();
    searcher = newSearcher(reader);
    searcher.setSimilarity(sim);
}
Also used : Field(org.apache.lucene.document.Field) MockAnalyzer(org.apache.lucene.analysis.MockAnalyzer) PerFieldSimilarityWrapper(org.apache.lucene.search.similarities.PerFieldSimilarityWrapper) Document(org.apache.lucene.document.Document) RandomIndexWriter(org.apache.lucene.index.RandomIndexWriter) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig)

Aggregations

PerFieldSimilarityWrapper (org.apache.lucene.search.similarities.PerFieldSimilarityWrapper)6 Similarity (org.apache.lucene.search.similarities.Similarity)5 Document (org.apache.lucene.document.Document)3 RandomIndexWriter (org.apache.lucene.index.RandomIndexWriter)3 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)2 Field (org.apache.lucene.document.Field)2 IndexWriterConfig (org.apache.lucene.index.IndexWriterConfig)2 ClassicSimilarity (org.apache.lucene.search.similarities.ClassicSimilarity)2 Directory (org.apache.lucene.store.Directory)2 SolrCore (org.apache.solr.core.SolrCore)2 FloatDocValuesField (org.apache.lucene.document.FloatDocValuesField)1 FacetField (org.apache.lucene.facet.FacetField)1 FacetsConfig (org.apache.lucene.facet.FacetsConfig)1 DirectoryTaxonomyWriter (org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter)1 IndexReader (org.apache.lucene.index.IndexReader)1 Term (org.apache.lucene.index.Term)1 SweetSpotSimilarity (org.apache.lucene.misc.SweetSpotSimilarity)1 BM25Similarity (org.apache.lucene.search.similarities.BM25Similarity)1 DFISimilarity (org.apache.lucene.search.similarities.DFISimilarity)1 TFIDFSimilarity (org.apache.lucene.search.similarities.TFIDFSimilarity)1