Java Code Examples for org.apache.lucene.search.NumericRangeQuery#newIntRange()
The following examples show how to use
org.apache.lucene.search.NumericRangeQuery#newIntRange() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZipscriptQueryExtension.java From drftpd with GNU General Public License v2.0 | 6 votes |
@Override public void addQueryTerms(BooleanQuery query, AdvancedSearchParams params) { try { ZipscriptQueryParams queryParams = params.getExtensionData(ZipscriptQueryParams.ZIPSCRIPTQUERYPARAMS); if (queryParams.getMinPresent() != null || queryParams.getMaxPresent() != null) { Query presentQuery = NumericRangeQuery.newIntRange("present", queryParams.getMinPresent(), queryParams.getMaxPresent(), true, true); query.add(presentQuery, Occur.MUST); } if (queryParams.getMinMissing() != null || queryParams.getMaxMissing() != null) { Query missingQuery = NumericRangeQuery.newIntRange("missing", queryParams.getMinMissing(), queryParams.getMaxMissing(), true, true); query.add(missingQuery, Occur.MUST); } if (queryParams.getMinPercent() != null || queryParams.getMaxPercent() != null) { Query percentQuery = NumericRangeQuery.newIntRange("percent", queryParams.getMinPercent(), queryParams.getMaxPercent(), true, true); query.add(percentQuery, Occur.MUST); } } catch (KeyNotFoundException e) { // No MP3 terms to include, return without amending query } }
Example 2
Source File: ZipscriptQueryExtension.java From drftpd with GNU General Public License v2.0 | 6 votes |
@Override public void addQueryTerms(BooleanQuery query, AdvancedSearchParams params) { try { ZipscriptQueryParams queryParams = params.getExtensionData(ZipscriptQueryParams.ZIPSCRIPTQUERYPARAMS); if (queryParams.getMinPresent() != null || queryParams.getMaxPresent() != null) { Query presentQuery = NumericRangeQuery.newIntRange("present", queryParams.getMinPresent(), queryParams.getMaxPresent(), true, true); query.add(presentQuery, Occur.MUST); } if (queryParams.getMinMissing() != null || queryParams.getMaxMissing() != null) { Query missingQuery = NumericRangeQuery.newIntRange("missing", queryParams.getMinMissing(), queryParams.getMaxMissing(), true, true); query.add(missingQuery, Occur.MUST); } if (queryParams.getMinPercent() != null || queryParams.getMaxPercent() != null) { Query percentQuery = NumericRangeQuery.newIntRange("percent", queryParams.getMinPercent(), queryParams.getMaxPercent(), true, true); query.add(percentQuery, Occur.MUST); } } catch (KeyNotFoundException e) { // No MP3 terms to include, return without amending query } }
Example 3
Source File: ShortFieldMapper.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public Query fuzzyQuery(Object value, Fuzziness fuzziness, int prefixLength, int maxExpansions, boolean transpositions) { short iValue = parseValue(value); short iSim = fuzziness.asShort(); return NumericRangeQuery.newIntRange(names().indexName(), numericPrecisionStep(), iValue - iSim, iValue + iSim, true, true); }
Example 4
Source File: FlacQueryExtension.java From drftpd with GNU General Public License v2.0 | 5 votes |
@Override public void addQueryTerms(BooleanQuery query, AdvancedSearchParams params) { try { FlacQueryParams queryParams = params.getExtensionData(FlacQueryParams.FLACQUERYPARAMS); if (queryParams.getGenre() != null) { Query genreQuery = LuceneUtils.analyze("flacGenre", TERM_GENRE, queryParams.getGenre()); query.add(genreQuery, Occur.MUST); } if (queryParams.getTitle() != null) { Query titleQuery = LuceneUtils.analyze("flacTitle", TERM_TITLE, queryParams.getTitle()); query.add(titleQuery, Occur.MUST); } if (queryParams.getArtist() != null) { Query artistQuery = LuceneUtils.analyze("flacArtist", TERM_ARTIST, queryParams.getArtist()); query.add(artistQuery, Occur.MUST); } if (queryParams.getAlbum() != null) { Query albumQuery = LuceneUtils.analyze("flacAlbum", TERM_ALBUM, queryParams.getAlbum()); query.add(albumQuery, Occur.MUST); } if (queryParams.getMinYear() != null || queryParams.getMaxYear() != null) { Query yearQuery = NumericRangeQuery.newIntRange("flacYear", queryParams.getMinYear(), queryParams.getMaxYear(), true, true); query.add(yearQuery, Occur.MUST); } } catch (KeyNotFoundException e) { // No FLAC terms to include, return without amending query } }
Example 5
Source File: MP3QueryExtension.java From drftpd with GNU General Public License v2.0 | 5 votes |
@Override public void addQueryTerms(BooleanQuery query, AdvancedSearchParams params) { try { MP3QueryParams queryParams = params.getExtensionData(MP3QueryParams.MP3QUERYPARAMS); if (queryParams.getGenre() != null) { Query genreQuery = LuceneUtils.analyze("mp3genre", TERM_GENRE, queryParams.getGenre()); query.add(genreQuery, Occur.MUST); } if (queryParams.getTitle() != null) { Query titleQuery = LuceneUtils.analyze("mp3title", TERM_TITLE, queryParams.getTitle()); query.add(titleQuery, Occur.MUST); } if (queryParams.getArtist() != null) { Query artistQuery = LuceneUtils.analyze("mp3artist", TERM_ARTIST, queryParams.getArtist()); query.add(artistQuery, Occur.MUST); } if (queryParams.getAlbum() != null) { Query albumQuery = LuceneUtils.analyze("mp3album", TERM_ALBUM, queryParams.getAlbum()); query.add(albumQuery, Occur.MUST); } if (queryParams.getMinYear() != null || queryParams.getMaxYear() != null) { Query yearQuery = NumericRangeQuery.newIntRange("mp3year", queryParams.getMinYear(), queryParams.getMaxYear(), true, true); query.add(yearQuery, Occur.MUST); } } catch (KeyNotFoundException e) { // No MP3 terms to include, return without amending query } }
Example 6
Source File: IMDBQueryExtension.java From drftpd with GNU General Public License v2.0 | 5 votes |
@Override public void addQueryTerms(BooleanQuery query, AdvancedSearchParams params) { try { IMDBQueryParams queryParams = params.getExtensionData(IMDBQueryParams.IMDBQUERYPARAMS); if (queryParams.getTitle() != null) { Query titleQuery = LuceneUtils.analyze("imdbtitle", TERM_TITLE, queryParams.getTitle()); query.add(titleQuery, Occur.MUST); } if (queryParams.getDirector() != null) { Query directorQuery = LuceneUtils.analyze("imdbdirector", TERM_DIRECTOR, queryParams.getDirector()); query.add(directorQuery, Occur.MUST); } if (queryParams.getGenres() != null) { Query genresQuery = LuceneUtils.analyze("imdbgenres", TERM_GENRES, queryParams.getGenres()); query.add(genresQuery, Occur.MUST); } if (queryParams.getMinVotes() != null || queryParams.getMaxVotes() != null) { Query votesQuery = NumericRangeQuery.newIntRange("imdbvotes", queryParams.getMinVotes(), queryParams.getMaxVotes(), true, true); query.add(votesQuery, Occur.MUST); } if (queryParams.getMinRating() != null || queryParams.getMaxRating() != null) { Query ratingQuery = NumericRangeQuery.newIntRange("imdbrating", queryParams.getMinRating(), queryParams.getMaxRating(), true, true); query.add(ratingQuery, Occur.MUST); } if (queryParams.getMinYear() != null || queryParams.getMaxYear() != null) { Query yearQuery = NumericRangeQuery.newIntRange("imdbyear", queryParams.getMinYear(), queryParams.getMaxYear(), true, true); query.add(yearQuery, Occur.MUST); } if (queryParams.getMinRuntime() != null || queryParams.getMaxRuntime() != null) { Query runtimeQuery = NumericRangeQuery.newIntRange("imdbruntime", queryParams.getMinRuntime(), queryParams.getMaxRuntime(), true, true); query.add(runtimeQuery, Occur.MUST); } } catch (KeyNotFoundException e) { // No IMDB terms to include, return without amending query } }
Example 7
Source File: ShortFieldMapper.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper) { return NumericRangeQuery.newIntRange(names().indexName(), numericPrecisionStep(), lowerTerm == null ? null : (int)parseValue(lowerTerm), upperTerm == null ? null : (int)parseValue(upperTerm), includeLower, includeUpper); }
Example 8
Source File: FlacQueryExtension.java From drftpd with GNU General Public License v2.0 | 5 votes |
@Override public void addQueryTerms(BooleanQuery query, AdvancedSearchParams params) { try { FlacQueryParams queryParams = params.getExtensionData(FlacQueryParams.FLACQUERYPARAMS); if (queryParams.getGenre() != null) { Query genreQuery = LuceneUtils.analyze("flacGenre", TERM_GENRE, queryParams.getGenre()); query.add(genreQuery, Occur.MUST); } if (queryParams.getTitle() != null) { Query titleQuery = LuceneUtils.analyze("flacTitle", TERM_TITLE, queryParams.getTitle()); query.add(titleQuery, Occur.MUST); } if (queryParams.getArtist() != null) { Query artistQuery = LuceneUtils.analyze("flacArtist", TERM_ARTIST, queryParams.getArtist()); query.add(artistQuery, Occur.MUST); } if (queryParams.getAlbum() != null) { Query albumQuery = LuceneUtils.analyze("flacAlbum", TERM_ALBUM, queryParams.getAlbum()); query.add(albumQuery, Occur.MUST); } if (queryParams.getMinYear() != null || queryParams.getMaxYear() != null) { Query yearQuery = NumericRangeQuery.newIntRange("flacYear", queryParams.getMinYear(), queryParams.getMaxYear(), true, true); query.add(yearQuery, Occur.MUST); } } catch (KeyNotFoundException e) { // No FLAC terms to include, return without amending query } }
Example 9
Source File: MP3QueryExtension.java From drftpd with GNU General Public License v2.0 | 5 votes |
@Override public void addQueryTerms(BooleanQuery query, AdvancedSearchParams params) { try { MP3QueryParams queryParams = params.getExtensionData(MP3QueryParams.MP3QUERYPARAMS); if (queryParams.getGenre() != null) { Query genreQuery = LuceneUtils.analyze("mp3genre", TERM_GENRE, queryParams.getGenre()); query.add(genreQuery, Occur.MUST); } if (queryParams.getTitle() != null) { Query titleQuery = LuceneUtils.analyze("mp3title", TERM_TITLE, queryParams.getTitle()); query.add(titleQuery, Occur.MUST); } if (queryParams.getArtist() != null) { Query artistQuery = LuceneUtils.analyze("mp3artist", TERM_ARTIST, queryParams.getArtist()); query.add(artistQuery, Occur.MUST); } if (queryParams.getAlbum() != null) { Query albumQuery = LuceneUtils.analyze("mp3album", TERM_ALBUM, queryParams.getAlbum()); query.add(albumQuery, Occur.MUST); } if (queryParams.getMinYear() != null || queryParams.getMaxYear() != null) { Query yearQuery = NumericRangeQuery.newIntRange("mp3year", queryParams.getMinYear(), queryParams.getMaxYear(), true, true); query.add(yearQuery, Occur.MUST); } } catch (KeyNotFoundException e) { // No MP3 terms to include, return without amending query } }
Example 10
Source File: IMDBQueryExtension.java From drftpd with GNU General Public License v2.0 | 5 votes |
@Override public void addQueryTerms(BooleanQuery query, AdvancedSearchParams params) { try { IMDBQueryParams queryParams = params.getExtensionData(IMDBQueryParams.IMDBQUERYPARAMS); if (queryParams.getTitle() != null) { Query titleQuery = LuceneUtils.analyze("imdbtitle", TERM_TITLE, queryParams.getTitle()); query.add(titleQuery, Occur.MUST); } if (queryParams.getDirector() != null) { Query directorQuery = LuceneUtils.analyze("imdbdirector", TERM_DIRECTOR, queryParams.getDirector()); query.add(directorQuery, Occur.MUST); } if (queryParams.getGenres() != null) { Query genresQuery = LuceneUtils.analyze("imdbgenres", TERM_GENRES, queryParams.getGenres()); query.add(genresQuery, Occur.MUST); } if (queryParams.getMinVotes() != null || queryParams.getMaxVotes() != null) { Query votesQuery = NumericRangeQuery.newIntRange("imdbvotes", queryParams.getMinVotes(), queryParams.getMaxVotes(), true, true); query.add(votesQuery, Occur.MUST); } if (queryParams.getMinRating() != null || queryParams.getMaxRating() != null) { Query ratingQuery = NumericRangeQuery.newIntRange("imdbrating", queryParams.getMinRating(), queryParams.getMaxRating(), true, true); query.add(ratingQuery, Occur.MUST); } if (queryParams.getMinYear() != null || queryParams.getMaxYear() != null) { Query yearQuery = NumericRangeQuery.newIntRange("imdbyear", queryParams.getMinYear(), queryParams.getMaxYear(), true, true); query.add(yearQuery, Occur.MUST); } if (queryParams.getMinRuntime() != null || queryParams.getMaxRuntime() != null) { Query runtimeQuery = NumericRangeQuery.newIntRange("imdbruntime", queryParams.getMinRuntime(), queryParams.getMaxRuntime(), true, true); query.add(runtimeQuery, Occur.MUST); } } catch (KeyNotFoundException e) { // No IMDB terms to include, return without amending query } }
Example 11
Source File: ByteFieldMapper.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public Query fuzzyQuery(Object value, Fuzziness fuzziness, int prefixLength, int maxExpansions, boolean transpositions) { byte iValue = parseValue(value); byte iSim = fuzziness.asByte(); return NumericRangeQuery.newIntRange(names().indexName(), numericPrecisionStep(), iValue - iSim, iValue + iSim, true, true); }
Example 12
Source File: ByteFieldMapper.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper) { return NumericRangeQuery.newIntRange(names().indexName(), numericPrecisionStep(), lowerTerm == null ? null : (int)parseValue(lowerTerm), upperTerm == null ? null : (int)parseValue(upperTerm), includeLower, includeUpper); }
Example 13
Source File: IntegerFieldMapper.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public Query fuzzyQuery(Object value, Fuzziness fuzziness, int prefixLength, int maxExpansions, boolean transpositions) { int iValue = parseValue(value); int iSim = fuzziness.asInt(); return NumericRangeQuery.newIntRange(names().indexName(), numericPrecisionStep(), iValue - iSim, iValue + iSim, true, true); }
Example 14
Source File: IntegerFieldMapper.java From Elasticsearch with Apache License 2.0 | 5 votes |
@Override public Query rangeQuery(Object lowerTerm, Object upperTerm, boolean includeLower, boolean includeUpper) { return NumericRangeQuery.newIntRange(names().indexName(), numericPrecisionStep(), lowerTerm == null ? null : parseValue(lowerTerm), upperTerm == null ? null : parseValue(upperTerm), includeLower, includeUpper); }
Example 15
Source File: IntFieldTypeDefinition.java From incubator-retired-blur with Apache License 2.0 | 4 votes |
@Override public Query getNewRangeQuery(String field, String part1, String part2, boolean startInclusive, boolean endInclusive) { int p1 = parseInt(part1); int p2 = parseInt(part2); return NumericRangeQuery.newIntRange(field, _precisionStep, p1, p2, startInclusive, endInclusive); }
Example 16
Source File: SuperParserTest.java From incubator-retired-blur with Apache License 2.0 | 4 votes |
private Query rq_i(String field, int min, int max) { return NumericRangeQuery.newIntRange(field, min, max, true, true); }
Example 17
Source File: BaseDirectoryTestSuite.java From incubator-retired-blur with Apache License 2.0 | 4 votes |
@Test public void testCreateIndex() throws IOException { long s = System.nanoTime(); IndexWriterConfig conf = new IndexWriterConfig(LuceneVersionConstant.LUCENE_VERSION, new KeywordAnalyzer()); IndexDeletionPolicyReader indexDeletionPolicy = new IndexDeletionPolicyReader( new KeepOnlyLastCommitDeletionPolicy()); conf.setIndexDeletionPolicy(indexDeletionPolicy); FSDirectory control = FSDirectory.open(fileControl); Directory dir = getControlDir(control, directory); // The serial merge scheduler can be useful for debugging. // conf.setMergeScheduler(new SerialMergeScheduler()); IndexWriter writer = new IndexWriter(dir, conf); int numDocs = 1000; DirectoryReader reader = null; long gen = 0; for (int i = 0; i < 100; i++) { if (reader == null) { reader = DirectoryReader.open(writer, true); gen = reader.getIndexCommit().getGeneration(); indexDeletionPolicy.register(gen); } else { DirectoryReader old = reader; reader = DirectoryReader.openIfChanged(old, writer, true); if (reader == null) { reader = old; } else { long newGen = reader.getIndexCommit().getGeneration(); indexDeletionPolicy.register(newGen); indexDeletionPolicy.unregister(gen); old.close(); gen = newGen; } } assertEquals(i * numDocs, reader.numDocs()); IndexSearcher searcher = new IndexSearcher(reader); NumericRangeQuery<Integer> query = NumericRangeQuery.newIntRange("id", 42, 42, true, true); TopDocs topDocs = searcher.search(query, 10); assertEquals(i, topDocs.totalHits); addDocuments(writer, numDocs); } writer.close(false); reader.close(); long e = System.nanoTime(); System.out.println("Total time [" + (e - s) / 1000000.0 + " ms]"); }
Example 18
Source File: TvMazeQueryExtension.java From drftpd with GNU General Public License v2.0 | 4 votes |
@Override public void addQueryTerms(BooleanQuery query, AdvancedSearchParams params) { try { TvMazeQueryParams queryParams = params.getExtensionData(TvMazeQueryParams.TvMazeQUERYPARAMS); if (queryParams.getName() != null) { Query nameQuery = LuceneUtils.analyze("tvmazename", TERM_NAME, queryParams.getName()); query.add(nameQuery, Occur.MUST); } if (queryParams.getGenre() != null) { Query genreQuery = LuceneUtils.analyze("tvmazegenre", TERM_GENRE, queryParams.getGenre()); query.add(genreQuery, Occur.MUST); } if (queryParams.getSeason() != null) { Query seasonQuery = NumericRangeQuery.newIntRange("tvmazeseason", queryParams.getSeason(), queryParams.getSeason(), true, true); query.add(seasonQuery, Occur.MUST); } if (queryParams.getNumber() != null) { Query numberQuery = NumericRangeQuery.newIntRange("tvmazenumber", queryParams.getNumber(), queryParams.getNumber(), true, true); query.add(numberQuery, Occur.MUST); } if (queryParams.getType() != null) { Query typeQuery = LuceneUtils.analyze("tvmazetype", TERM_TYPE, queryParams.getType()); query.add(typeQuery, Occur.MUST); } if (queryParams.getStatus() != null) { Query statusQuery = LuceneUtils.analyze("tvmazestatus", TERM_STATUS, queryParams.getStatus()); query.add(statusQuery, Occur.MUST); } if (queryParams.getLanguage() != null) { Query languageQuery = LuceneUtils.analyze("tvmazelanguage", TERM_LANGUAGE, queryParams.getLanguage()); query.add(languageQuery, Occur.MUST); } if (queryParams.getCountry() != null) { Query countryQuery = LuceneUtils.analyze("tvmazecountry", TERM_COUNTRY, queryParams.getCountry()); query.add(countryQuery, Occur.MUST); } if (queryParams.getNetwork() != null) { Query networkQuery = LuceneUtils.analyze("tvmazenetwork", TERM_NETWORK, queryParams.getNetwork()); query.add(networkQuery, Occur.MUST); } } catch (KeyNotFoundException e) { // No TvMaze terms to include, return without amending query } }
Example 19
Source File: QueryBuilder.java From exhibitor with Apache License 2.0 | 4 votes |
public QueryBuilder versionRange(int startVersion, int endVersion) { NumericRangeQuery<Integer> query = NumericRangeQuery.newIntRange(FieldNames.VERSION, startVersion, endVersion, true, false); queries.add(query); return this; }
Example 20
Source File: TvMazeQueryExtension.java From drftpd with GNU General Public License v2.0 | 4 votes |
@Override public void addQueryTerms(BooleanQuery query, AdvancedSearchParams params) { try { TvMazeQueryParams queryParams = params.getExtensionData(TvMazeQueryParams.TvMazeQUERYPARAMS); if (queryParams.getName() != null) { Query nameQuery = LuceneUtils.analyze("tvmazename", TERM_NAME, queryParams.getName()); query.add(nameQuery, Occur.MUST); } if (queryParams.getGenre() != null) { Query genreQuery = LuceneUtils.analyze("tvmazegenre", TERM_GENRE, queryParams.getGenre()); query.add(genreQuery, Occur.MUST); } if (queryParams.getSeason() != null) { Query seasonQuery = NumericRangeQuery.newIntRange("tvmazeseason", queryParams.getSeason(), queryParams.getSeason(), true, true); query.add(seasonQuery, Occur.MUST); } if (queryParams.getNumber() != null) { Query numberQuery = NumericRangeQuery.newIntRange("tvmazenumber", queryParams.getNumber(), queryParams.getNumber(), true, true); query.add(numberQuery, Occur.MUST); } if (queryParams.getType() != null) { Query typeQuery = LuceneUtils.analyze("tvmazetype", TERM_TYPE, queryParams.getType()); query.add(typeQuery, Occur.MUST); } if (queryParams.getStatus() != null) { Query statusQuery = LuceneUtils.analyze("tvmazestatus", TERM_STATUS, queryParams.getStatus()); query.add(statusQuery, Occur.MUST); } if (queryParams.getLanguage() != null) { Query languageQuery = LuceneUtils.analyze("tvmazelanguage", TERM_LANGUAGE, queryParams.getLanguage()); query.add(languageQuery, Occur.MUST); } if (queryParams.getCountry() != null) { Query countryQuery = LuceneUtils.analyze("tvmazecountry", TERM_COUNTRY, queryParams.getCountry()); query.add(countryQuery, Occur.MUST); } if (queryParams.getNetwork() != null) { Query networkQuery = LuceneUtils.analyze("tvmazenetwork", TERM_NETWORK, queryParams.getNetwork()); query.add(networkQuery, Occur.MUST); } } catch (KeyNotFoundException e) { // No TvMaze terms to include, return without amending query } }