Examples of LuceneSearcher


Examples of com.xebia.search.LuceneSearcher

import com.xebia.search.LuceneSearcherImpl;

public class SearchExample {

    public static void main(String[] args) {
        LuceneSearcher luceneSearcher = new LuceneSearcherImpl();
        List<String> values = luceneSearcher.search("names", "albert");
        for (String value : values) {
            System.out.println(value);
        }
    }
View Full Code Here

Examples of org.apache.camel.component.lucene.LuceneSearcher

    public void process(Exchange exchange) throws Exception {
        Hits hits;

        String phrase = exchange.getIn().getHeader("QUERY", String.class);
        if (phrase != null) {
            searcher = new LuceneSearcher();
            searcher.open(indexDirectory, analyzer);
            hits = searcher.search(phrase, maxNumberOfHits);           
        } else {
            throw new IllegalArgumentException("SearchPhrase for LuceneQueryProcessor not set. Set the Header value: QUERY");
        }           
View Full Code Here

Examples of org.apache.camel.component.lucene.LuceneSearcher

    public void process(Exchange exchange) throws Exception {
        Hits hits;

        String phrase = exchange.getIn().getHeader("QUERY", String.class);
        if (phrase != null) {
            searcher = new LuceneSearcher();
            searcher.open(indexDirectory, analyzer);
            hits = searcher.search(phrase, maxNumberOfHits, luceneVersion);           
        } else {
            throw new IllegalArgumentException("SearchPhrase for LuceneQueryProcessor not set. Set the Header value: QUERY");
        }           
View Full Code Here

Examples of org.fao.geonet.kernel.search.LuceneSearcher

       
        // If a field is stored, field values could be retrieved from the index
        // The main advantage is that only values from records visible to the
        // user are returned, because the search filter the results first.
        if (origin.equals("") || origin.equals(RECORDS_FIELD_VALUES)) {
            LuceneSearcher searcher = (LuceneSearcher) sm.newSearcher(SearchManager.LUCENE, Geonet.File.SEARCH_LUCENE);

            searcher.getSuggestionForFields(context, fieldName, searchValue, _config, maxNumberOfTerms, threshold, listOfSuggestions);
        }
        // No values found from the index records field value ...
        if (origin.equals(INDEX_TERM_VALUES)
                || (listOfSuggestions.size() == 0 && origin.equals(""))) {
            // If a field is not stored, field values could not be retrieved
View Full Code Here

Examples of org.springmodules.lucene.search.factory.LuceneSearcher

  final public void testSearchQueryCreatorHitExtractor() throws Exception {
    Analyzer analyzer = new SimpleAnalyzer();
    MockControl searcherFactoryControl = MockControl.createStrictControl(SearcherFactory.class);
    SearcherFactory searcherFactory = (SearcherFactory)searcherFactoryControl.getMock();
    MockControl searcherControl = MockControl.createStrictControl(LuceneSearcher.class);
    LuceneSearcher searcher = (LuceneSearcher)searcherControl.getMock();
    MockControl queryCreatorControl = MockControl.createStrictControl(QueryCreator.class);
    QueryCreator queryCreator = (QueryCreator)queryCreatorControl.getMock();
    MockControl hitsControl = MockControl.createStrictControl(LuceneHits.class);
    LuceneHits hits = (LuceneHits)hitsControl.getMock();
    MockControl hitExtractorControl = MockControl.createStrictControl(HitExtractor.class);
    HitExtractor hitExtractor = (HitExtractor)hitExtractorControl.getMock();

    //query
    Query query = new TermQuery(new Term("field", "sample"));
   
    //document
    Document document = new Document();
    document.add(new Field("field", "a sample", Field.Store.YES, Field.Index.TOKENIZED));
    document.add(new Field("filter", "a sample filter", Field.Store.YES, Field.Index.TOKENIZED));
    document.add(new Field("sort", "2", Field.Store.YES, Field.Index.UN_TOKENIZED));
    Object obj = new Object();

    searcherFactory.getSearcher();
    searcherFactoryControl.setReturnValue(searcher, 1);
   
    queryCreator.createQuery(analyzer);
    queryCreatorControl.setReturnValue(query, 1);
   
    searcher.search(query);
    searcherControl.setReturnValue(hits, 1);

    hits.length();
    hitsControl.setReturnValue(1, 1);
   
    hits.id(0);
    hitsControl.setReturnValue(1, 1);
   
    hits.doc(0);
    hitsControl.setReturnValue(document, 1);
   
    hits.score(0);
    hitsControl.setReturnValue((float)1, 1);
   
    hitExtractor.mapHit(1, document, 1);
    hitExtractorControl.setReturnValue(obj, 1);
   
    hits.length();
    hitsControl.setReturnValue(1, 1);
   
    searcher.close();
    searcherControl.setVoidCallable(1);

    searcherFactoryControl.replay();
    searcherControl.replay();
    queryCreatorControl.replay();
View Full Code Here

Examples of org.springmodules.lucene.search.factory.LuceneSearcher

  final public void testSearchParsedQueryCreatorHitExtractor() throws Exception {
    Analyzer analyzer = new SimpleAnalyzer();
    MockControl searcherFactoryControl = MockControl.createStrictControl(SearcherFactory.class);
    SearcherFactory searcherFactory = (SearcherFactory)searcherFactoryControl.getMock();
    MockControl searcherControl = MockControl.createStrictControl(LuceneSearcher.class);
    LuceneSearcher searcher = (LuceneSearcher)searcherControl.getMock();
    MockControl hitsControl = MockControl.createStrictControl(LuceneHits.class);
    LuceneHits hits = (LuceneHits)hitsControl.getMock();
    MockControl hitExtractorControl = MockControl.createStrictControl(HitExtractor.class);
    HitExtractor hitExtractor = (HitExtractor)hitExtractorControl.getMock();

    //query
    final boolean[] called = { false };
    ParsedQueryCreator queryCreator = new ParsedQueryCreator() {
      public QueryParams configureQuery() {
        called[0] = true;
        return new QueryParams("field","lucene");
      }
    };
    final Query query = queryCreator.createQuery(analyzer);
   
    //document
    Document document = new Document();
    document.add(new Field("field", "a sample", Field.Store.YES, Field.Index.TOKENIZED));
    document.add(new Field("filter", "a sample filter", Field.Store.YES, Field.Index.TOKENIZED));
    document.add(new Field("sort", "2", Field.Store.YES, Field.Index.UN_TOKENIZED));
    Object obj = new Object();

    searcherFactory.getSearcher();
    searcherFactoryControl.setReturnValue(searcher, 1);
   
    searcher.search(query);
    searcherControl.setReturnValue(hits, 1);

    hits.length();
    hitsControl.setReturnValue(1, 1);
   
    hits.id(0);
    hitsControl.setReturnValue(1, 1);
   
    hits.doc(0);
    hitsControl.setReturnValue(document, 1);
   
    hits.score(0);
    hitsControl.setReturnValue((float)1, 1);
 
    hitExtractor.mapHit(1, document, 1);
    hitExtractorControl.setReturnValue(obj, 1);
   
    hits.length();
    hitsControl.setReturnValue(1, 1);
   
    searcher.close();
    searcherControl.setVoidCallable(1);

    searcherFactoryControl.replay();
    searcherControl.replay();
    hitExtractorControl.replay();
View Full Code Here

Examples of org.springmodules.lucene.search.factory.LuceneSearcher

  final public void testSearchQueryCreatorHitExtractorQueryResultCreator() throws Exception {
    Analyzer analyzer = new SimpleAnalyzer();
    MockControl searcherFactoryControl = MockControl.createStrictControl(SearcherFactory.class);
    SearcherFactory searcherFactory = (SearcherFactory)searcherFactoryControl.getMock();
    MockControl searcherControl = MockControl.createStrictControl(LuceneSearcher.class);
    LuceneSearcher searcher = (LuceneSearcher)searcherControl.getMock();
    MockControl queryCreatorControl = MockControl.createStrictControl(QueryCreator.class);
    QueryCreator queryCreator = (QueryCreator)queryCreatorControl.getMock();
    MockControl hitsControl = MockControl.createStrictControl(LuceneHits.class);
    LuceneHits hits = (LuceneHits)hitsControl.getMock();
    MockControl hitExtractorControl = MockControl.createStrictControl(HitExtractor.class);
    HitExtractor hitExtractor = (HitExtractor)hitExtractorControl.getMock();
    MockControl queryResultCreatorControl = MockControl.createStrictControl(QueryResultCreator.class);
    QueryResultCreator queryResultCreator = (QueryResultCreator)queryResultCreatorControl.getMock();

    //query
    Query query = new TermQuery(new Term("field", "sample"));
   
    //document
    Document document = new Document();
    document.add(new Field("field", "a sample", Field.Store.YES, Field.Index.TOKENIZED));
    document.add(new Field("filter", "a sample filter", Field.Store.YES, Field.Index.TOKENIZED));
    document.add(new Field("sort", "2", Field.Store.YES, Field.Index.UN_TOKENIZED));
    Object obj = new Object();

    searcherFactory.getSearcher();
    searcherFactoryControl.setReturnValue(searcher, 1);
   
    queryCreator.createQuery(analyzer);
    queryCreatorControl.setReturnValue(query, 1);
   
    searcher.search(query);
    searcherControl.setReturnValue(hits, 1);
   
    queryResultCreator.createResult(hits, hitExtractor);
    List ret = new ArrayList();
    ret.add(obj);
    queryResultCreatorControl.setReturnValue(ret);

    searcher.close();
    searcherControl.setVoidCallable(1);

    searcherFactoryControl.replay();
    searcherControl.replay();
    queryCreatorControl.replay();
View Full Code Here

Examples of org.springmodules.lucene.search.factory.LuceneSearcher

  final public void testSearchQueryCreatorHitExtractorFilter() throws Exception {
    Analyzer analyzer = new SimpleAnalyzer();
    MockControl searcherFactoryControl = MockControl.createStrictControl(SearcherFactory.class);
    SearcherFactory searcherFactory = (SearcherFactory)searcherFactoryControl.getMock();
    MockControl searcherControl = MockControl.createStrictControl(LuceneSearcher.class);
    LuceneSearcher searcher = (LuceneSearcher)searcherControl.getMock();
    MockControl queryCreatorControl = MockControl.createStrictControl(QueryCreator.class);
    QueryCreator queryCreator = (QueryCreator)queryCreatorControl.getMock();
    MockControl hitsControl = MockControl.createStrictControl(LuceneHits.class);
    LuceneHits hits = (LuceneHits)hitsControl.getMock();
    MockControl hitExtractorControl = MockControl.createStrictControl(HitExtractor.class);
    HitExtractor hitExtractor = (HitExtractor)hitExtractorControl.getMock();

    //query
    Query query = new TermQuery(new Term("field", "sample"));
   
    //filter
    TermQuery filterQuery = new TermQuery(new Term("filter", "another"));
    Filter filter = new QueryFilter(filterQuery);
   
    //document
    Document document = new Document();
    document.add(new Field("field", "a sample", Field.Store.YES, Field.Index.TOKENIZED));
    document.add(new Field("filter", "a sample filter", Field.Store.YES, Field.Index.TOKENIZED));
    document.add(new Field("sort", "2", Field.Store.YES, Field.Index.UN_TOKENIZED));
    Object obj = new Object();

    searcherFactory.getSearcher();
    searcherFactoryControl.setReturnValue(searcher, 1);
   
    queryCreator.createQuery(analyzer);
    queryCreatorControl.setReturnValue(query, 1);
   
    searcher.search(query, filter);
    searcherControl.setReturnValue(hits, 1);

    hits.length();
    hitsControl.setReturnValue(1, 1);
   
    hits.id(0);
    hitsControl.setReturnValue(1, 1);
   
    hits.doc(0);
    hitsControl.setReturnValue(document, 1);
   
    hits.score(0);
    hitsControl.setReturnValue((float)1, 1);
   
    hitExtractor.mapHit(1, document, 1);
    hitExtractorControl.setReturnValue(obj, 1);
   
    hits.length();
    hitsControl.setReturnValue(1, 1);
   
    searcher.close();
    searcherControl.setVoidCallable(1);

    searcherFactoryControl.replay();
    searcherControl.replay();
    queryCreatorControl.replay();
View Full Code Here

Examples of org.springmodules.lucene.search.factory.LuceneSearcher

    MockControl indexWriterControl = MockControl.createStrictControl(LuceneIndexWriter.class);
    LuceneIndexWriter indexWriter = (LuceneIndexWriter)indexWriterControl.getMock();
    MockControl indexReaderControl = MockControl.createStrictControl(LuceneIndexReader.class);
    LuceneIndexReader indexReader = (LuceneIndexReader)indexReaderControl.getMock();
    MockControl searcherControl = MockControl.createStrictControl(LuceneSearcher.class);
    LuceneSearcher searcher = (LuceneSearcher)searcherControl.getMock();
    MockControl documentModifierControl = MockControl.createStrictControl(DocumentModifier.class);
    DocumentModifier documentModifier = (DocumentModifier)documentModifierControl.getMock();
    MockControl hitsControl = MockControl.createStrictControl(LuceneHits.class);
    LuceneHits hits = (LuceneHits)hitsControl.getMock();
   
    //document
    Document document = new Document();
    document.add(new Field("field", "a sample", Field.Store.YES, Field.Index.TOKENIZED));
    document.add(new Field("filter", "a sample filter", Field.Store.YES, Field.Index.TOKENIZED));
    document.add(new Field("sort", "2", Field.Store.YES, Field.Index.UN_TOKENIZED));

    Term term = new Term("id","2");
   
    indexFactory.getIndexReader();
    indexFactoryControl.setReturnValue(indexReader, 1);
   
    indexReader.createSearcher();
    indexReaderControl.setReturnValue(searcher);
   
    searcher.search(new TermQuery(term));
    searcherControl.setReturnValue(hits);
   
    hits.length();
    hitsControl.setReturnValue(1, 2);
   
    hits.doc(0);
    hitsControl.setReturnValue(document);
   
    documentModifier.updateDocument(document);
    documentModifierControl.setReturnValue(document, 1);
   
    searcher.close();
    searcherControl.setVoidCallable(1);

    indexReader.close();
    indexReaderControl.setVoidCallable(1);
View Full Code Here

Examples of org.springmodules.lucene.search.factory.LuceneSearcher

    MockControl indexWriterControl = MockControl.createStrictControl(LuceneIndexWriter.class);
    LuceneIndexWriter indexWriter = (LuceneIndexWriter)indexWriterControl.getMock();
    MockControl indexReaderControl = MockControl.createStrictControl(LuceneIndexReader.class);
    LuceneIndexReader indexReader = (LuceneIndexReader)indexReaderControl.getMock();
    MockControl searcherControl = MockControl.createStrictControl(LuceneSearcher.class);
    LuceneSearcher searcher = (LuceneSearcher)searcherControl.getMock();
    MockControl documentsModifierControl = MockControl.createStrictControl(DocumentsModifier.class);
    DocumentsModifier documentsModifier = (DocumentsModifier)documentsModifierControl.getMock();
    MockControl hitsControl = MockControl.createStrictControl(LuceneHits.class);
    LuceneHits hits = (LuceneHits)hitsControl.getMock();
   
    //document
    Document document = new Document();
    document.add(new Field("field", "a sample", Field.Store.YES, Field.Index.TOKENIZED));
    document.add(new Field("filter", "a sample filter", Field.Store.YES, Field.Index.TOKENIZED));
    document.add(new Field("sort", "2", Field.Store.YES, Field.Index.UN_TOKENIZED));

    Term term = new Term("id","2");
    List documents = new ArrayList();
   
    indexFactory.getIndexReader();
    indexFactoryControl.setReturnValue(indexReader, 1);
   
    indexReader.createSearcher();
    indexReaderControl.setReturnValue(searcher);
   
    searcher.search(new TermQuery(term));
    searcherControl.setReturnValue(hits);
   
    documentsModifier.updateDocuments(hits);
    documentsModifierControl.setReturnValue(documents, 1);
   
    searcher.close();
    searcherControl.setVoidCallable(1);

    indexReader.close();
    indexReaderControl.setVoidCallable(1);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.