Hi Elaine, You can achieve that with some modifications in sol configuration files. Generally text will be configured as <fieldType name="text" class="solr.TextField" positionIncrementGap="100"> <analyzer type="index"> <tokenizer class="solr.WhitespaceTokenizerFactory"/> <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true"/> <filter class="solr.LowerCaseFilterFactory"/> </analyzer> <analyzer type="query"> <tokenizer class="solr.WhitespaceTokenizerFactory"/> <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt"/> <filter class="solr.LowerCaseFilterFactory"/> </analyzer> </fieldType>
When a field is declared as text(with above conf.) it will tokenized. Say, for example, your sentence "Can you get what you want?" will become be tokenized like "can, you, get, what, you, want". So when you search for 'sentence:"get what you"' you will get 0 results. To achieve your objective you can remove Tokenizers in "text" configuration. The best way I suggest is to declare the field as type "string". Search the string with wild card like 'sentence:"*get what you*"' using sorlj client and when you get try to records (results) save the output of sentence.indexOf(keyword) in your java bean. Here sentence is a variable declared in the java bean. For more details you need to read the usage of Solrj. If you have any issues in modifying the configuration post the configuration you have for the fieldtype "text" and i will modify it for you. Regards, Sandeep Team Elaine Li wrote: > > Say the field <field name="sentence">Can you get what you > want?</field>, the field type is Text. > > My query contains 'sentence:"get what you"'. Is it possible to get > number 2 directly from a query since the word 'get' is the 2nd token > in the sentence? > -- View this message in context: http://www.nabble.com/How-to-retrieve-the-index-of-a-string-within-a-field--tp25771821p25788406.html Sent from the Solr - User mailing list archive at Nabble.com.