Okay I think I have the idea:

<dataConfig>
  <dataSource type="JdbcDataSource"
                      name="animals"
                      batchSize="-1"
                      driver="com.mysql.jdbc.Driver"

url="jdbc:mysql://localhost/animals?characterEncoding=UTF8&amp;zeroDateTimeBehavior=convertToNull"
                      user="user"
                      password="pass"/>
  <script><![CDATA[
    function BoostScores(row) {
      // if searching for recommendations add in the boost score
       if(some_condition) {
        row.put('$docBoost', row.get('boost_score'));
      } // end if(some_condition)

      return row;
    } // end function BoostRecommendations(row)
  ]]></script>
 <document>
     <entity name="animal"
                dataSource="animals"
                pk="id"
                query="SELECT * FROM animals">
      <field column="id" name="id" />
      <field column="genus" name="genus" />
      <field column="species" name="species" />
      <entity name="boosters"
                 dataSource="boosts"
                 query="SELECT boost_score FROM boosts WHERE animal_id=${
animal.id}">
        <field column="boost_score" name="boost_score />
      </entity>
    </entity>
  </document>
</dataConfig>

Now, am I right in thinking that the boost score is only when the data is
loaded? If so, that's close to what I want to do but not exactly. I would
like to load all the data without boosting any scores but storing what the
boost score would be. And then, depending on the search, boost scores by the
value.

For example, if a user searches for dog, they would get search results that
were unboosted.

However, I would also want the option to pass in a flag of some kind so that
if a user searches for dog, they would get search results with the boost
score factored in. Ideally it would be something like:

Regular search: http://localhost/solr/search/?q=dog
Boosted search: http://localhost/solr/search?q=dog&boost=true

To achieve this, would it be applied in the data import handler? If so, what
would I need to put in for some_condition?

Thanks for all the help so far. I truly do appreciate it.

Thanks,

Brian Lamb

On Wed, Mar 9, 2011 at 11:50 PM, Bill Bell <billnb...@gmail.com> wrote:

> Yes just add if statement based on a field type and do a row.put() only if
> that other value is a certain value.
>
>
>
> On 3/9/11 1:39 PM, "Brian Lamb" <brian.l...@journalexperts.com> wrote:
>
> >That makes sense. As a follow up, is there a way to only conditionally use
> >the boost score? For example, in some cases I want to use the boost score
> >and in other cases I want all documents to be treated equally.
> >
> >On Wed, Mar 9, 2011 at 2:42 PM, Jayendra Patil
> ><jayendra.patil....@gmail.com
> >> wrote:
> >
> >> you can use the ScriptTransformer to perform the boost calcualtion and
> >> addition.
> >> http://wiki.apache.org/solr/DataImportHandler#ScriptTransformer
> >>
> >> <dataConfig>
> >>        <script><![CDATA[
> >>                function f1(row)  {
> >>                    // Add boost
> >>                    row.put('$docBoost',1.5);
> >>                    return row;
> >>                }
> >>        ]]></script>
> >>        <document>
> >>                <entity name="e" pk="id" transformer="script:f1"
> >> query="select * from X">
> >>                ....
> >>                </entity>
> >>        </document>
> >> </dataConfig>
> >>
> >> Regards,
> >> Jayendra
> >>
> >>
> >> On Wed, Mar 9, 2011 at 2:01 PM, Brian Lamb
> >> <brian.l...@journalexperts.com> wrote:
> >> > Anyone have any clue on this on?
> >> >
> >> > On Tue, Mar 8, 2011 at 2:11 PM, Brian Lamb <
> >> brian.l...@journalexperts.com>wrote:
> >> >
> >> >> Hi all,
> >> >>
> >> >> I am using dataimport to create my index and I want to use docBoost
> >>to
> >> >> assign some higher weights to certain docs. I understand the concept
> >> behind
> >> >> docBoost but I haven't been able to find an example anywhere that
> >>shows
> >> how
> >> >> to implement it. Assuming the following config file:
> >> >>
> >> >> <document>
> >> >>    <entity name="animal"
> >> >>               dataSource="animals"
> >> >>               pk="id"
> >> >>               query="SELECT * FROM animals">
> >> >>     <field column="id" name="id" />
> >> >>     <field column="genus" name="genus" />
> >> >>     <field column="species" name="species" />
> >> >>     <entity name="boosters"
> >> >>                dataSource="boosts"
> >> >>                query="SELECT boost_score FROM boosts WHERE animal_id
> >>=
> >> ${
> >> >> animal.id}">
> >> >>       <field column="boost_score" name="boost_score />
> >> >>     </entity>
> >> >>   </entity>
> >> >> </document>
> >> >>
> >> >> How do I add in a docBoost score? The boost score is currently in a
> >> >> separate table as shown above.
> >> >>
> >> >
> >>
>
>
>

Reply via email to