Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 160839
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:06:22+00:00 2026-05-11T11:06:22+00:00

I am using Lucene in PHP (using the Zend Framework implementation). I am having

  • 0

I am using Lucene in PHP (using the Zend Framework implementation). I am having a problem that I cannot search on a field which contains a number.

Here is the data in the index:

       ts      |    contents --------------+-----------------   1236917100  | dog cat gerbil   1236630752  |  cow pig goat   1235680249  | lion tiger bear   nonnumeric  | bass goby trout 

My problem: A query for ‘ts:1236630752‘ returns no hits. However, a query for ‘ts:nonnumeric‘ returns a hit.

I am storing ‘ts’ as a keyword field, which according to documentation ‘is not tokenized, but is indexed and stored. Useful for non-text fields, e.g. date or url.’ I have tried treating it as a ‘text’ field, but the behavior is the same except that a query for ‘ts:*‘ returns nothing when ts is text.

I’m using Zend Framework 1.7 (just downloaded the latest 3 days ago) and PHP 5.2.9. Here is my code:

<?php  //========================================================= // Initializes Zend Framework (Zend_Loader). //========================================================= set_include_path(realpath('../library') . PATH_SEPARATOR . get_include_path()); require_once('Zend/Loader.php'); Zend_Loader::registerAutoload();  //========================================================= // Delete existing index and create a new one //========================================================= define('SEARCH_INDEX', 'test_search_index'); if(file_exists(SEARCH_INDEX))   foreach(scandir(SEARCH_INDEX) as $file)     if(!is_dir($file))       unlink(SEARCH_INDEX . '/$file');  $index = Zend_Search_Lucene::create(SEARCH_INDEX);  //========================================================= // Create this data in index: //         ts      |    contents //   --------------+----------------- //     1236917100  | dog cat gerbil //     1236630752  |  cow pig goat //     1235680249  | lion tiger bear //     nonnumeric  | bass goby trout //=========================================================  function add_to_index($index, $ts, $contents) {   $doc = new Zend_Search_Lucene_Document();   $doc->addField(Zend_Search_Lucene_Field::Keyword('ts', $ts));   $doc->addField(Zend_Search_Lucene_Field::Text('contents', $contents));   $index->addDocument($doc); }  add_to_index($index, '1236917100', 'dog cat gerbil'); add_to_index($index, '1236630752', 'cow pig goat'); add_to_index($index, '1235680249', 'lion tiger bear'); add_to_index($index, 'nonnumeric', 'bass goby trout');  //========================================================= // Run some test queries and output results //=========================================================  echo '<html><body><pre>';  function run_query($index, $query) {   echo 'Running query:  $query\n';   $hits = $index->find($query);   echo 'Got ' . count($hits) . ' hits.\n';   foreach($hits as $hit)     echo '  ts='$hit->ts', contents='$hit->contents'\n';   echo '\n'; }  run_query($index, 'pig');           //1 hit run_query($index, 'ts:1236630752'); //0 hits run_query($index, '1236630752');    //0 hits run_query($index, 'ts:pig');        //0 hits run_query($index, 'contents:pig');  //1 hits run_query($index, 'ts:[1236630700 TO 1236630800]'); //0 hits (range query) run_query($index, 'ts:*');          //4 hits if ts is keyword, 1 hit otherwise run_query($index, 'nonnumeric');    //1 hits run_query($index, 'ts:nonnumeric'); //1 hits run_query($index, 'trout');         //1 hits 

Output

 Running query:  pig Got 1 hits.   ts='1236630752', contents='cow pig goat'  Running query:  ts:1236630752 Got 0 hits.  Running query:  1236630752 Got 0 hits.  Running query:  ts:pig Got 0 hits.  Running query:  contents:pig Got 1 hits.   ts='1236630752', contents='cow pig goat'  Running query:  ts:[1236630700 TO 1236630800] Got 0 hits.  Running query:  ts:* Got 4 hits.   ts='1236917100', contents='dog cat gerbil'   ts='1236630752', contents='cow pig goat'   ts='1235680249', contents='lion tiger bear'   ts='nonnumeric', contents='bass goby trout'  Running query:  nonnumeric Got 1 hits.   ts='nonnumeric', contents='bass goby trout'  Running query:  ts:nonnumeric Got 1 hits.   ts='nonnumeric', contents='bass goby trout'  Running query:  trout Got 1 hits.   ts='nonnumeric', contents='bass goby trout' 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T11:06:23+00:00Added an answer on May 11, 2026 at 11:06 am

    The find() method tokenizes the query, and with the default Analzer your numbers will be pretty much ignored. If you want to search for a number you have to construct the query or use an alternate analyzer that includes numeric values..

    http://framework.zend.com/manual/en/zend.search.lucene.searching.html

    It is important to note that the query parser uses the standard analyzer to tokenize separate parts of query string. Thus all transformations which are applied to indexed text are also applied to query strings.

    The standard analyzer may transform the query string to lower case for case-insensitivity, remove stop-words, and stem among other transformations.

    The API method doesn’t transform or filter input terms in any way. It’s therefore more suitable for computer generated or untokenized fields.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 90k
  • Answers 90k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Yes, WaitForSingleObject uses the timer tick resolution, it does not… May 11, 2026 at 6:00 pm
  • Editorial Team
    Editorial Team added an answer Based on comments and further research I realized that the… May 11, 2026 at 6:00 pm
  • Editorial Team
    Editorial Team added an answer to script it to a file try: http://www.codeproject.com/KB/database/ScriptDiagram2005.aspx I would… May 11, 2026 at 6:00 pm

Related Questions

I am looking for a reliable way to check to see if a directory
I am using Lucene to allow a user to search for words in a
I'm working on an asp.net application which uses Lucene.net I need to highlight the
I'm working on all of these words feature using Lucene. I'm using StandardAnalyzer without

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.